用Simple Injector替换Ninject

5
我已经在我的应用程序中使用了Ninject。Ninject非常简单易学,但它的速度相当慢,因此我尝试使用另一个IoC来比较它是否更快。
有很多MVC3的IoC容器,Simple Injector对我来说看起来非常不错,但是我在尝试用Simple Injector替换Ninject时遇到了很多问题。
特别是在使用AutoMapper时。我尝试将这些代码转换为Simple Injector代码。
Bind<ITypeMapFactory>().To<TypeMapFactory>();

foreach (var mapper in MapperRegistry.AllMappers())
{
    Bind<IObjectMapper>().ToConstant(mapper);
}

Bind<ConfigurationStore>().ToSelf().InSingletonScope()
    .WithConstructorArgument("mappers",
        ctx => ctx.Kernel.GetAll<IObjectMapper>());

Bind<IConfiguration>()
    .ToMethod(ctx => ctx.Kernel.Get<ConfigurationStore>());

Bind<IConfigurationProvider>().ToMethod(ctx =>
    ctx.Kernel.Get<ConfigurationStore>());

Bind<IMappingEngine>().To<MappingEngine>()

你能帮我吗?我已经阅读了文档并进行了谷歌搜索,但迄今为止没有解决方案。


1
除非您说明需要帮助的内容,否则我们无法为您提供帮助。哪里出了问题? - Gaute Løken
1个回答

11

这个 Ninject 注册大致相当于以下 Simple Injector 注册:

container.Register<ITypeMapFactory, TypeMapFactory>();
container.RegisterCollection<IObjectMapper>(MapperRegistry.AllMappers());
container.RegisterSingleton<IConfiguration, ConfigurationStore>();
container.RegisterSingleton<IConfigurationProvider, ConfigurationStore>();
container.Register<IMappingEngine, MappingEngine>();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接