Automapper通用地图零件

时间:2018-08-27 13:02:06

标签: c# mapping automapper automapper-6

即我有以下地图课程:

public class AutoMapperAddress : AutoMapper.Profile
{
    public AutoMapperAddress()
    {
        CreateMap<AddressDto, ViewModels.AddressElementAPI>();
    }
}

然后我应该在其他地方使用它,即:

public class AutoMapperLocation : AutoMapper.Profile
{
    public AutoMapperLocation()
    {
        // location mappers here
        // I need the same Address mapping as AutoMapperAddress has
    }
}

public class AutoMapperCarrier : AutoMapper.Profile
{
    public AutoMapperCarrier ()
    {
        // carrier mappers here
        // I need the same Address mapping as AutoMapperAddress has
    }
}

如何做到?

添加:

我试图在创建映射器对象期间解决它:

        mapper = (new MapperConfiguration(cfg => {
            cfg.AddProfile<Models.AutoMapperRules.AutoMapperLocation>();
            cfg.AddProfile<Models.AutoMapperRules.AutoMapperAddress>();
            }
        )).CreateMapper();

但是我想将其封装在AutoMapperLocation中,因为没有AutoMapperAddress就没有AutoMapperLocation

0 个答案:

没有答案