简体   繁体   English

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

[英]Use AutoMapper to Map Un-Mapped Members Via a DI Container

Given these classes: 给定这些类:

    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()
        {
            ...
        }
    }

And this configuration: 而这个配置:

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

How can I populate SalesManagers with AutoMapper using the SalesMangersBuilder class pulled from a DI container (StructureMap)? 如何使用从DI容器(StructureMap)中提取的SalesMangersBuilder类用AutoMapper填充SalesManagers Is this possible to just work in AutoMapper? 这可能仅适用于AutoMapper吗?

If this isnt what you need https://github.com/AutoMapper/AutoMapper/wiki/Lists-and-arrays 如果这不是您所需要的https://github.com/AutoMapper/AutoMapper/wiki/Lists-and-arrays

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

I has been a while since I played with automapper so to rusty to give a better answer. 自从我玩过automapper以来,我已经有段时间了,因此请生锈以给出更好的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM