有几点需要注意:
该OwinBootstrapper
组件将NinjectModule
在调用传入后加载任何已定义的 ',Func<IKernel>
因此您需要注意不要两次加载任何内容。看这里
该Bootstrapper
组件会Dispose
启动,IKernel
因此您需要确保在启动关闭后不要尝试访问该实例。看这里
您几乎可以在创建底层内核后立即访问它,也许您更愿意提出 PR 以使其可用?
目前OwinAppBuilderExtensions
定义
public const string NinjectOwinBootstrapperKey = "NinjectOwinBootstrapper";
它用于存储的运行时实例OwinBootstrapper
app.Properties.Add(NinjectOwinBootstrapperKey, bootstrapper);
OwinBootstrapper
持有对组件运行时实例的私有引用,Bootstrapper
而该Bootstrapper
实例又公开对组件运行时实例的引用IKernel
public IKernel Kernel
{
get { return kernelInstance; }
}
所以加了一点公关
public IKernel Kernel
{
get
{
this.bootstrapper.Kernel;
}
}
toOwinBootstrapper
可以IKernel
在app.Properties
调用app.UseNinjectMiddleware(() => container);
.