Note that there are some explanatory texts on larger screens.

plurals
  1. POShowing a Form from Presenter in C#
    primarykey
    data
    text
    <p>I have more of an architectural question. I'm trying to implement MVP in C# as follows:</p> <ul> <li>IView creates Presenter</li> <li>IPresenter has a property IView which holds View, that is bound to it</li> <li>View CAN be Form, but Presenter does not distinguish between Form and non-Form types, so View can be swapped and the solution is to be testable</li> </ul> <p>What I sometimes need to do, is to open some other form. E.g., I have Browser view with DataGrid and when I double-click on a grid item or select something and click Edit button, Edit event is raised and Presenter acts.</p> <p>Now, Presenter needs to open a Editor view, which is also a Form, <em>but</em> the problem is, presenter should not construct the Form itself, because then it is impossible to Mock the View.</p> <p>I'm pretty struggling with the proper concept. My code looks something like this:</p> <pre><code>var editorView = new EditorForm(); editorView.Presenter.Entity = SelectedEntity; editorView.ShowDialog(View as Form); </code></pre> <p>Under the hood, EditorForm constructor constructs the presenter and assigns <em>this</em> (View instance) to the presenter:</p> <pre><code>public EditorForm() { Presenter = new EditorPresenter(this); InitializeComponents(); } </code></pre> <p>From the View perspective, I can swap it to MockView simply by implementing the Mock and then instantiating the same Presenter from MockView's constructor.</p> <p>I was searching for some other Q&amp;A here and over the web but did not find anything suitable.</p> <p>Thank you for all your hints.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload