如何在Grace IOC中注册IHubContext <,>

时间:2019-07-24 05:19:05

标签: .net-core ioc-container grace-ioc

我有一个使用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.MVCGrace.AspNetCore.Hosting软件包已安装。

我错过了什么吗?

0 个答案:

没有答案