AutoMapper获取所有配置文件非静态API版本

时间:2016-02-07 18:41:11

标签: c# asp.net automapper

我想将此转换为新版本。 我读: https://github.com/AutoMapper/AutoMapper/wiki/Migrating-from-static-API https://lostechies.com/jimmybogard/2016/01/21/removing-the-static-api-from-automapper/

public static class AutoMapperConfiguration
{
    public static void Configure()
    {
        Mapper.Initialize(x => GetConfiguration(Mapper.Configuration));
    }

    private static void GetConfiguration(IConfiguration configuration)
    {
        var assemblies = AppDomain.CurrentDomain.GetAssemblies();
        foreach (var assembly in assemblies)
        {
            var profiles = assembly.GetTypes().Where(x => x != typeof(Profile) && typeof(Profile).IsAssignableFrom(x));
            foreach (var profile in profiles)
            {
                configuration.AddProfile((Profile)Activator.CreateInstance(profile));
            }
        }
    }
}

我在/ Plugins / plugin-name / Entities / Config文件夹中的配置文件,其中包含我的EntityConfiguration的名称 我的视图数据在/ Plugins / plugin-name / ViewModels / EntityEditViewModel

谢谢!

0 个答案:

没有答案