So I am trying to inject a generic repository that receives as generic types both the entity type and the type of key the entity uses.
The declaration looks something like this:
public class GenericRepository<KeyType, T> : BaseRepository<T, NpgsqlConnection>, IGenericRepository<KeyType, T>
where T : class
where KeyType : struct
So I try to inject them like this:
services.AddTransient(typeof(IGenericRepository<>), typeof(GenericRepository<>));
That works for when there is only one generic type, but not for two. I get the following error:
Using the generic type 'GenericRepository<KeyType, T>' requires 2 type arguments
Does anyone have a clue how to solve this?
I know I could make classes for each one, but I'd like to inject it like this:
public class RestaurantTypesService : IRestaurantTypesService
{
private readonly IGenericRepository<long, RestaurantType> _restaurantTypeRepository;
public RestaurantTypesService(IGenericRepository<long, RestaurantType> repository)
{
_restaurantTypeRepository = repository;
}
}