Webforms MVP Passive View - Event Processing

If there is no event specific to a particular event in your interface and call simple presenter methods to handle events and not have any official EventHandlers? For example,

// ASPX protected void OnSaveButtonClicked(object sender, EventArgs e) { _Presenter.OnSave(); } 

Or if the view has an EventHandlers event defined in its interface and link them explicitly to control events on the page

 // View public interface IView { ... event EventHandler Saved; ... } // ASPX Page implementing the view protected override void OnInit(EventArgs e) { base.OnInit(e); SaveButton.Click += delegate { Saved(this, e); }; } // Presenter internal Presenter(IView view,IRepository repository) { _view = view; _repository = repository; view.Saved += Save; } 

The second is like a whole plumbing code that you need to add in everything.

My intention is to understand the benefits of each style, not just the full answer to it. My main goals are clarity and high value. General testability is important, but I would not sacrifice the simplicity and clarity of the design in order to be able to add another type of test that does not lead to too much gain compared to existing test cases with a simpler design. If the design choice is more testable, please include an example (pseudo-code in order) of the type of test that it can now offer, so I can decide if I really appreciate this type of additional test. Thanks!

Update: Do I need my question for further clarification?

+6
c # tdd mvp webforms
source share
3 answers

In your browsing interface, you should have a link to the save button, and then everything is done in this document. This allows your view without code and your presenter to be easily verified.

 // View interface public interface IView { Button SaveButton; } // View code behind public Button SaveButton { get { return btnSave; } } // Presenter internal Presenter(IView view,IRepository repository) { _view = view; _repository = repository; view.SaveButton.Click += new EventHandler(Saved);; } void Saved(object sender, EventArgs e) { // do save } 

-3
source share

I don't like having an explicit link to a button (or any other control) in the interface. This means that we are closely related to the implementation of the control.

Controls can be implemented differently between project types (e.g. Winforms and ASP).

This means that the interface may need to be changed for different views, which we do not want. The whole point of MVP is that Presenter can rely on a stable interface, which allows you to separate the user interface from the model, easily substitute for specific views and testability.

It is better to stick to interface properties and methods that are independent of any specific controls and leave implementation details to specific representations.

+6
source share

We have just implemented MVP using web forms and have chosen a simpler option for using methods of invoking a view on the presenter directly for button events, etc.

Our excuse is that we cannot see the unit test in any case (we use waitin to test this layer), so the main goal here is to have a single testable host that is as separate as possible from the view / model.

In my experience, you will never achieve completely pure MVP in WebForms anyway due to the nature of the beast (they really like to use this code behind the file ...), so I wouldn't hang on it.

At the end of the day, you need to evaluate the reasons for separating presentation logic and presentation and determine if any method will help you / discourage you later.

+1
source share

All Articles