我正在使用MVP模式創建ASP.NET Web窗體應用程序。我的觀點的結構是這樣的:在使用MVP構建的ASP.NET Web窗體應用程序上應用依賴注入模式
public partial class ShipperView : System.Web.UI.Page, IShipperView
{
ShipperPresenter presenter;
public ShipperOperationsView()
{
IShipperOperations operations = new ShipperOperations();
INavigator navigator = new Navigator();
presenter = new ShipperPresenter(this,operations,navigator); //Instantiating presenter
}
...
}
我演講的基本結構是這樣的:
public class ShipperPresenter
{
IShipper shipperView;
IShipperOperations operations;
INavigator navigator;
public ShipperPresenter(IShipperView view,IShipperOperations operations,INavigator navigator)
{
shipperView = view;
this.operations = operations;
this.navigator = navigator;
}
...
}
我不想使用new關鍵字來實例化我的演講,我想用解決依賴性來取代它。在依賴關係解析期間,我想將當前視圖的實例傳遞給依賴關係解析器。我嘗試了很多,但沒有得到任何滿意的答案。
使用任何IoC容器(如StructureMap,Ninject,Unity或MEF)可以解決此問題嗎?任何指針都會有很大的幫助。
相關:http://stackoverflow.com/questions/8324678/c-sharp-asp-net-dependency-injection- with-ioc-container-complications – Steven