[RESOLVED]Where to place CreateMap

I am using Automapper, but unsure where to place the command CreateMap.

I have currently placed it in the constructor.

Please share your experience, much appreciated.

public OrderController()
{
this.repository = new OrderRepository();

Mapper.CreateMap<Order, OrderViewModel>();
Mapper.CreateMap<OrderViewModel, Order>();
}

I create an MappingConfig class and put the mappings in a static method in that. Then I call the static method in the Application_Start event in Global.asax, just like you do for ReouteConfig or BundlesConfig. The mappings only need to be created once in
the life time of the application. Recreating them every time the controller is instantiated is unnecessary.

Leave a Reply