使用AutoMapper通过DI容器映射未映射的成员

时间:2016-08-19 13:56:33

标签: c# dependency-injection automapper

鉴于这些课程:

    public class Source
    {
        public int SalesManager { get; set; }
    }

    public class Destination
    {
        public int SalesManager { get; set; }

        public SelectList SalesManagers { get; set; }
    }

    public class SalesManagersBuilder
    {
        public SalesManagersBuilder(IDataContext db)
        {
            _db = db;
        }

        private readonly IDataContext _db;

        public SelectList BuildList()
        {
            ...
        }
    }

这个配置:

 cfg.CreateMap<Source, Destination>().ForMember(x => x.SalesManagers,o => o.???);

如何使用从DI容器(StructureMap)中提取的SalesManagers类在AutoMapper中填充SalesMangersBuilder?这可能只适用于AutoMapper吗?

1 个答案:

答案 0 :(得分:0)

如果这不是你需要的 https://github.com/AutoMapper/AutoMapper/wiki/Lists-and-arrays

您可以尝试自定义值解析器 https://github.com/AutoMapper/AutoMapper/wiki/Custom-value-resolvers

自从我玩自动播放器以来,我已经有一段时间了,所以要生锈,以便给出更好的答案。