Where in my ASP.NET MVC application should I define my AutoMapper mappings?
Mapper.CreateMap<User, UserViewModel>();
Presently I am defining these in the constructor of a BaseController, which all my Controlllers derive from. Is this the best place?
I think it’s kind of late to answer the question, but maybe someone can use my answer.
I use Ninject to resolve dependencies, so I’ve created Ninject Module for AutoMapper. Here is the code:
As you can see on load it scans assembly for implementaion of IViewModelMapping and then runs Create method.
Here is the code of IViewModelMapping:
Typical implementation of IViewModelMapping looks like this: