winforms - MVP Flow question -


i implementing mvp pattern windows form , have question current implementation trying fit more complex architecture. right have total agnostic view properties, presenter injected view in constructor , view has instance of presenter. code: view

public class myview : imyview {    public myview()    {       var presenter = new mypresenter(this);       presenter.init();    } } 

this presenter

public class mypresenter {    private imyview view;    private mymodel model;    //    public mypresenter(imyview view)    {       // injection       this.view = view;    } } 

in way can accomplish 2 tasks:

  • call methods on presenter view
  • interact view from presenter now, have 2 questions:
  • to orchestrate using ioc container can write code one:

    var view = ioc.resolve<imyview>(); var presenter = ioc.resolve<mypresenter>(); //view injected navigationservice.show(presenter.view); 

    so far good.

  • first question: how can model presenter when job done? presenter used view not same using ioc container view instantiate new presenter ... model exposed presenter not same used presenter instantiated in view

  • second question: how can pass existing model mvp triad when have one? example how can make code working details view model coming repository?

to have more clean approach inject model presenter, too

public class mypresenter {    private imyview view;    private mymodel model;     public mypresenter(imyview view, mymodel model)    {       this.view = view;       this.model = model    } } 

by doing have reference model outside of presenter created it.

when doing this, can choose model want use. example if backend (your model) not finished, write mock-model (when use interface model) test presenter , view.

hope helped


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -