Is ASP.net Model View Presenter worth the time?

后端 未结 5 1199
失恋的感觉
失恋的感觉 2021-01-31 10:56

I\'m reading about ASP.net MVP pattern over this weekend and it seem like even the most simple task take too much effort if do it in MVP pattern the pay off seem to be at larger

相关标签:
5条回答
  • 2021-01-31 11:32

    I would recommend reading the following two links to get you up to speed on MVP and MVC :

    • A great blog post by Gil Fink on the different advantages of MVP and MVC
    • A StackOverFlow question on whats the difference between MVP and MVC

    Should you switch over?
    Based on what you've told me I would recommend that you use the Passive MVP model mentioned in the article above.

    My main assumptions are:

    1. Your dealing with an existing codebase of WebForms apps
    2. You need to use ThirdParty .Net controls for existing functionality
    3. Your working on existing apps and don't have time to re architect them
    4. Any ASP.Net Web Apps you work on in the future, you can incrementally apply the passive MVP and get the benefits of TDD straight away

    Your View (codebehind + aspx) essentially become dumb and just perform simple tasks:

    • take information given by the presenter
    • responds to events and provides information back to the presenter

    I've used this model extensively for Web Forms development and I couldn't imagine not being able to Unit Test my Model and Presenter code. Once you establish your base model which doesn't take very long and seen the power of Unit Testing, working with Web Forms becomes enjoyable.

    Some links to MVP stuff that the model I've used is based on:

    • Easy Example of MVP model
    • Simple MVP model for ASP.Net
    • An MVP and MVC example for ASP.Net

    I would also recommend that you learn MVC to.
    When time permits, take an existing App and port it to MVC. This way your sole focus is getting to know MVC and when you move logic into the MVC pattern, you'll discover things that you implemented in WebForms and never gave much thought to but now need to solved in another way. Great way to compare the patterns and see what works for you.

    Hope this helps, feel free to ask any questions.

    0 讨论(0)
  • 2021-01-31 11:36

    In my opinion, the ideal way to go for new applications is MVC. However, if you have a lot of code already using WebForms, then the MVP pattern is the way to go.

    0 讨论(0)
  • 2021-01-31 11:43

    If you start a new project, then ASP.net MVC is a better choice. But if you just want to refactor an existing project as you just said, then MVP is the option because there is no easy way to convert those web-forms codes to MVC .

    0 讨论(0)
  • 2021-01-31 11:47

    I would go Asp.Net MVC if it's a new project, but I agree, MVP might be a good pattern for legacy webforms projects.

    Here's an example from my blog: http://www.unit-testing.net/CurrentArticle/How-To-Use-Model-View-Presenter-With-AspNet-WebForms.html

    0 讨论(0)
  • 2021-01-31 11:57

    my personal opinion is that if there's a lot of code in the code behind, there still are ways other than adopting M-V-P in order to slim it down, refactor and make it testable.

    if your page has extensive user interaction (like buttons/links enabling/disabling, panels and controls appearing/disappearing) M-V-P would be worth the hassle.

    0 讨论(0)
提交回复
热议问题