I've implemented my own copy of the model view presenter pattern (in vein of web client software factory) so I can leverage my own DI framework instead of being tied to WCSF's ObjectBuilder which I had numerous problems with. I've come up with a few ways to do it but none of them particularly make me happy. I wanted to know if anyone else had some other ideas.
Solution #1a
Uses a 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;
}
}
}
Solution #1b
Call buildup in page load instead of using a 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 presenter through Property allow Getter to BuildUp if needed.
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;
}
}
}
Solution #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 #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