Don*_*ino 5 c# dependency-injection ninject automapper simple-injector
我已经将Ninject用于我的应用程序.Ninject非常简单易学,但速度很慢,我尝试使用另一个IoC进行比较,如果它比Ninject更快.
MVC3和Simple Injector有很多IoC容器看起来对我很好,但是我用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>()
Run Code Online (Sandbox Code Playgroud)
你能帮帮我吗?我已经阅读了文档和googled,但到目前为止还没有解决方案.
Ste*_*ven 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>();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2940 次 |
最近记录: |