17

私は今週末にASP.net MVPパターンについて読んでいます.MVPパターンでそれを行うと、最も単純なタスクでさえ多大な労力を費やすように思えます.より大きなプロジェクトで見返りが得られるようですが、 MVPに続きます。ASP.net MVC でプロジェクトを実行しないのはなぜですか?

私が MVP パターンを見ている理由は、すべての ASP.net Webform プロジェクトで、Web 上に多くのサーバー コントロールがある場合、イベント処理のためだけにコード ビハインドに多くのコードがあることに気付いたからです。フォームなので、それを減らしてMVPパターンに出くわす方法を探していました。

MVP パターンに従うこと、または単に ASP.net MVC に切り替えることに努力する価値はありますか?

4

5 に答える 5

20

I would recommend reading the following two links to get you up to speed on 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:

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.

于 2009-05-05T12:10:14.427 に答える
15

新しいプロジェクトを開始する場合は、ASP.net MVC を選択することをお勧めします。しかし、あなたが言ったように既存のプロジェクトをリファクタリングしたいだけなら、MVP がオプションです。これらの Web フォーム コードを MVC に変換する簡単な方法がないからです。

于 2009-05-04T02:22:05.707 に答える
3

新しいプロジェクトであれば Asp.Net MVC を使用しますが、MVP は従来の Web フォーム プロジェクトに適したパターンであることに同意します。

これは私のブログの例です: http://www.unit-testing.net/CurrentArticle/How-To-Use-Model-View-Presenter-With-AspNet-WebForms.html

于 2012-03-06T05:26:18.110 に答える
3

私の意見では、新しいアプリケーションの理想的な方法は MVC です。ただし、既に WebForms を使用しているコードが多数ある場合は、MVP パターンが最適です。

于 2009-05-04T02:22:19.853 に答える
2

私の個人的な意見では、コード ビハインドに多くのコードがある場合、それをスリム化し、リファクタリングしてテスト可能にするために、MVP を採用する以外の方法がまだあるということです。

ページに広範なユーザー操作 (ボタン/リンクの有効化/無効化、パネルやコントロールの表示/非表示など) がある場合、MVP は手間をかける価値があります。

于 2009-05-04T02:19:18.940 に答える