in a classic Passive-MVP pattern, how can i avoid a reference of the presenter in my view completely & still inject the presenter instance which needs the view instance as a parameter.
with asp.net as an example:
- my implemented views (web project) should not have a reference to the Presenters. (Neither IPresenter nor the concrete ones)
- when the view instantiates, (basically my web page), the presenter should be instantiated with the current view’s reference.
- i am using unity as my ioc container.
right now what i do in the web page’s code behind is this:
public partial class SomePage : MyBasePage, ISomeView
{
private readonly ISomePresenter presenter;
public SomePage()
{
this.presenter = ResolveSomeWay(this);
}
}
for this i have a reference of the ‘Presenter Contracts DLL’ in my view implementation. is there a way to avoid this reference completely & still hook up the presenter with the view instance, when the view instantiates?
i just care about the presenter instantiation, since the presenter’s constructor can set the passed parameter-view-instance to its View Property & it subscribes to the view’s events, for any future communication.
thanks folks for your time.
You could “publish” a new View was instantiated to a Message Bus, to which a Presenter factory could “bind” the instantiated View to a Presenter. Although the View would be agnostic of the presenter, it would not be of the Message Bus.