I'm using AutoMapper for the 1st time and soon saw the latest version had deprecated the Mapper.Initialize() and Mapper.Map<>() APIs in favor of CreateMapper and MapperConfiguration instead.
The problem is I've found the documentation and general help online to be greatly lacking for these new API's. I figured out the syntax mapping DB Entity objects to Business layer objects but am unsure about the syntax with MapperConfiguration to initialize for multiple mappings. I.e. I've got a mapping from my PTT_Event class to Event, but need to map several other classes PTT_Address to Address, etc. I would like to use just 1 MapperConfiguration class to perform mappings for all my objects of course and not 1 MapperConfiguration class for each set of mappings needed.
I.e. how do initialize MapperConfiguration object with multiple mappings (PTT_Event -> Event, PTT_Address -> Address, etc)?
Sample code below (prototype code so its bit messy):
mapperConfig = new MapperConfiguration(cfg => cfg.CreateMap < Event, PTT_Event >().ReverseMap());
autoMapper = mapperConfig.CreateMapper();
[TestMethod]
public void GetEventById(int eventid)
{
Event reqEvent = null;
using (var context = new PTDLinkRupeeEntities())
{
PTT_Event dbEvent = context.PTT_Event
.Where(e => e.EventId == eventId)
.Select(e => e)
.FirstOrDefault();
reqEvent = autoMapper.Map<Event>(dbEvent);
Assert.IsNotNull(reqEvent, "Not seeing event returned for eventId {0}.", eventId);
}
}