Make using DI containers easier

Mar 15, 2013 at 12:50 PM
In the current implementation, the presenter base class has a constructor that takes in the View as argument. This causes a circular reference, which makes it much harder for DI containers to do its job, and do it in a fast way.

I think it would be good to add an extra constructor that doesn't take the view as an argument, and make the View settable as a property. This property can still have the proper checking to ensure it isn't set twice and isn't reset. However, breaking the dependency cycle by introducing a property makes DI support much easier, because you can simply resolve the concrete presenter and set the view afterwards, as can be seen in this example:
public IPresenter Create(Type presenterType, IView view)
{
    var presenter = (IPresenter)_container.GetInstance(presenterType);
    presenter.View = view;
    return presenter;
} 
For more info, see this discussion on stackoverflow.