C# 理解模型视图表示(MVP)
我已经搜索了很多关于MVP的文章,但是我没有找到任何好的文章来帮助我更好地理解它。有人知道关于这个主题的好文章吗?有真实的例子来帮助我更好地理解它 提前谢谢。 已编辑 还有一个链接:C# 理解模型视图表示(MVP),c#,asp.net,mvp,C#,Asp.net,Mvp,我已经搜索了很多关于MVP的文章,但是我没有找到任何好的文章来帮助我更好地理解它。有人知道关于这个主题的好文章吗?有真实的例子来帮助我更好地理解它 提前谢谢。 已编辑 还有一个链接: 这里有一个网站专门介绍在asp.net上进行mvp: MVP作为一种模式已经有点过时了——MVC(它有一个很好的asp.net框架和支持)和MVVM(WPF的事实模式)已经在很大程度上占据了主导地位。事实上,Martin Fowler(MVP的发明者)已经证明,该模式确实应该分为两种模式,即被动视图和他的站点
这里有一个网站专门介绍在asp.net上进行mvp:
MVP作为一种模式已经有点过时了——MVC(它有一个很好的asp.net框架和支持)和MVVM(WPF的事实模式)已经在很大程度上占据了主导地位。事实上,Martin Fowler(MVP的发明者)已经证明,该模式确实应该分为两种模式,即被动视图和他的站点上的监控控制器:查看我对so帖子的回答,这可能会帮助您: 它通过MVP和MVC之间的差异进行分析,因为这两种差异经常是相互对比的。
此外,还有一些有用的链接,展示了如何轻松地将MVP模型适合现有ASP.Net网站
HTH如果您想深入了解这种模式,请查看Web客户端软件工厂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 }
public分部类MyNewView:Microsoft.Practices.CompositeWeb.Web.UI.Page,IMyNewViewView { 私人MyNewViewPresenter\u presenter; 受保护的无效页面加载(对象发送方、事件参数e) { 如果(!this.IsPostBack) { 这是。_presenter.OnViewInitialized(); } 此。_presenter.OnViewLoaded(); } [新建] 公共MyNewViewPresenter演示者 { 得到 { 返回此。\u演示者; } 设置 { 如果(值==null) 抛出新的ArgumentNullException(“值”); 这是。_presenter=值; this.\u presenter.View=此; } } //TODO:将事件转发给演示者并向用户显示状态。 //有关此示例,请参见视图演示器(带应用程序控制器)快速启动: // } 公共界面imynewview { } 公共类MyNewViewPresenter:Presenter { //注意:如果希望ObjectBuilder注入模块控制器,请取消注释以下代码 //该代码将不会在Shell模块中工作,因为默认情况下不会创建模块控制器 // //专用IShellController _控制器; //公共MyNewViewPresenter([CreateNew]IShellController) // { //_controller=控制器; // } public override void OnViewLoaded() { //TODO:实现每次加载视图时将执行的代码 } 公共覆盖无效OnViewInitialized() { //TODO:实现将在首次加载视图时执行的代码 } //TODO:处理其他视图事件并在视图中设置状态 }
如果您感兴趣,我认为要将现有应用程序转换为使用Web客户端软件工厂,需要进行一些工作。如果您维护或仍在构建ASP.Net应用程序,那么webformsmvp是值得学习的。