使用静态服务地址

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 });
posted @ 2016-08-15 20:58  柠檬头  阅读(180)  评论(0编辑  收藏  举报