1

I got this error:

ArgumentException: The number of generic arguments provided doesn't equal the arity of the generic type definition. Parameter name: instantiation

public class EfCoreRepository<TContext, TEntity> : IEfCoreRepository<TEntity>
            where TContext : IEfCoreDbContext
            where TEntity : class
            {
        ....
        }

Here is the interface

public interface IEfCoreRepository<TEntity> where TEntity : class

where I register it like that

services.AddTransient(typeof(IEfCoreRepository<>), typeof(EfCoreRepository<,>));
  • 1
    I don't think you can register an [open type](https://stackoverflow.com/questions/2173107/what-exactly-is-an-open-generic-type-in-net). You can't instantiate an open type, so why would you want to register it? – John Wu May 14 '19 at 23:41
  • I think it's should be ```services.AddScoped(typeof(IEfCoreRepository<>), typeof(EfCoreRepository<>));``` right ? – Tony Ngo May 15 '19 at 04:06

1 Answers1

0

I updated the interface to be

public interface IEfCoreRepository<TContext, TEntity> 
         where TContext : IEfCoreDbContext
         where TEntity : class

and then register it like this

services.AddTransient(typeof(IEfCoreRepository<,>), typeof(EfCoreRepository<,>));