I use the following method as described in the following answer to create an instance of a mapper:
var platformSpecificRegistry = AutoMapper.Internal.PlatformAdapter.Resolve<IPlatformSpecificMapperRegistry>();
platformSpecificRegistry.Initialize();
var autoMapperCfg = new AutoMapper.ConfigurationStore(new TypeMapFactory(), AutoMapper.Mappers.MapperRegistry.Mappers);
var mappingEngine = new AutoMapper.MappingEngine(_autoMapperCfg);
As described by the following question:
AutoMapper How To Map Object A To Object B Differently Depending On Context.
How would I be able to use[reuse] an Automapper profile class like the following to create an instance of a mapper?
public class ApiTestClassToTestClassMappingProfile : Profile
{
protected override void Configure()
{
base.Configure();
Mapper.CreateMap<ApiTestClass, TestClass>()
.IgnoreAllNonExisting();
}
}
Just to give you an idea on why I require such functionality: I register all Automapper Profile classes into my IoC container [CastleWindsor] using the following method :
IoC.WindsorContainer.Register(Types.FromThisAssembly()
.BasedOn<Profile>()
.WithServiceBase()
.Configure(c => c.LifeStyle.Is(LifestyleType.Singleton)));
var profiles = IoC.WindsorContainer.ResolveAll<Profile>();
foreach (var profile in profiles)
{
Mapper.AddProfile(profile);
}
IoC.WindsorContainer.Register(Component.For<IMappingEngine>().Instance(Mapper.Engine));
While above completely fulfills the need for initializing my static Mapper class, I really dont have any idea how to re-use my Automapper profile classes for creating instance mappers [using non-static mapper].