AutoMapper How To Map Object A To Object B Differently Depending On Context

后端 未结 3 1004
面向向阳花
面向向阳花 2020-12-24 09:16

Calling all AutoMapper gurus!

I\'d like to be able to map object A to object B differently depending on context at runtime. In particular, I\'d like to ignore certai

3条回答
  •  不知归路
    2020-12-24 09:45

    The Mapper class is merely a thin wrapper on top of a Configuration and MappingEngine objects. You can create separate instances of Configuration/MappingEngine objects (still using singletons), and use your IoC container of choice to load the correct one as necessary.

    The best option still is to use different destination types. The really tough part about truly supporting this feature is the inherent hierarchical nature of type maps. The top-level object might have a mapping profile, while lower level ones do not. Some in between might have it or not, etc.

提交回复
热议问题