I have created a generic repository that I want to be used in a service.
public abstract class AbstractBaseRepository<TEntity, TEntityKey>
: IBaseRepository<TEntity, TEntityKey>
where TEntity : class, IBaseEntity<TEntityKey>, new() { /* some code */ }
And the interface:
public interface IBaseRepository<TEntity, TEntityKey> { /* some code */ }
On my service I inject the repository like this:
public class TenantsService : AbstractBaseService<TenantEntity, int>
{
public TenantsService(IBaseRepository<TenantEntity, int> tenantsRepository)
: base(tenantsRepository) { }
}
On my startup, on the ConfigureServices method, I have:
services.AddScoped(typeof(IBaseRepository<,>), typeof(AbstractBaseRepository<,>));
I added this startup code based on the following two answers:
https://stackoverflow.com/a/33567396
https://stackoverflow.com/a/43094684
When I run the application I am getting the following error:
Cannot instantiate implementation type 'Playground.Repositories.Base.AbstractBaseRepository`2[TEntity,TEntityKey]' for service type 'Playground.Repositories.Base.IBaseRepository`2[TEntity,TEntityKey]'