简体   繁体   English

用简单的注射器替换Ninject

[英]Replace Ninject with Simple Injector

I've used Ninject for my application. 我已经将Ninject用于我的应用程序。 Ninject is really simple and easy to learn, but its quite slow and I try to use another IoC to compare if its faster as with Ninject. Ninject非常简单易学,但速度很慢,我尝试使用另一个IoC进行比较,如果它比Ninject更快。

There are a lot of IoC containers for MVC3 and Simple Injector looks really good to me, but I've a lot of problems with replacting Ninject with Simple Injector . MVC3和Simple Injector有很多IoC容器看起来对我很好,但是我用Simple Injector替换Ninject有很多问题。

Especially with the AutoMapper . 特别是使用AutoMapper I try to convert this lines into Simple Injector code. 我尝试将这些行转换为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>()

Do you can help me? 你能帮帮我吗? I've read the documentation and googled, but no solution so far. 我已经阅读了文档和googled,但到目前为止还没有解决方案。

This Ninject registration roughly translates to the following Simple Injector registration: 此Ninject注册大致转换为以下Simple Injector注册:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM