Grace: Problem in registering IHubContext<,> in Grace IOC
Question on stackoverflow
I have a 2.2 .net core application, using SignalR core, in one of my Controllers I want to inject IHubContext<ChatHub, IChatClient>. Works pretty well with built-in IoC, but when I add Grace IoC I get the following error message:
Unable to resolve service for type 'Microsoft.AspNetCore.SignalR.IHubContext`2[Test.Hubs.ChatHub,Test.Hubs.IChatClient]' while attempting to activate TestController
I tried to add the following line in the ConfigureContainer method:
scope.Configure(c=> c.Export<IHubContext<ChatHub, IChatClient>>());
Also tried:
scope.Configure(c=> { c.Export(typeof(IHubContext<,>)); });
Then the error changed to the following which sounds reasonable since I haven’t registered a concrete class for the interface.
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]]
And BTW, I’ve tested aforementioned approaches with both
.UseGrace((new InjectionScopeConfiguration { AutoRegisterUnknown = true })) and .UseGrace((new InjectionScopeConfiguration { AutoRegisterUnknown = false })).
Grace.AspNetCore.MVC and Grace.AspNetCore.Hosting packages are installed.
Anything that I missed?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 32 (16 by maintainers)
Commits related to this issue
- addressing a generic constraint for issue #229 — committed to ipjohnson/Grace by ipjohnson 5 years ago
- more constraint changes for issue #229 — committed to ipjohnson/Grace by ipjohnson 5 years ago
So I took a look and there is a bug in the way the generic type is being constructed (or not constructed as the case is). I’m going to try and address this issue and a couple others this weekend.
@shahabganji this is caused by a combination of
AutoRegisterUnknown = falseandconfig.UseControllerActivator = true;Essentially you’re telling the container not to auto register unknown types (controller specifically) and you’re enabling resolving controllers from the container. If you register all your controllers and other concrete types then you can use that combination of flags. Otherwise you’ll need to change something.
@cuteant your issue looks to be different and I’m planning on addressing it this weekend as I have a couple days off.
OrchardCore.ShellContainerFactory
Replace with this: `
public static IServiceProvider BuildGraceServiceProvider(this IServiceCollection services) { var configuration = new InjectionScopeConfiguration(); configuration.AutoRegisterUnknown = false; configuration.Behaviors.AllowInstanceAndFactoryToReturnNull = true; return BuildGraceServiceProvider(services, configuration); }
` The test case in OrchardCore.Test cannot pass
My english is not so good, I hope you can understand
I’ve released a new version 7.1.0-beta
I think this can be closed out and I’ll push an RC version here this week
Ok I can reproduce it. My unit test was slightly different than the use case. It’s an easy fix but I won’t be able to do it till tomorrow or Wednesday
@ipjohnson
Thanks for your great support. Unfortunately, my laptop is broken and I cannot test it until I get it repaired. however, as soon as I have my machine I will test and report the results. 🙏
I have one more issue I need to address before I can do a beta release but you can test the fix in the nightly nuget feed
https://ci.appveyor.com/nuget/grace-master
Hi @ipjohnson, yes sure I’ll try to reproduce the problem in a repository and I will share the link here.
@silkfire your assumption is correct.