2011-09-29 57 views
1

我正在使用Microsoft.Practices.ServiceLocation程序集與ninject一起幫助服務位置。註冊我ninject內核到服務定位提供方法:ninject和企業庫服務定位器相關的程序集

var kernel = new StandardKernel(); 
//do bindings 
var locator = new NinjectServiceLocator(kernel); 
ServiceLocator.SetLocatorProvider(() => locator); 

上面的代碼一切工作正常上安裝了企業庫(通過MSI可執行文件)的機器。我不能在生產環境中運行安裝程序,所以我在bin目錄中本地安裝了dll,希望這可以起作用。但它不起作用。我沒有得到任何程序集沒有發現異常,而是我得到一個對象引用沒有設置異常調用:'在Microsoft.Practices.ServiceLocation.ServiceLocator.get_Current()'。

我讀過幾個地方,這個程序集沒有任何依賴關係http://msdn.microsoft.com/en-us/library/ff664422%28v=PandP.50%29.aspx和本地dll應該做的伎倆,但它似乎並不。

我已經測試了幾個盒子,錯誤一直髮生,直到我運行安裝程序。有趣的是,我卸載庫後,它仍然有效(我猜它被緩存在某處)。

有沒有人有任何類型的問題的經驗?

回答

1

原來的問題是,servicelocator.current是空的,因爲我自動註冊的綁定模塊之一是缺少一個DLL。因爲引導程序被從global.asax調用,我的錯誤處理是假設要記錄任何異常並繼續(不希望整個站點停止這一頁)。所以我從來沒有得到reg錯誤,我的引導程序沒有告訴我失敗。

var kernel = new StandardKernel(); 
//do bindings -> throw error here without reaching below two lines to regiester the service locator 
var locator = new NinjectServiceLocator(kernel); 
ServiceLocator.SetLocatorProvider(() => locator);