SignalR 2 Dependency Injection with Ninject

前端 未结 3 777
野趣味
野趣味 2020-12-08 23:16

I have an existing MVC application that is using Dependency Injection with Ninject. I installed the Ninject.MVC3 nuget package and it creates a class called NinjectWebCommon

3条回答
  •  再見小時候
    2020-12-08 23:54

    Have you tried adding the StockTickerHub itself to your kernel?

    By default, SignalR uses Activator.CreateInstance to construct Hubs without any constructor arguments. If you want to inject your own dependencies into a Hub, you can do so by registering the Hub with SignalR's dependency resolver.

    https://github.com/SignalR/SignalR/blob/2.0.1/src/Microsoft.AspNet.SignalR.Core/Hubs/DefaultHubActivator.cs#L28

    If you want to get really creative, you can register your own IHubActivator instead of registering all of Hubs individually.

    I go into more detail in how Hubs are created by default in this answer: SignalR with IoC (Castle Windsor) - which lifetime for hubs?

提交回复
热议问题