I have a Repository class, which looks like this:
public class AppUserRepository : BaseRepositoryViewAsync<AppDbContext, AppUser, DTO.AppUsers.AppUser>, IAppUserRepository
{
public AppUserRepository(AppDbContext dbContext, IBaseMapper<AppUser, DTO.AppUsers.AppUser> mapper) : base(dbContext, mapper)
{
}
}
The implementation of BaseRepositoryViewAsync looks like this:
public class BaseRepositoryViewAsync<TDbContext, TEntityIn, TEntityOut> :
BaseRepositoryViewAsync<TDbContext, TEntityIn, TEntityOut, Guid>, IBaseRepositoryViewAsync<TEntityOut>
where TDbContext : BaseDbContext<BaseUser<Guid>, Guid>
where TEntityIn : class, IDomainEntityId
where TEntityOut : class, IDomainEntityId
{
public BaseRepositoryViewAsync(TDbContext dbContext, IBaseMapper<TEntityIn, TEntityOut> mapper) : base(dbContext, mapper)
{
}
}
Well there we can see, that the requirement for TDbContext is, that it is a BaseDbContext<BaseUser, Guid>
The AppDbContext:
public class AppDbContext : BaseDbContext<AppUser, Guid>
{
}
And the AppUser:
public class AppUser: BaseUser<Guid>, IDomainEntityId
{
}
The error that I get:
AppUserRepository.cs(8, 18): [CS0311] The type 'DAL.App.EF.AppDbContext' cannot be used as type parameter 'TDbContext' in the generic type or method 'BaseRepositoryViewAsync<TDbContext, TEntityIn, TEntityOut>'. There is no implicit reference conversion from 'DAL.App.EF.AppDbContext' to 'Base.DAL.EF.BaseDbContext<Base.Domain.Identity.BaseUser<System.Guid>, System.Guid>'.
From the error I understand, that the AppDbContext does not fit the requirements of being a BaseDbContext, but I can not figure out why it does not fit, since the AppDbContext directly Extends it.
It seems to me, that everything is implemented correctly, but I also might be wrong.
The not so liked fix is here:
public class AppDbContext : BaseDbContext<BaseUser<Guid>, Guid>
{
public new DbSet<AppUser> Users { get; set; } = null!;
}
I don't like this, because then I must override the users dbSet and this will create a discriminator column in the db, which is not necessary, since all users will be AppUsers.