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 const
Here is what I do:
First, I define theses interfaces:
public interface IView
{
TPresenter Presenter { get; set; }
}
public interface IPresenter
where TView : IView
where TPresenter : IPresenter
{
TView View { get; set; }
}
Then this abstract presenter class:
public abstract class AbstractPresenter : IPresenter
where TView : IView
where TPresenter : class, IPresenter
{
protected TView view;
public TView View
{
get { return this.view; }
set
{
this.view = value;
this.view.Presenter = this as TPresenter;
}
}
}
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 :
public class MyPresenter : AbstractPresenter
{
//...
}
Where IMyView
implements IView
. A concrete view type must exists (e.g. MyView
), but it's the container that resolves it:
MyPresenter
type as itself in the container, with a transient behavior.MyView
as an IMyView
in the container with a transient behavior.MyPresenter
to the container.MyPresenter
AbstractPresenter.View
property.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.