我已經繼承了一些具有所有靜態方法的AuthenticationManager類的代碼。你如何重構靜態類來使用依賴注入?
進出口引進DI和想補充一點,採取了依賴UserController的
UserController _userController;
public AuthenticationManager(UserController userCont)
{
_userController = userCont;
}
現在即時得到編譯時錯誤作爲一個非靜態變量從一個靜態方法引用的構造函數。您的最佳實踐建議是什麼,以使這個工作與這個類和調用代碼的最小變化?
我們使用SimpleServiceLocator作爲IOC容器。
難道不是升級到[Simple Injector](http://simpleinjector.codeplex.com)的時候嗎?我停止開發簡單服務定位器。 – Steven 2011-12-23 15:59:58
感謝您的提示 - 我不知道簡單的注射器存在!簡單注射器是否提供瞭解決我的問題的額外功能,還是隻是一件好事? – 2011-12-28 00:20:39
它沒有解決你的問題,但簡單的注射器更快,更乾淨,並且有更好的支持來添加擴展(這裏描述的大多數高級場景[http://simpleinjector.codeplex.com/wikipage?title = Advanced-scenarios&referTitle = Documentation)不能用SSL實現)。您可以閱讀關於核心差異的信息SI SSL [here](http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=87)。 – Steven 2011-12-28 10:27:13