MVC Pattern, ViewModels, Location of conversion

asp.net-mvcmvc

I've been working with ASP.Net MVC for around a year now and have created my applications in the following way.

X.Web – MVC Application Contains
Controller and Views

X.Lib – Contains
Data Access, Repositories and
Services.

This allows us to drop the .Lib into any application that requires it.

At the moment we are using Entity Framework, the conversion from EntityO to a more specific model is done in the controller.

This set-up means if a service method returns an EntityO and then the Controller will do a conversion before the data is passed to a view.

I'm interested to know if I should move the conversion to the Service so that the app doesn't have Entity Objects being passed around.

Best Answer

I agree that you are doing it the right way. Jimmy Bogard (author of AutoMapper) wrote an excellent article on why this style of solution structure works and I follow this "guidance" whenever I can: http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/12/08/organizing-asp-net-mvc-solutions.aspx

However you should also focus on getting the right structure within you Library assembly. Richard Dingwall wrote an interesting article on organizing your code by responsibility rather than technology: http://richarddingwall.name/2009/08/08/real-life-ddd-organise-code-by-responsibility-layers-not-repositories-and-services/

Related Topic