I’m creating a sample to illustrate the MVP (Supervising Controller and Passive View) pattern for use with a legacy .NET WebForms application. To help with some separation of concerns I’m also going to lightly introduce StructureMap to wire up the presentation layer with DAOs/Repositories as needed.
My question is what part of the application should be calling the ObjectFactory.GetInstance<T>() methods? I’ve been calling them in the View, since the View news up its corresponding presenter, something like this:
partial class CustomerDetails : Page, ICustomerDetailsView
{
private readonly CustomerDetailsPresenter _presenter;
public CustomerDetails()
{
var rep = ObjectFactory.GetInstance<ICustomerRepository>();
this._presenter = new CustomerDetailsPresenter(this, rep);
}
// do work down here with normal ASP.NET events...
}
but I’m not sure if there’s a better place to handle the object creation; putting it in the view almost makes me think as though the view knows too much about what’s going on (it knows about repositories and StructureMap, instead of just knowing about presenters), but I can’t think of any other place where this kind of code should live.
Here is a good example of using structuremap with asp.net webforms