Automapper with Unity - 在哪里放置 CreateMap 的东西?
我正在使用 unity 注册自动映射器,如下所示:
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 注册的其他对象?
I am registering automapper using unity with the following:
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>();
This works fine but where do I put the equivalent of my Mapper.CreateMap's?
Also, if I have some custom resolvers, how and where do I register these where they have dependencies on other objects I have registered through Unity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 IoC 中注册完所有内容后,从容器中提取 IConfiguration 实例以注册自定义解析器和创建映射。
once you've registered everything in IoC, pull the IConfiguration instance from the container to register custom resolvers & create mappings.