I have an abstract BaseRepository which handles basic CRUD operations.
public abstract class BaseRepository
{
protected readonly IDbContextFactory<DbContext> _dbContextFactory;
public BaseRepository(IDbContextFactory<TrinityDbContext> dbContextFactory)
{
_dbContextFactory = dbContextFactory;
}
}
public abstract class BaseRepository<T> : BaseRepository where T : class, IUniqueIdentifier
{
public BaseRepository(IDbContextFactory<TrinityDbContext> dbContextFactory) : base(dbContextFactory) { }
}
I created an abstract RepoServiceBase to add those CRUD operations to my services.
public abstract class RepoServiceBase<T> where T : class, IUniqueIdentifier
{
private readonly BaseRepository<T> _repo;
public RepoServiceBase(BaseRepository<T> repo)
{
_repo = repo;
}
}
But when constructing the service I get the following error: Cannot convert from IProductRepository to BaseRepository
public class ProductService : RepoServiceBase<Product>, IProductService
{
public ProductService(IProductRepository repo) : base(repo) { }
}
Is there a way to require IProductRepository to implement BaseRepository?