Automapper общая часть карты - PullRequest
       19

Automapper общая часть карты

0 голосов
/ 27 августа 2018

т.е. У меня есть следующий класс карты:

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:

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

но я хочу инкапсулировать его внутри AutoMapperLocation, потому что нет смысла иметь AutoMapperLocation без AutoMapperAddress

...