質問

私は私のアプリケーションのために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>();
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top