When using automapper, we tried to create one mapper class per entity, and it quickly became out of control.
One of the reasons is that we thought Mapper.Reset() is good enough to do the pre-clean-up, but the CreateMap from another Mapper class can also re-define the mapping relationship. Single Mapper works OK in unit-test mode, but when merge together in application, too many mapper classes became too many interferences.
We decide to go with aggregate pattern to solve this mess, mapping should be defined in the “root” mapper class per aggregate. Simple, clean and easy to manage.
A simple rule will be one mapper class per repository class.
Another very useful tip for automapper I learned today is: instead of catching AutoMapperMappingException and look Context, it’s much easier just call this before do any actual map operation
It will give out more accurate error message in your mapping configuration, saved a lot of time. The message in context in exception is too general and useless.