私はMVPをたくさん検索しましたが、それをよく理解するのに役立つ良い記事は見つかりませんでした。私がそれをよりよく理解するのを助けるために実際の例で、誰かが主題に関する良い記事を知っていますか?
前もって感謝します。
あなたを助けるかもしれないので、ポストへの私の答えをチェックしてください:
ASP.net Model View Presenter は時間の価値がありますか?
MVP と MVC はしばしば対比されるため、MVP と MVC の違いについて説明します。
また、MVP モデルを既存の ASP.Net Web サイトに簡単に適合させる方法を示す役立つリンクもいくつかあります。
HTH
asp.netでmvpを実行することに専念しているサイトは次のとおりです。http ://webformsmvp.com/ パターンとしてのMVPはやや時代遅れです-MVC(優れたasp.netフレームワークとサポートを備えています)とMVVM(WPFの事実上のパターン) )主に引き継いでいます。実際、Martin Fowler(MVPの発明者)は、彼のサイトでパターンをパッシブビューと監視コントローラーの2つのパターンに分割する必要があることを文書化しています:http://martinfowler.com/eaaDev/ModelViewPresenter.html
このパターンをさらに詳しく知りたい場合は、Web Client Software Factory 2010ツールを参照してください。
このツールは基本的に複合 Web アプリケーション (モジュール)を作成するために使用されますが、ビューは MVP パターンを使用して実装されます。従来の ASP.Net コードを維持する場合、または ASP.Net パラダイムをもう少し掘り下げたい場合は、このツールのソース コードを確認することから始めるのが最適です。
このツールでは、Visual Studio にいくつかの拡張機能をインストールする必要があります。その後、MVP を実装する特別な Web プロジェクトを作成できます。これにより、タスクを容易にするために Visual Studio にコンテキスト メニューが追加されます。
例:
デフォルトの生成コードを確認します。
public partial class MyNewView : Microsoft.Practices.CompositeWeb.Web.UI.Page, IMyNewViewView
{
private MyNewViewPresenter _presenter;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this._presenter.OnViewInitialized();
}
this._presenter.OnViewLoaded();
}
[CreateNew]
public MyNewViewPresenter Presenter
{
get
{
return this._presenter;
}
set
{
if (value == null)
throw new ArgumentNullException("value");
this._presenter = value;
this._presenter.View = this;
}
}
// TODO: Forward events to the presenter and show state to the user.
// For examples of this, see the View-Presenter (with Application Controller) QuickStart:
//
}
public interface IMyNewViewView
{
}
public class MyNewViewPresenter : Presenter<IMyNewViewView>
{
// NOTE: Uncomment the following code if you want ObjectBuilder to inject the module controller
// The code will not work in the Shell module, as a module controller is not created by default
//
// private IShellController _controller;
// public MyNewViewPresenter([CreateNew] IShellController controller)
// {
// _controller = controller;
// }
public override void OnViewLoaded()
{
// TODO: Implement code that will be executed every time the view loads
}
public override void OnViewInitialized()
{
// TODO: Implement code that will be executed the first time the view loads
}
// TODO: Handle other view events and set state in the view
}
ツールで略奪する:
ところで、新しいプロジェクトを開始する場合は、MVC を使用することをお勧めします。既存のアプリケーションを編集する必要がある場合は、Web Client Software Factory での MVP の実装をベースとして使用できます。
興味のある方は、既存のアプリケーションを Web Client Software Factory を使用するように変換するためのワークスルーがあると思います。