ninjectを単純なインジェクタに置き換えます
-
11-12-2019 - |
質問
私は私のアプリケーションのためにninjectを使いました。Ninjectは本当にシンプルで学ぶのが簡単ですが、それはかなり遅く、私はninjectと同じくらい速くするかどうかを比較するために別のIOCを使用しようとします。
MVC3用のIOCコンテナがたくさんあり、シンプルな注入器は私にとって本当によく見えますが、シンプルなインジェクタ。
特に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>()
.
あなたは私を助けることができますか?私はドキュメントを読み、グーグルされましたが、これまでの解決策はありません。
解決
このn個の登録は、次の単純なインジェクタ登録に大きく変換されます。
container.Register<ITypeMapFactory, TypeMapFactory>();
container.RegisterCollection<IObjectMapper>(MapperRegistry.AllMappers());
container.RegisterSingleton<IConfiguration, ConfigurationStore>();
container.RegisterSingleton<IConfigurationProvider, ConfigurationStore>();
container.Register<IMappingEngine, MappingEngine>();
. 所属していません StackOverflow