I have implemented my own copy of the model view presentation template (in the form of factory web client software), so I can use my own DI infrastructure instead of binding to the WCBF ObjectBuilder, which I had a lot of problems with. I came up with several ways to do this, but none of them are particularly pleasing to me. I wanted to know if anyone has any other ideas.
Solution # 1a
Uses an HttpModule to intercept context.PreRequestHandlerExecute to call ObjectFactory.BuildUp (HttpContext.Current.Handler)
public partial class _Default : Page, IEmployeeView { private EmployeePresenter _presenter; private EmployeePresenter Presenter { set { _presenter = value; _presenter.View = this; } } }
Decision No. 1b
Call extension on page load instead of using HttpModule
public partial class _Default : Page, IEmployeeView { private EmployeePresenter _presenter; private EmployeePresenter Presenter { set { _presenter = value; _presenter.View = this; } } protected void Page_Load(object sender, EventArgs e) { ObjectFactory.BuildUp(this); } }
Solution # 1c
Access to the presenter via the property allows Getter to create a BuildUp, if necessary.
public partial class _Default : Page, IEmployeeView { private EmployeePresenter _presenter; public EmployeePresenter Presenter { get { if (_presenter == null) { ObjectFactory.BuildUp(this); } return _presenter; } set { _presenter = value; _presenter.View = this; } } }
Decision number 2
public partial class _Default : Page, IEmployeeView { private EmployeePresenter _presenter; private EmployeePresenter Presenter { get { if (_presenter == null) { _presenter = ObjectFactory.GetInstance<EmployeePresenter>(); _presenter.View = this; } return _presenter; } } }
Solution No. 2b
public partial class _Default : Page, IEmployeeView { private EmployeePresenter _presenter; private EmployeePresenter Presenter { get { if (_presenter == null) { Presenter = ObjectFactory.GetInstance<EmployeePresenter>(); } return _presenter; } set { _presenter = value; _presenter.View = this; } } }
Edit : added solution 1c, 2b
c # dependency-injection mvp structuremap
Chris marisic
source share