Is there any standard approach for defining projects in an ASP.NET MVC solution? [closed]

丶灬走出姿态 提交于 2020-01-15 12:32:27

问题


How should I logically define an ASP.NET MVC solution? Into how many projects must I divide my solution? Is there a standard approach for this? Like for example, a model class library, an MVC web application (comprising controllers & views), a unit test project, a repository project etc... What are the different types of project one can come up with?


回答1:


The answer is really depends. Depends of the scale of your project. You can have it all in one project (main MVC one) of you can split it further. The canonic form for this projects is something like that:

project.WEB
project.Common (here belongs common functionality between projects, so helpers, utilities, even some extension methods belong there)
project.Model (Data entities)
project.BL //(Business Logic)
project.DAL //(Data Access Layer or Persistence)
project.Tests

*note the "project" is your namespace root. How ho handle namespace naming you can check it there: namespace naming conventions

And the you can split it further and further. However I would suggest that you do not exaggerate with splitting it any further. When you will have to do it you will know (one project grow too much, there are logic separations ...). You try to follow the principle YAGNI.

And one more thing. If you want to be there "by the book" check it out DDD - Domain Driven Desing: http://msdn.microsoft.com/en-us/magazine/dd419654.aspx.




回答2:


This is a very broad question, but i will give you an example of what I did on my previous project. Firstly, it will depend on the complexities of the overall application, and the developers personal preference. A simple app could very well fit inside a single MVC 4 application.

Web Project - for the views using MVC4
Application - for business logic)
Data - for repositories and webservice methods)
Domain - for the objects used in the app
Utilities - for common functionality that needs to be used in more than one project

The example above fitted the project very nicely allowed me to separate all the concerns making it more maintainable.



来源:https://stackoverflow.com/questions/15267561/is-there-any-standard-approach-for-defining-projects-in-an-asp-net-mvc-solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!