1

I know about the feature of defining a Before/AfterMap callback on the map level for a given type pair. However, I'm searching for a solution to define a global Before/AfterMap function somehow, which would apply to every defined type map.

In most of my DTOs I have a mechanism which prevents changed notifications temporarly with the BeginUpdate/EndUpdate pattern. I would like AutoMapper to wrap the mapping between these calls whenever the target type supports it.

I've looked through questions here and the AutoMapper docs but haven't found a native solution.

Zoltán Tamási
  • 12,249
  • 8
  • 65
  • 93

1 Answers1

1

I think I've found a porposed solution, but haven't tested it completely yet.

After all of my maps are registered, I would do something like this:

var typeMaps = Mapper.GetAllTypeMaps();
foreach (var typeMap in typeMaps)
{
    typeMap.AddBeforeMapAction(...);
    typeMap.AddAfterMapAction(...);
}
Zoltán Tamási
  • 12,249
  • 8
  • 65
  • 93
  • did you ever get anywhere with this? Do you have an example of the final result. – Chase Florell Nov 25 '19 at 18:33
  • I am facing same issue. I am registering an expression which is calling a method in .AddAfterMapAction. But it is not calling the method while mapping. https://stackoverflow.com/questions/60373957/automapper-addaftermapaction-not-calling-method – Fahad Mahmood Feb 24 '20 at 13:39