我以前使用过 Autofac,但现在我想试试 SimpleInjector。我的问题是,在我的方法中调用 mappingEngine 时出现以下错误:
缺少类型映射配置或不支持的映射。
映射类型:Something -> SomethingDto 目标路径:IEnumerable`1[0]
源值:
_mappingEngine.Map<IEnumerable<SomethingDto>>(IEnumerableOfSomething);
^-- doesn't work
Mapper.Map<IEnumerable<SomethingDto>>(IEnumerableOfSomething);
^-- works (That's not what I want)
Mapper.Map 不是我想要的。我在这里基于此注册 Automapper:
container.Register<ITypeMapFactory, TypeMapFactory>();
container.RegisterAll<IObjectMapper>(
MapperRegistry.AllMappers());
container.RegisterSingle<ConfigurationStore>();
container.Register<IConfiguration>(() =>
container.GetInstance<ConfigurationStore>());
container.Register<IConfigurationProvider>(() =>
container.GetInstance<ConfigurationStore>());
container.Register<IMappingEngine, MappingEngine>();
Mapper.Initialize(x =>
{
var profiles = container.GetAllInstances<Profile>();
foreach (var profile in profiles)
{
x.AddProfile(profile);
}
});
Mapper.AssertConfigurationIsValid();
我的问题是,如何在 SimpleInjector 中注册 IMappingEngine 并正确添加我的配置文件?
提前致谢!
迎接 mtrax