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: stackoverflow.com/questions/119388/… stackoverflow.com/questions/127886/… stackoverflow.com/questions/2002220/… stackoverflow.com/questions/2178715/… stackoverflow.com/questions/1433192/… stackoverflow.com/questions/2540882 stackoverflow.com/questions/178398George Stocker– George Stocker2010-04-26 13:15:36 +00:00Commented Apr 26, 2010 at 13:15
-
1stackoverflow.com/questions/1637391/… stackoverflow.com/questions/26715/asp-net-mvc-subfolders stackoverflow.com/questions/2180704/…George Stocker– George Stocker2010-04-26 13:17:59 +00:00Commented Apr 26, 2010 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.
Comments
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.
Comments
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.