【发布时间】:2012-07-03 15:22:56
【问题描述】:
我为MVP搜索了很多,但是我没有找到任何可以帮助我很好理解它的好文章。有谁知道关于这个主题的任何好文章,并附有真实世界的例子来帮助我更好地理解它?
提前致谢。
【问题讨论】:
我为MVP搜索了很多,但是我没有找到任何可以帮助我很好理解它的好文章。有谁知道关于这个主题的任何好文章,并附有真实世界的例子来帮助我更好地理解它?
提前致谢。
【问题讨论】:
查看我对 so 帖子的回答,这可能会对您有所帮助:
Is ASP.net Model View Presenter worth the time?
它讲述了 MVP 和 MVC 之间的差异,因为这两者经常是对比的。
此外,还有一些有用的链接,展示了如何轻松地将 MVP 模型拟合到现有的 ASP.Net 网站。
HTH
【讨论】:
如果您想深入了解此模式,请查看 Web Client Software Factory 2010 工具。
此工具主要用于创建复合 Web 应用程序(模块),但视图是使用 MVP 模式实现的。如果您要维护传统的 ASP.Net 代码,或者如果您想深入挖掘 ASP.Net 范式,那么检查该工具的源代码是一个很好的起点。
此工具需要您安装几个 Visual Studio 扩展,然后,您可以创建一个特殊的 Web 项目来为您实现 MVP,它会在 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 应该是一个更好的主意,如果你需要编辑一个现有的应用程序,你可以将 MVP 在 Web Client 中的实现作为基础软件工厂。
如果您有兴趣,我认为有一个解决方法可以将现有应用程序转换为使用 Web 客户端软件工厂
【讨论】:
ASP.NET Supervising Controller (Model View Presenter) From Schematic To Unit Tests to Code
Simplest example of MVP design patter of Asp.net
Model View Presenter with ASP.NET
Very Quick MVP Pattern to Use with ASP.NET
已编辑
另一个链接: Model View Presenter (MVP) Design Pattern with .NET - Winforms vs. ASP.NET Webforms
【讨论】:
这是一个专门在 asp.net 上做 mvp 的网站:http://webformsmvp.com/ MVP 作为一种模式已经有点过时了——MVC(它有一个很好的 asp.net 框架和支持)和 MVVM(事实上的 WPF 模式)已经在很大程度上取代了它。事实上,Martin Fowler(MVP 的发明者)已经在他的网站上记录了该模式确实应该分为两种模式,被动视图和监督控制器:http://martinfowler.com/eaaDev/ModelViewPresenter.html
【讨论】: