我們有一個非常基本的Owin應用程序,我們希望使用Ninject來解決我們的依賴關係。我想指出的是,沒有涉及Web API或MVC或其他中間件。Ninject範圍每Owin上下文
我們建立了這樣的內核:
private static StandardKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<Test>().ToSelf().InRequestScope();
kernel.Load(Assembly.GetExecutingAssembly());
return kernel;
}
Test類是簡化問題的更好的解釋。
我們試圖建立Ninject並註冊內核followoing:
app.UseNinjectMiddleware(CreateKernel);
我真的不知道這是要走的路,但無法找到文件等類似的東西
我們想要的是在Owin請求的範圍內解析一個Test實例。假設我們有以下中間件:
app.Use((context,next) =>
{
// How to access my Ninject Kernel or our test instance here?
return next.Invoke();
});
app.Use((context,next) =>
{
// How to access the same Ninject Kernel or our Test instance here?
return next.Invoke();
});
有沒有人知道如何做到這一點???