I have one more architectural question. I am trying to implement MVP in C # as follows:
- IView creates a presenter
- IPresenter has an IView property that contains the View that is associated with it.
- View CAN be Form, but Presenter does not distinguish between Form and non-Form types, so View can be swapped and the solution should be checked
What I sometimes need to do is open another form. For example, I have a browser view using a DataGrid, and when I double-click on a grid element or select something and click the "Edit" button, the "Edit" event appears and the "Lead" is active.
Now Presenter needs to open the editor's view, which is also a form, but the problem is that the moderator should not create the Form itself, because then it is impossible to execute the Mock View.
I'm pretty struggling with the right concept. My code looks something like this:
var editorView = new EditorForm(); editorView.Presenter.Entity = SelectedEntity; editorView.ShowDialog(View as Form);
Under the hood, the EditorForm constructor creates a presenter and assigns this (view instance) to the presenter:
public EditorForm() { Presenter = new EditorPresenter(this); InitializeComponents(); }
In the perspective of the View, I can change it to MockView by simply executing Mock and then instantiating the same Presenter from the MockView constructor.
I searched for some other Q&A here and over the Internet, but did not find anything suitable.
Thank you for all your tips.
source share