【问题标题】:Automapper with Unity - where to put CreateMap stuff?带有 Unity 的 Automapper - 在哪里放置 CreateMap 的东西?
【发布时间】:2010-11-29 16:03:56
【问题描述】:

我正在使用以下统一注册自动映射器:

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 注册的其他对象?

【问题讨论】:

    标签: c# unity-container automapper


    【解决方案1】:

    在 IoC 中注册完所有内容后,从容器中拉取 IConfiguration 实例以注册自定义解析器并创建映射。

    【讨论】:

    • 你有这方面的例子吗?
    • @retslig 不确定我明白你在问什么,但我认为它应该看起来像... IConfiguration configuration = // pull from IoC configuration.CreateMap..... configuratoin.CreateMap..... // whatever else you need configuration.AssertConfigurationIsValid(); 抱歉格式,但我不知道如何在评论中获取代码块
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    • 2014-12-20
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多