使用实体框架作为ORM的Winform应用程序的MVC或MVP架构 [英] MVC or MVP architecture for winform applications using Entity Framework as ORM

查看:209
本文介绍了使用实体框架作为ORM的Winform应用程序的MVC或MVP架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将开发一个相当规模的winform项目。我打算使用Entity Framework作为ORM工具。现在我正在寻找一个架构(MVC / MVP / MVVM等)来实现所有这些。首先,对于windows窗体的n层架构几乎没有选择,而我获得的大部分都是在EF进入市场之前写的。我从codeplex得到了一个名为Rocket Framework的框架( http://rocketframework.codeplex.com



我已经环顾四周了,但怀疑它会满足广泛的要求。如果有人已经发现了轮子,请引导我。
如果现有架构以前的EF4可以容纳它,我也可以尝试一下。
想法!

解决方案

您的选择受到您使用的技术的影响。一些技术有一定的自然选择,所以如果您(和每个开发人员)都不会明确地设计和关心这些技术,那么最终会产生最自然的感觉。 WinForms最自然的模式是MVP。你有你的看法,你可以在设计师中进行布局,代码隐藏文件成为主持人,基本上将视图和演示者结合在一个类中(这是一个1:1的关系)。对于Web应用程序,另一方面,MVC是一种自然的模式,因为您的Web服务器已经充当控制器。最后,MVVM在WPF中得到很好的支持,但是如果您开始使用文件后面的代码,您也可能会倾向于MVP。但是依靠DataBinding可以让你忘记使用后面的代码文件。我读过的一篇很好的文章是这里。当然,您可以使用WinForms实现MVVM,请阅读此链接一个很好的例子。



从可测性的角度来看,MVVM被视为最佳模式,因为您的视图模型(并且您的视图的行为)可以是测试没有实际的GUI。然而,MVP很容易理解和实现,不需要复杂的绑定,并且可以最大限度地控制正在发生的事件(例如事件抑制)。


I am going to develop a winform project of considerable size. I am planning to use Entity Framework as ORM tool. Now I am searching for an architecture(MVC/MVP/MVVM etc..) to implement all these. Firstly there are few choices for n-layered architecture for windows forms and most those I get are written prior to EF came into market. I got a framework called Rocket Framework from codeplex(http://rocketframework.codeplex.com)

I have looked around it but am skeptical that it will accommodate a wide range of requirements. If anyone has already discovered the wheel already, please guide me through. Also if the existing architectures prior EF4 can accommodate it than also I can give it a try. Ideas please!

解决方案

Well your choices is influenced by the technology you're using. Some technologies make a certain pattern natural to do and thus if you (and every developer) don't explicitely design and care about this you'll end up with what feels most natural. On WinForms the most natural pattern is MVP. You have your view that you can layout in the designer and your code-behind file becomes the presenter, essentially combining view and presenter in one class (it's a 1:1 relationship anyway). For web applications on the other hand MVC is a natural pattern since your web server already acts as a controller. Finally MVVM is supported very well in WPF, although you could fall towards MVP there as well if you start using the code behind file a lot. But relying on DataBinding instead can make you forget to use the code behind file. A good article I read about this is here. Of course you can realize MVVM with WinForms, read this link for a good example.

From the point of testability MVVM is perceived as the best pattern since your view model (and therefor the behavior of your view) can be tested without an actual GUI. MVP however is easy to understand and realize, doesn't require complex bindings and gives you most control over what is happening (e.g. event suppression).

这篇关于使用实体框架作为ORM的Winform应用程序的MVC或MVP架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆