1
votes

I'm using NET Core 2.1 and have Ninject as my DI and I'm trying to inject IHubContext inside a controller constructor using ninject, but getting this error:

"Ninject.ActivationException: 'Error activating IHubContext No matching bindings are available, and the type is not self-bindable."

I've added SignalR to services (services.AddSignalR()) and mapped it for the IApplicationBuilder: app.UseSignalR(route => route.MapHub("/myhub"));

Tried binding it from the global resolver also: kernel.Bind< IHubContext>().ToMethod(context => GlobalHost.DependencyResolver.Resolve< IHubContext>()).InSingletonScope(); but with no luck, what I am missing in order to inject this IHubContext in the constructor of my controller using Ninject.

Thank you.

1
You should be binding IHubContext<THub>. I'm assuming your MapHub is actually MapHub<HubType>, you should use HubType with IHubContext<> - Brennan

1 Answers

2
votes

Finally fixed this issue, for anyone else who has this problem, trying to use signalR with Ninject as the DI.

 var serviceProvider = app.ApplicationServices;
 kernel.Bind<IHubContext<MyHub>>().ToMethod(context => serviceProvider.GetService<IHubContext<MyHub>>());