1
votes

what is the way to register a Generic class with 3 arguments

public interface ITest<T,V,VE>
{

}

public class TestRespository<T,V,VE>:ITest<T,V,VE>
{

}

i had registered like this

services.AddScoped(typeof(ITest<,,>), typeof(ITest<,,>));

but unable to get in Constructor as well as

service.GetService(typeof(ITest<TestClass, vTestClass, VETestClass>)) as ITest<TestClass, vTestClass, VETestClass>;
2

2 Answers

5
votes

The problem is with call of AddScoped() method. You should pass type of implementation in second argument, not the type of interface itself:

services.AddScoped(typeof(ITest<,,>), typeof(TestRespository<,,>));
1
votes
services.AddScoped(typeof(ITest<,,>), typeof(ITest<,,>));

You need to have implementation and interface not interface twice. You are registering interface as interface, so it cannot be instantiated.

services.AddScoped(typeof(ITest<,,>), typeof(TestRepository<,,>));

Should do the trick.