简体   繁体   中英

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)? Is this possible to just work in AutoMapper?

If this isnt what you need https://github.com/AutoMapper/AutoMapper/wiki/Lists-and-arrays

you could try 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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