ASP.NET MVC4 n-Tier架构:最佳实践方法

4
我正在开发一个MVC4 webapp + EntityFramwork5的三层架构。我希望保持分层,所以只有DAL知道我在使用EF。实际上,我有很多类来管理这些内容:
DAL
1. Entity POCO
2. Entity DataContext: DbContext
3. Entity Repository
BL
1. Entity ViewModel
2. Entity Service(实例化Entity Repository)
WEB
1. Entity Controllers (实例化Entity Service)
这样可以工作,但是维护起来很困难。我考虑移除DAL中的Entity Repository并直接使用DataContext(如果我没有错的话,毕竟DbContext既是Repository又是UnitOfWork),但这将迫使我在BL中添加对EntityFramework.dll的引用。这不是什么大问题,但我不确定是否是最好的选择。
有什么建议吗?

我不太确定你为什么提到项目难以维护。你认为哪一层难以维护? - cat916
例如,如果我向POCO添加一个字段,我需要更新数据上下文(不总是需要),dal存储库,BL视图模型,BL服务...不少...但在这种结构中可能是必须的(或设计错误)。 - Davide
1
嗨@Davide,你也可以为你的项目应用一些GOF设计模式。例如,如果你想给POCO添加一个字段,你可以使用“Builder”模式 :)。 - cat916
1个回答

5

You can use this this and this article.

An experienced Architect does not need to go through every single step in the book to get a reasonable design done for a small web

application. Such Architects can use their experience to speed up the process. Since I have done similar web applications before and have understood my deliverable, I am going to take the faster approach to get the initial part of our DMS design done. That will hopefully assist me to shorten the length of this article.

For those who do not have experience, let me briefly mention the general steps that involved in architecturing a software below...

Understand the initial customer requirement - Ask questions and do research to further elaborate the requirement
Define the process flow of the system preferably in visual (diagram) form. I usually draw a process-flow diagram here. In my

effort, I would try to define the manual version of the system first and then would try to convert that into the automated version while identifying the processes and their relations. This process-flow diagram that we draw here can be used as the medium to validate the captured requirements with the customer too. Identify the software development model that suite your requirements When the requirements are fully captured and defined before the design start, you can use the 'Water-Fall' model. But when the requirements are undefined, a variant of 'Spiral' can be used to deal with that. When requirements are not defined, the system gets defined while it is being designed. In such cases, you need to keep adequate spaces in respective modules, which later expansions are expected. Decide what architecture to be used. In my case, to design our Document Management System (DMS), I will be using a combination of ASP.NET MVC and Multitier Architecture (Three Tier Variant). Analyze the system and identify its modules or sub systems.
Pick one sub system at a time and further analyze it and identify all granular level requirements belonging to that part of the systems. Recognize the data entities and define the relationships among entities (Entity Relationship Diagram or ER Diagram). That can followed by identifying the business entities (Some business entities directly map with the classes of your system) and define the business process flow. Organized your entities. This is where you normalize your database, and decide what OOP concepts and design pattern to be used etc.
Make your design consistent. Follow the same standards across all modules and layers. This includes streamlining the concepts (as an example, if you have used two different design patterns in two different modules to achieve the same goal, then pick the better approach and use that in both the places), and conventions used in the project. Tuning the design is the last part of the process. In order to do this, you need to have a meeting with the project team. In that meeting you need to present your design to your team and make them ask questions about it. Take this as an opportunity to honestly evaluate/ adjust your design.


请您明确说明这是来自您第一参考资料的长引用,并包含编号列表,谢谢。很高兴您没有提供仅链接答案。 - Gert Arnold

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接