What is the best way to organize a MVC2 web project (as complex as stackoverflow)? should i have everything in one project? if not, how should i separate the projects and folders?
-
1See: http://stackoverflow.com/questions/119388/how-to-customize-directory-structure-in-asp-net-mvc http://stackoverflow.com/questions/127886/what-is-the-best-practice-for-view-file-directory-structure-in-asp-net-mvc http://stackoverflow.com/questions/2002220/changing-asp-net-mvc-default-folder-structure http://stackoverflow.com/questions/2178715/mvc-folder-structure-for-project-with-multiple-themes-skin http://stackoverflow.com/questions/1433192/c-mvc-folder-structure-where-to-put-classes http://stackoverflow.com/questions/2540882/ http://stackoverflow.com/questions/178398/ – George Stocker Apr 26 '10 at 13:15
-
1http://stackoverflow.com/questions/1637391/where-should-a-viewmodel-sit-in-the-directory-structure-of-an-asp-net-mvc-applica http://stackoverflow.com/questions/26715/asp-net-mvc-subfolders http://stackoverflow.com/questions/2180704/question-about-mvc-folder-structure – George Stocker Apr 26 '10 at 13:17
3 Answers
There's no best way. There are good and bad ways. Having everything in the same project is definitely not a good way. Big projects should be separated in layers and each layer usually goes into a different assembly so that it can be reused in other projects. For example you could have Models, Data Access, Business Logic, Web.
Jeffrey Palermo has a series of posts about the onion architecture which is worth reading.
From performance standpoint it is considered a good practice to have less bigger assemblies than many smaller assemblies.

- 1,023,142
- 271
- 3,287
- 2,928
Have a look at MVC Areas in MVC 2: http://msdn.microsoft.com/en-us/library/ee671793(VS.100).aspx
This is one way to organise code in larger projects.

- 24,079
- 20
- 92
- 147
I would start with a new ASP.NET MVC Project and then add a couple of more projects to your solution. I usually end up with:
MyProject
MyProject.Data
MyProject.Test
I normally put the generated classes from Subsonic (or other ORM tool) along with their repository classes in my .data project and my tests in the .test project. Apart from that, I use the main project as normal. Views in the Views folder, Models in the Models folder and so on.

- 5,433
- 2
- 21
- 30