从Simple Injector转换为Unity

时间:2016-04-18 17:25:59

标签: c# unity-container simple-injector automapper-4

这个Simple Injector代码如何转换为统一。这是参考this

public static Container RegisterAutoMapper(this Container container)
{
    var profiles = typeof(AutoMapperRegistry).Assembly.GetTypes()
        .Where(t => typeof(Profile).IsAssignableFrom(t))
        .Select(t => (Profile)Activator.CreateInstance(t));

    var config = new MapperConfiguration(cfg =>
    {
        foreach (var profile in profiles)
        {
            cfg.AddProfile(profile);
        }
    });

    container.Register<MapperConfiguration>(() => config);
    container.Register<IMapper>(() => container.GetInstance<MapperConfiguration>()
        .CreateMapper());

    return container;
}

我相信我们正在扫描配置文件和循环的第一部分是非常简单的,我可能是错的。接近

的东西
public static Container RegisterAutoMapper(this Container container)
{
    var profiles = AppDomain.CurrentDomain
                            .GetAssemblies()
                            .SelectMany(a => a.GetTypes());

    var config = new MapperConfiguration(cfg =>
    {
        foreach (var item in profiles)
        {
            if (item.FullName != "AutoMapper.SelfProfiler`2")
                cfg.AddProfile(Activator.CreateInstance(item) as Profile);
        }
    });


    //container.Resolve...;
    //container.Resolve...;

    return container;
}

我们如何使用统一来解决这个问题。

0 个答案:

没有答案