小编Jam*_*mes的帖子

如何使用Simple Injector注册AutoMapper 4.2.0

已更新至AutoMapper 4.2.0,并按照此处提供的迁移指南进行操作:https://github.com/AutoMapper/AutoMapper/wiki/Migrating-from-static-API/f4784dac61b91a0df130e252c91a0efd76ff51de#preserving-static-feel.尝试将StructureMap的页面上的代码转换为Simple Injector.有人能告诉我这个代码在Simple Injector中的样子吗?

StructureMap

public class AutoMapperRegistry : Registry
{
    public AutoMapperRegistry()
    {
        var profiles =
            from t in typeof (AutoMapperRegistry).Assembly.GetTypes()
            where typeof (Profile).IsAssignableFrom(t)
            select (Profile)Activator.CreateInstance(t);

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

        For<MapperConfiguration>().Use(config);
        For<IMapper>().Use(ctx => ctx.GetInstance<MapperConfiguration>().CreateMapper(ctx.GetInstance));
    }
}
Run Code Online (Sandbox Code Playgroud)

简单的注射器

?
Run Code Online (Sandbox Code Playgroud)

c# automapper simple-injector

9
推荐指数
2
解决办法
3952
查看次数

标签 统计

automapper ×1

c# ×1

simple-injector ×1