我正在使用以下统一注册自动映射器:
container
.RegisterType<AutoMapper.Configuration, AutoMapper.Configuration>(new PerThreadLifetimeManager(),
new InjectionConstructor(typeof (ITypeMapFactory), AutoMapper.Mappers.MapperRegistry.AllMappers()))
.RegisterType<ITypeMapFactory, TypeMapFactory>()
.RegisterType<IConfiguration, AutoMapper.Configuration>()
.RegisterType<IConfigurationProvider, AutoMapper.Configuration>()
.RegisterType<IMappingEngine, MappingEngine>();
这工作正常,但我应该把我的 Mapper.CreateMap 的等价物放在哪里?
此外,如果我有一些自定义解析器,我应该如何以及在何处注册这些解析器,因为它们依赖于我通过 Unity 注册的其他对象?
最佳答案
在 IoC 中注册所有内容后,从容器中提取 IConfiguration 实例以注册自定义解析器并创建映射。
关于c# - 带有 Unity 的 Automapper - 在哪里放置 CreateMap 的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4305550/