Question

I'm following along with Pro ASP.NET MVC 4 and instead of creating a single MVC 4 project for the web application, the book advises creating a Visual Studio Solution (SportsStore) with two projects - SportsStore.Domain (a Class Library) and SportsStore.WebUI (an MVC 4 web app).

Rather than creating the models in the SportsStore.WebUI Models folder, they are created in an Entities folder in SportsStore.Domain and exposed through a repository. The book suggests that this is a convention/best practice.

Is this true? If so, why? And is this a common/best practice? Is this the general approach on most ASP.NET MVC applications or just larger ones?

Was it helpful?

Solution

Best practices almost never apply to every case and that's why we need you, the professional software developer, to make that judgment call. If you know that you are just creating a simple demo web app that will be thrown away, then it probably isn't worth the extra trouble of creating a separate project for your entities. In that case, time over extensibility is your priority.

Having said that, most real world projects do have a separate project for entities. Even if the entity project will only ever be used by your web project, sometimes the separation is good just to guide you to a good design.

As for repositories, they aren't always a good idea and sometimes create an abstraction that isn't needed. See Rob Conery's opinion on them for example.

OTHER TIPS

I'll just add to what Jason has stated. The whole idea behind the MVC framework is separation of concerns. With a separate project, you're allowing one person or team to work on that specific area of the application. Additionally, the project will have no idea what's going on with the rest of the application - it is there to just provide the entities (models).

Also, I've personally found that once you get into the UI aspect of the site, the MVVM pattern is especially useful. The screens rarely tend to be an exact match of your data structure, so the view model provides a nice intermediate between your view and your entities.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top