kirov-opensource / NAutowired

ASP.NET CORE Field Injection Implement
MIT License
77 stars 16 forks source link

不支持泛型类 #20

Closed wxk0248 closed 3 years ago

wxk0248 commented 3 years ago

[Service(Lifetime.Scoped)] public class Test<T>:ITest { public void OutPut() { Console.WriteLine("111"); } } System.ArgumentException:“Cannot instantiate implementation type 'TestAutoWared.Service.Test`1[T]' for service type 'TestAutoWared.Service.ITest'.”

FatTigerWang commented 3 years ago

泛型是无法直接加入到容器的, 可以在Startup.cs使用:

services.AddScoped<Test<YourClass>>();
wxk0248 commented 3 years ago

好的,十分感谢!