C# .NET WinForms 应用程序的 MVC/MVP 框架

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/536888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 07:13:59  来源:igfitidea点击:

MVC/MVP framework for .NET WinForms applications

c#.netwindowswinformsframeworks

提问by Alexander

Does anybody know a useable MVC/MVP framework for enterprise WinForms applications?

有人知道企业 WinForms 应用程序的可用 MVC/MVP 框架吗?

Before there was User Interface Process Application Block for .NET. But it is not longer under development since Windows Workflow Foundationhas been released (which also will be completely rewritten with .NET 4.0).

在有用于 .NET 的用户界面进程应用程序块之前。但自从Windows Workflow Foundation发布后,它就不再处于开发阶段(也将用 .NET 4.0 完全重写)。

Maybe i am not up-to-date, but i seems to me like there is a gap at the moment.

也许我不是最新的,但在我看来,目前存在差距。

采纳答案by Dylan Smith

Microsoft has the Composite Application Block (CAB) for use with WinForms applications. While not technically an MVC/MVP implementation, it does provide nice separation between UI code and non-UI code: http://msdn.microsoft.com/en-us/library/aa480450.aspx

Microsoft 具有用于 WinForms 应用程序的复合应用程序块 (CAB)。虽然技术上不是 MVC/MVP 实现,但它确实在 UI 代码和非 UI 代码之间提供了很好的分离:http: //msdn.microsoft.com/en-us/library/aa480450.aspx

It is also fairly popular to just do it yourself without using any frameworks as long as you are comfortable with the relevant patterns. Jeremy Miller has an excellent series of articles on some best practices when taking this approach:

只要您对相关模式感到满意,不使用任何框架而自行完成也是相当流行的。Jeremy Miller 有一系列关于采用这种方法的最佳实践的优秀文章:

Build your own CAB Part #1 - The Preamble

构建您自己的 CAB 第 1 部分 - 序言

Build your own CAB Part #2 - The Humble Dialog Box

构建您自己的 CAB 第 2 部分 - 不起眼的对话框

Build your own CAB Part #3 - The Supervising Controller Pattern

构建您自己的 CAB 第 3 部分 - 监督控制器模式

Build your own CAB Part #4 - The Passive View

构建您自己的 CAB 第 4 部分 - 被动视图

Build your own CAB Part #5 - The Presentation Model

构建您自己的 CAB 第 5 部分 - 演示模型

Build your own CAB Part #6 - View to Presenter Communication

构建您自己的 CAB 第 6 部分 - 查看演示者通信

Build your own CAB - Answering some questions

建立自己的 CAB - 回答一些问题

Build your own CAB Part #7 - Whats the Model?

构建您自己的 CAB 第 7 部分 - 模型是什么?

Build your own CAB Part #8 - Assigning Responsibilities in a Model View Presenter Architecture

构建您自己的 CAB 第 8 部分 - 在模型视图展示器架构中分配职责

Build your own CAB Part #9 - Domain Centric Validation with the Notification Pattern

构建您自己的 CAB 第 9 部分 - 使用通知模式进行以域为中心的验证

Build your own CAB Part #10 - Unit Testing the UI with NUnitForms

构建您自己的 CAB 第 10 部分 - 使用 NUnitForms 对 UI 进行单元测试

Build your own CAB Part #11 - Event Aggregator

构建您自己的 CAB 第 11 部分 - 事件聚合器

Build your own CAB Part #12 - Rein in runaway events with the "Latch"

构建您自己的 CAB 第 12 部分 - 使用“Latch”控制失控事件

Build your own CAB Part #13 - Embedded Controllers with a Dash of DSL

构建您自己的 CAB 第 13 部分 - 带有 DSL 的嵌入式控制器

回答by Kieron

Have you tried MVC#? I started using it a while back, but the project fell by the wayside, so I can't vouch for it to much - sorry!

你试过MVC#吗?不久前我开始使用它,但该项目搁浅了,所以我不能保证太多 - 抱歉!

EDIT:I just found thisarticle which looks pretty good too.

编辑:我刚刚发现这篇文章看起来也很不错。

回答by Bertvan

Smart Client Software Factory?

智能客户端软件工厂?

回答by Duncan

I've always rolled my own - it's not really difficult and the more I am in 'control' of my codebase the better I feel.

我总是自己动手 - 这并不难,我对代码库的“控制”越多,我的感觉就越好。

I just wonder how an MVC framework would fit in with, say, CastleWindsor or the like?

我只是想知道 MVC 框架如何适应,比如说,CastleWindsor 之类的?

This probably isn't the most helpful of answers but just wondering if you have already considered this option!

这可能不是最有帮助的答案,只是想知道您是否已经考虑过这个选项!

回答by Wolfwyrd

We use the Smart Client Software Factory from MS. It provides IDE integration, full MVC support and once you get over the concepts behind it is a very competent implementation. You can acquire it from: http://msdn.microsoft.com/en-us/library/aa480482.aspx

我们使用 MS 的 Smart Client Software Factory。它提供了 IDE 集成、完整的 MVC 支持,一旦你了解了它背后的概念,它就是一个非常有能力的实现。您可以从以下位置获取它:http: //msdn.microsoft.com/en-us/library/aa480482.aspx

回答by Rinat Abdullin

I didn't like Prism, CAB or SmartClient for being too complex and ended up rolling out my own implementations, in the end.

我不喜欢 Prism、CAB 或 SmartClient,因为它们太复杂了,最后我推出了自己的实现。

As time goes, some common patterns are emerging. These are get reused from an application to an application. Here is an example: DDD and Rule driven UI Validation in Windows.Forms with MVC.

随着时间的推移,一些常见的模式正在出现。这些从应用程序到应用程序被重用。这是一个示例:Windows.Forms 中使用 MVC 的 DDD 和规则驱动的 UI 验证

回答by Rinat Abdullin

I'm plugging my own framework : TrueView for .NET. It's based on DDD and the Naked Objects pattern.

我正在插入我自己的框架:TrueView for .NET。它基于 DDD 和裸对象模式。

At the very least, using it to create quick prototypes is a great way to get decent feedback from your business users.

至少,使用它来创建快速原型是从业务用户那里获得良好反馈的好方法。

回答by Rinat Abdullin

All these standard frameworks are not suitable for large complex application developments and they assume that the displays will be static. I have developed my own as well due to the common requirement that the screen controls have to be dynamic, even the MVC/MVP patterns assume that the display will be static so when the fields diplayed in a control depend on what role a user has the MVC/MVP patterns are not suitable. I have developed a tool where you can build the screens from loading up the business objects and their properties into a database then the user just selects the objects and object properties she wants to display, a control can be made up of any number of control groups, each control group can contain any business object property, the business objects are generated from views by my Linq ORM. A control will therefore only display the fields of the control groups that a user has access to. You could also use Aspect orientated programming to provide the gule for the MVC pattern but when the displays have to be dynamic based on the role this overhead would probably add a little to much complexity and performance cost.

所有这些标准框架都不适用于大型复杂应用程序的开发,并且它们假定显示将是静态的。由于屏幕控件必须是动态的共同要求,我也开发了自己的控件,即使 MVC/MVP 模式也假设显示将是静态的,因此当控件中显示的字段取决于用户具有的角色时MVC/MVP 模式不适合。我开发了一个工具,您可以通过将业务对象及其属性加载到数据库中来构建屏幕,然后用户只需选择她想要显示的对象和对象属性,一个控件可以由任意数量的控件组组成,每个控制组可以包含任何业务对象属性,业务对象是由我的 Linq ORM 从视图生成的。因此,控件将仅显示用户有权访问的控件组的字段。您还可以使用面向方面的编程来为 MVC 模式提供规则,但是当显示必须基于角色动态时,这种开销可能会增加一点到很多复杂性和性能成本。

回答by Dan Haywood

As well as TrueView, there's also Naked Objects for .NET. This supports client/server mode and a web viewer (based on a Java equivalent viewer) is currently being ported.

除了 TrueView,还有适用于 .NETNaked Objects。这支持客户端/服务器模式,并且当前正在移植 Web 查看器(基于 Java 等效查看器)。

As for which properties/actions are available for a given user/role, this is done dynamically in Naked Objects. There are three sorts of business rules preconditions that are supported: 1. is the member visible? 2. is the member usable? 3. is the change to the member (new property value or action parameter) valid? Or, more pithily: can you see it? can you use it? can you do it? The Naked Objects programming model lets these rules be specified both declaratively and imperatively.

至于给定用户/角色可以使用哪些属性/操作,这是在 Naked Objects 中动态完成的。支持三种业务规则前提条件: 1. 成员是否可见?2.会员可以使用吗?3. 对成员的更改(新的属性值或操作参数)是否有效?或者,更简洁地说:你能看到吗?你能用吗?你能做到吗?Naked Objects 编程模型允许以声明方式和命令方式指定这些规则。

Even if you end up wrapping your domain model in your own UI layer, I recommend you take a look at NO.

即使您最终将域模型包装在您自己的 UI 层中,我也建议您查看 NO。

Cheers

干杯

Dan Haywood

丹·海伍德

author: "Domain Driven Design using Naked Objects", pragprog.com

作者:“使用裸对象的域驱动设计”,pragprog.com

回答by Leniel Maccaferri

I've used with success the following open source project to implement the MVP pattern in ASP.NET + WinForms + C#:

我已经成功地使用以下开源项目在 ASP.NET + WinForms + C# 中实现了 MVP 模式:

  • Castle Project.
  • 城堡项目。

Take a look at my blog post which shows a complete ASP.NET Web Application sample:

看看我的博客文章,它展示了一个完整的 ASP.NET Web 应用程序示例:

Model View Presenter pattern with Castle in ASP.NET

在 ASP.NET 中使用 Castle 模型视图演示者模式