Monday, March 26, 2012

AutoMapper Revisited

A few months back I posted about AutoMapper, a tool for which I had use in a project. One of the characteristics of AutoMapper is that, when it can’t map a given attribute, if fails silently. For example, if attribute A in the source object is renamed to B and there is no B in the target object, we don’t get any exception or error back. This is the normal behavior, ignore what it can’t map.

The side effect of this is that when you change the source or destination classes, unless you have unit tests, you can get had to find errors. For this reason (and we do have unit tests), I opted for the progressive removal of AutoMapper in the project. Now the mappers simply break compilation when the classes change, and the fixes are simple to make. The convenience wasn’t worth it.