3
对于我使用这个模块首发:AutoMapper与Ninject混乱
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可以工作。
我错过了什么?我如何让自举程序使用单元测试,以便我的解析程序中的存储库使用假/模拟存储库?