using MVP, what is the normal order of construction and dependency injection.
normally you create a presenter for each view and pass the view into the presenter on constructor. But what if you have:
- A Service that multiple views need to listen to events on.
- Multiple views all pointing to the same data model cache.
can someone display a normal flow of info from a user click to data coming back in a service from a server.
Here is what I do:
First, I define theses interfaces:
Then this abstract presenter class:
The view is injected via a property, instead of the constructor, to allow the bi-directional affection in the setter. Notice that a safe cast is needed…
Then, my concrete presenter is something like :
Where
IMyViewimplementsIView. A concrete view type must exists (e.g.MyView), but it’s the container that resolves it:MyPresentertype as itself in the container, with a transient behavior.MyViewas anIMyViewin the container with a transient behavior.MyPresenterto the container.MyPresenterAbstractPresenter.Viewproperty.It allows you to inject other dependencies (services, repos) into both your view and your presenter. But in the scenario you described, I recommend you to inject services and caches into the presenter, instead of the view.