我有一个使用SignalR核心的2.2 .net核心应用程序,我想在其中一个控制器中注入IHubContext<ChatHub, IChatClient>
。内置IoC可以很好地工作,但是当我添加Grace IoC
时,出现以下错误消息:
Unable to resolve service for type 'Microsoft.AspNetCore.SignalR.IHubContext`2[Test.Hubs.ChatHub,Test.Hubs.IChatClient]' while attempting to activate TestController
我试图在ConfigureContainer
方法中添加以下行:
scope.Configure(c=> c.Export<IHubContext<ChatHub, IChatClient>>());
也尝试过:
scope.Configure(c=> { c.Export(typeof(IHubContext<,>)); });
然后将错误更改为以下内容,这听起来很合理,因为我尚未为该接口注册具体的类。
Could not find public constructor on type Microsoft.AspNetCore.SignalR.IHubContext`2[[Test.Hubs.ChatHub, Test, Version=0.0.1.0, Culture=neutral, PublicKeyToken=null],[Test.Hubs.IChatClient, Test, Version=0.0.1.0, Culture=neutral, PublicKeyToken=null]]
顺便说一句,我已经测试了上述两种方法
.UseGrace((new InjectionScopeConfiguration { AutoRegisterUnknown = true }))
和.UseGrace((new InjectionScopeConfiguration { AutoRegisterUnknown = false }))
。
Grace.AspNetCore.MVC
和Grace.AspNetCore.Hosting
软件包已安装。
我错过了什么吗?