I have been reading countless articles about how to architect a new MVC 3 application using best practices.
90% of the articles combine the EF EDMX files into the same project as the MVC app. Those that do seperate these items into their own projects don’t clarify which project each goes into and what references each project has. Usually they consist of code snippets that are great to teach how to do a specific function, but don’t tell me how to architect the solution.
I believe that I need at least 5 projects in my solution. Can anyone tell me if I have the correct layout here?
- Data Access Layer – Contains the EF EDMX files. (Perhaps the DBContext auto-generated code?)
- Business Layer – Contains the IRepository and Repository classes, UoW classes, as well as the business logic for the domain. – Contains reference to DAL.
- ViewModels – Contains the viewmodels that will use AutoMapper to go between my DAL and the presentation layer. – Contains reference to DAL.
- MVC 3 App – Standard MVC 3 app. Contains references to the BusinessLayer and the ViewModels projects.
- Test – Unit testing.
Does this look right? Can anyone point me to a good article that uses n-tiered development with ViewModels, AutoMapper, Repository patterns and EF4?
I like the following
Domain – contains models and ViewModels
Services -business logic and viewmodel hydrating (ie population) code
Contracts or interfaces – repository interfaces, unit of work, IContext, and ICache
Web site
DataAccess – concrete implementation of entity framework
Some include their AutoMap code directly as an action filter as an attribute inside the web project. My automap code is done in the services project (but again this is up to you) unless I can use the attribute to do it in the controller.
btw see Jimmy’s nice attribute here:
http://lostechies.com/jimmybogard/2009/06/30/how-we-do-mvc-view-models/
What you have outlined above is fine as well though. This is a very subjective matter. My general recommendations are that ‘if someone can open a project and have an idea where to look for something, you are likely doing it correctly’