On some of our projects we have been experimenting with smaller AutoMapper profiles. The idea is that it is easier to digest a smaller profile. We have gone so far as creating a profile for each Domain object and handle all of the mappings to and from the domain object. We are also trying out a Profile per scenario. While these smaller profiles are easier to dig in and understand, the registration of them are a little painful. So I put together a quick way to auto register all the profiles for automapper. Below is the code to discover all the profiles in an assembly than register them with AutoMapper. There is nothing fancy here and I could certainly spend more time making it better performing, but realistically this is startup code that runs once at application start up. That being said I would rather focus performance optimization efforts on places that actually make a difference to the End User Experience.
Here is the sample.
It is important to know that we have full code coverage over our application including integration tests, so that if something were to break as a result of loading this in a non deterministic order, we would know before we commit our changes to source control.
Here is the code for the ForEach extension method, since I breezed over it.
This is a smaller post than I normally put together.. is this small of a post useful?