January 10th, 2013, 11:10 AM
Extract ViewModel building code from ASP.NET MVC Controller
I believe that building ViewModel for a View from within Controller is a violation of SRP.
I would like to put that logic in a separate layer(service).
I consider (and tried) AutoMapper, but building ViewModel might require working with other services and models, which, I believe, is outside of "mapping" concept.
In ASP.NET MVC pipeline, what would be the best place to add such extension? Ideally I want my controller to be oblivious to the details of data being shown. I.e. if action results in a "user profile" view, I want controller to only express an intent of show user profile of user with id 5 and not have to go and hunt for user profile image from gravatar, or get list of group names user belongs to, or get a list of friends.