A colleague of mine suggested using a factory class for creating viewmodel objects in our ASP.NET MVC solutions. The idea being that it can help with the design, and maintainability, of the way viewmodels are built in our apps.
I wanted to find out if anyone else has experience of this. I've done some research and found very little on this practise.
Currently we create viewmodel objects at the controller level eg
public ActionResult Index()
{
return this.View(this.BuildIndexViewModel());
}
So this.BuildIndexViewModel() is responsible for creating the viewmodel class (obviously :). But we're looking into the possability of:
public ActionResult Index()
{
return this.View(ViewModelFactory.CreateIndexViewModel());
}
This is an interesting idea, but I'm not 100% convinced. I was interested in other people's opinions on this.
