Ninject を使用して AutoMapper を ASP.NET MVC 2 アプリケーションに挿入するのに問題があります。AutoMapper および StructureMap タイプの構成に関する Jimmy Bogard の投稿をガイドとして使用しました。
public class AutoMapperModule : NinjectModule
{
public override void Load()
{
Bind<ITypeMapFactory>().To<TypeMapFactory>();
Bind<Configuration>().ToSelf().InSingletonScope().WithConstructorArgument("mapper", MapperRegistry.AllMappers);
Bind<IConfiguration>().To<Configuration>();
Bind<IConfigurationProvider>().To<Configuration>();
Bind<IMappingEngine>().To<MappingEngine>();
}
}
Ninject は、解決時に例外をスローしますConfiguration
。
IObjectMapper のアクティブ化でエラーが発生しました 一致するバインディングが利用できず、型が自己バインド可能ではありません。アクティベーション パス:
3) Configuration 型のコンストラクターのパラメーター マッパーへの依存関係 IObjectMapper の注入
アップデート
これは現在、次のバインディングを使用して機能しています。
Bind<ITypeMapFactory>().To<TypeMapFactory>();
Bind<Configuration>().ToConstant(new Configuration(Kernel.Get<ITypeMapFactory>(), MapperRegistry.AllMappers())).InSingletonScope();
Bind<IConfiguration>().ToMethod(c => c.Kernel.Get<Configuration>());
Bind<IConfigurationProvider>().ToMethod(c => c.Kernel.Get<Configuration>());
Bind<IMappingEngine>().To<MappingEngine>();
モジュールを GitHub に公開しました。AutoMapper.Ninject . 私のブログの詳細: http://binaryspeakeasy.com/2010/09/automapper-ninject/