ASP.NET MVC 3最佳实践/设计 [英] ASP.NET MVC 3 best practice / design

查看:89
本文介绍了ASP.NET MVC 3最佳实践/设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很多时间寻找设计使用EF 4.1或其他ORM一个ASP.NET MVC 3网站的最佳实践。我发现这个<一个href=\"http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application\"相对=nofollow>教程在ASP.NET MVC应用程序执行工作模式的存储库和单位。这是一个很好的教程,我学到了一些东西。因此,这让我思考,并希望从人们对堆栈知道这是什么,你会使用?如果不是,为什么?你是如何设计你的网站?我只是想学习正确的方式做事情,明白为什么一种方法是优于其他。

I have spent a lot of time searching for best practices for designing a ASP.NET MVC 3 web site using EF 4.1 or another ORM. I found this tutorial on Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application . It was a good tutorial and I learned something. So this got me thinking and wanted to know from the people on stack is this something you would use? if not why and how did you design your web site? I just want to learn the correct way to do things and understand why one way is better then the other.

推荐答案

先说实体框架实现了存储库模式和工作模式的单位。在现代ORM像实体框架之上实现工作模式库和单位是抽象的附加层是:

First to say Entity Framework implements a Repository pattern and a Unit of Work Pattern. Implementing Repository and Unit of Work patterns on top of a modern ORM like Entity framework is an additional layer of abstraction that:


  • 缩小底层ORM
  • 的可能性
  • 并没有提供额外的价值基础ORM

  • 充其量是毫无价值,但可能是有害的

这样的实现的目的之一是封装查询逻辑存储库,而不是一个查询像单一职责原则(的 SRP )建议,但一对夫妇的查询,从而违反了SRP。你可以做的是依靠你的ORM和单查询类封装广泛的查询逻辑。

One purpose of such implementations is to encapsulate the query logic in the Repository and not one query like Single Responsibility Principle (SRP) would suggest, but a couple of queries and thus violating SRP. What you could do is to rely on your ORM and encapsulate extensive query logic in single Query classes.

我的建议是不是通过抽象层将抽象层等讨好最佳做法,但尝试使用一些通用的设计指导等的 SOLID

My suggestion is not to please "best practices" by adding abstraction layers on abstraction layers and so on but to try to solve a problem using some more general design guidelines such as SOLID.

Ayende Rahien回顾了一系列博客文章的罗斯文入门套件的应用程序(<一个href=\"http://ayende.com/blog/153059/northwind-starter-kit-review-if-you-wonrsquo-t-respect-the-database-there-will-be-pain\"相对=nofollow>这里,的这里,<一个href=\"http://ayende.com/blog/153153/northwind-starter-kit-review-refactoring-to-an-actual-read-model\"相对=nofollow>这里,的这里,<一个href=\"http://ayende.com/blog/153057/northwind-starter-kit-review-the-parents-have-eaten-sour-grapes-and-the-childrenrsquo-s-teeth-are-set-on-edge\"相对=nofollow>这里,<一个href=\"http://ayende.com/blog/153029/northwind-starter-kit-review-data-access-and-the-essence-of-needless-work-part-ii\"相对=nofollow>这里,<一个href=\"http://ayende.com/blog/153028/northwind-starter-kit-review-data-access-and-the-essence-of-needless-work-part-i\"相对=nofollow>这里和这里 )在他的博客这一协议与应用程序中适用所谓的最佳实践。这是一个伟大的阅读!

Ayende Rahien reviews the Northwind Starter Kit application in a series of blog posts (here, here, here, here, here, here, here and here) in his blog that deal with so called best practices applied in an application. This is a great read!

这篇关于ASP.NET MVC 3最佳实践/设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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