Skip to content

Dependency injection

Lucian Bargaoanu edited this page Oct 16, 2016 · 11 revisions

AutoMapper supports the ability to construct Custom Value Resolvers and Custom Type Converters using static service location:

    Mapper.Initialize(cfg =>
    {
        cfg.ConstructServicesUsing(ObjectFactory.GetInstance);
        
        cfg.CreateMap<Source, Destination>();
    });

Or dynamic service location, to be used in the case of instance-based containers (including child/nested containers):

    var mapper = new Mapper(Mapper.Configuration, childContainer.GetInstance);

    var dest = mapper.Map<Source, Destination>(new Source { Value = 15 });
Clone this wiki locally