【发布时间】:2012-07-25 21:17:04
【问题描述】:
我在我的应用程序中使用了 Ninject。 Ninject 非常简单易学,但速度很慢,我尝试使用另一个 IoC 来比较它是否比 Ninject 更快。
有很多用于 MVC3 的 IoC 容器,Simple Injector 对我来说看起来非常好,但我在用 Simple Injector 替换 Ninject 时遇到了很多问题。
尤其是AutoMapper。我尝试将此行转换为简单的注入器代码。
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>()
你能帮我吗?我已经阅读了文档并在 Google 上搜索过,但目前还没有解决方案。
【问题讨论】:
-
除非您说明您需要帮助的内容,否则我们无法帮助您。什么失败了?
标签: c# dependency-injection ninject automapper simple-injector