手始めに、私はこのモジュールを使用しています:
public class AutoMapperModule : NinjectModule
{
public override void Load()
{
Bind<ITypeMapFactory>().To<TypeMapFactory>();
foreach (var mapper in MapperRegistry.AllMappers())
{
Bind<IObjectMapper>().ToConstant(mapper);
}
Bind<AutoMapper.ConfigurationStore>().ToSelf().InSingletonScope().WithConstructorArgument("mappers", ctx => ctx.Kernel.GetAll<IObjectMapper>());
Bind<IConfiguration>().ToMethod(ctx => ctx.Kernel.Get<AutoMapper.ConfigurationStore>());
Bind<IConfigurationProvider>().ToMethod(ctx => ctx.Kernel.Get<AutoMapper.ConfigurationStore>());
Bind<IMappingEngine>().To<MappingEngine>();
}
}
すべてのマップにブートストラッパークラスがあります
public static void Configure(IKernel kernel)
{
Mapper.Initialize(map => map.ConstructServicesUsing(t => kernel.Get(t)));
}
データベースにアクセスするリゾルバーがあり、リポジトリーを挿入する必要があります。そのまま動作していますが、単体テストとIMappingEngineで動作させる方法がわかりません。
public HomeController(IMappingEngine mappingEngine)
{
_mappingEngine = mappingEngine;
}
マップが存在しないため、_mappingEngine.Mapは例外をスローします。Mapper.Mapは機能します。
私は何が欠けていますか?ブートストラッパーを単体テストで動作させて、リゾルバーのリポジトリーが偽の/模擬リポジトリーを使用できるようにするにはどうすればよいですか?