I’ve created an ASP.NET MVC 3 solution. It consists of three separate projects. I’m going to use Automapper and Unity. Each View has its own ViewModel.
The projects are:
- DATA (Code First Models and repository classes are located in this project)
- BUSINESS (Service classes are located in this project. DATA project is added as a reference.)
- WEB (WEB UI project. This is the MVC project. BUSINESS project is added as a reference.)
Now, I have 2 questions.
- Is this project structure a good practice?
- I’m trying to use Automapper with my service calls in the controllers. However If I use Automapper in the controller, I have to add DATA project as a reference in my WEB project in order to make conversions from POCOs to ViewModels. Shouldn’t the WEB project only interact with BUSINESS project?
Need assistance.
Thank you.
Question 1 This is subjective and this isn’t the best place to ask it. However for what it worth, the projects I maintain typically have a Core, Web, and Services project in them.
Question 2 No, based on your example and my experience, it is fine for your Web project to have references to your DATA and BUSINESS project. For us, our Web projects know about our Core and Services projects. However, our Services project does not have a reference to our Web project. For this reason, our Automapper configuration does know how to map to and from Service Models, View Models, and Entity Models.
Does this help? Let me know in the comments if you like me to elaborate. A little ways down on this blog you may find an image that depicts a similar project setup to what we use.