Replace Ninject with Simple Injector

假装没事ソ 提交于 2020-01-10 11:33:47

问题


I've used Ninject for my application. 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.

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.

Especially with the AutoMapper. I try to convert this lines into Simple Injector code.

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.


回答1:


This Ninject registration roughly translates to the following Simple Injector registration:

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


来源:https://stackoverflow.com/questions/11658786/replace-ninject-with-simple-injector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!