我最近試用了Ninject
和Ninject.Web.Mvc
擴展名,我注意到了一些特殊的東西,雖然沒有打破,但令人困惑。Ninject和OnePerRequestModule
在NinjectHttpApplication
抽象類,沒有定義構造函數如下..
/// <summary>
/// Initializes a new instance of the <see cref="NinjectHttpApplication"/> class.
/// </summary>
protected NinjectHttpApplication()
{
this.onePerRequestModule = new OnePerRequestModule();
this.onePerRequestModule.Init(this);
}
我把一個調試器斷點這裏,這被稱爲幾次。我找不到任何真實的文檔。在實現代碼中,這條線引起了我的注意。
if (kernel.Settings.Get("ReleaseScopeAtRequestEnd", true))
{
OnePerRequestModule.StartManaging(kernel);
}
我的問題如下...
- 什麼是
OnePerRequestModule
- 爲什麼這個構造被稱爲多次?
- 這個
StartManaging
方法的目的是什麼,如果構造函數被多次調用?
相關:http://stackoverflow.com/questions/15778324/do-i-need-to-register-ninject-oneperrequestmodule-with-ninject-web-mvc-3-0/15786866# – 2013-04-03 12:28:57