我刚刚开始使用SignalR,并为SignalR创建了一个自定义解析器,因此我可以使用Castle Windsor通过集线器构造器注入依赖项.
我有点假设我只需要注册依赖项,但我发现在我的应用程序工作之前还必须自己注册集线器.这是预期的吗?如果是这样,我应该用什么寿命用于集线器?
我在我的 Web 应用程序中使用了 Ninject DI,其中包含来自 Asp.Net 堆栈(MVC、Web Api 2、SignalR)的一系列技术。
我已经通过以下方法使 DI 适用于所有使用的技术:
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop()
{
bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
internal static IKernel CreateKernel()
{
var …Run Code Online (Sandbox Code Playgroud)