2017-01-10 6 views
0

Перед сканированием сборки (около 4.x), мы сделали что-то вроде следующего, чтобы обеспечить централизованный подход к добавлению профилей:Automapper несколько источников для профилей

/// <summary> 
///  Class that allows all the AutoMapper profiles to be initiated for all assemblies within the platform. 
/// </summary> 
public class OzCpAutoMapperConfig 
{ 
    private Type[] _ExternalProfiles; 

    /// <summary> 
    ///  For the 201610.02 release we are not using assembly scanning so we get the caller to pass 
    ///  in the profiles they want us to register. 
    /// </summary> 
    /// <param name="aExternalProfiles">List of automapper profile classes that we also need to register</param> 
    public void ConfigurationApproachFor201610_02(Type[] aExternalProfiles) 
    { 
     _ExternalProfiles = aExternalProfiles; 
     Mapper.Initialize(DoMapperConfigFor201610_02); 
    } 

    /// <summary> 
    ///  Internal helper method that populates the AutoMapper configuration object. 
    /// </summary> 
    /// <param name="aMapperConfiguration">Instance of AutoMapper configuration object that we need to use.</param> 
    private void DoMapperConfigFor201610_02(IMapperConfiguration aMapperConfiguration) 
    { 
     //Add all the external mapper configurations passed in by the original caller 
     foreach (Type externalProfile in _ExternalProfiles) 
     { 
      aMapperConfiguration.AddProfile(Activator.CreateInstance(externalProfile) as Profile); 
     } 

     //Now add all the platform profiles 
     aMapperConfiguration.AddProfile<CarnivalApiServiceAutoMapperProfile>(); 
     aMapperConfiguration.AddProfile<CarnivalOpenseasApiServiceAutoMapperProfile>(); 
     ... 
    } 
} 

Так что теперь с 5.2 мы хотим использовать сборку сканирование и иметь возможность передавать некоторые дополнительные профили для регистрации. Однако IMapperConfiguration больше недоступен. Таким образом, хотя я мог бы сделать:

Mapper.Initialize(cfg => { cfg.AddProfiles("MyNameSpace.Application", "MyNameSpace.Core", ....); 

, как добавить дополнительные профили Я хочу включены как часть Mapper.Initialize() вызов? (Они не находятся в сборках, которые нужно отсканировать).

ответ

0

IMapperConfiguration был переименован в IMapperConfigurationExpression в 5.2. Таким образом, описанный выше подход может быть использован после использования переименованного интерфейса.