You can put it in the application_start()
of the global.asax
Currently I have a static method that I call from the application_start that initializes all my mappings. Library.AutoMapping.RegisterMaps();
AutoMapper.Mapper.CreateMap(typeof(CoolObject), typeof(CoolObjectViewModel));
AutoMapper.Mapper.CreateMap<CoolObject, CoolObjectViewModel>()
.ForMember(d => d.Property1, f => f.MapFrom(s => s.Property1))
.ForMember(d => d.Property2, f => f.MapFrom(s => s.Property2))
.ForMember(d => d.Property3, f => f.MapFrom(s => s.Property3));
So my Controller looks something like this. You'll notice that the HomeController constructor requires an IDataContext. I register IDataContext with Ninject on a RequestScope level and a DataContext is instantiated for me and injected into my controller. This is where my request level repository comes from.
public class HomeController : Controller {
IDataContext dataContext;
public HomeController(IDataContext dataContext) {
this.dataContext = dataContext;
}
}
I have a slightly more detailed explanation about Ninject here http://buildstarted.com/2010/08/24/dependency-injection-with-ninject-moq-and-unit-testing/