Initializing Automapper

I struggled for while with getting Automapper to register the Profiles of my sub layers (Service layer for instance), when it is setup in the App start process. I found this on StackOverflow and it was the correct answer. Saving here so I can find easily next time.

Additionally. It was not necessary to override the ProfileNames. All profiles in all layers can have the same class name as far as I can tell. No issues in my case.

Original ref:


 var assembliesToScan = AppDomain.CurrentDomain.GetAssemblies();
        var allTypes = assembliesToScan.SelectMany(a => a.ExportedTypes).ToArray();

        var profiles =
                .Where(t => typeof(Profile).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo()))
                .Where(t => !t.GetTypeInfo().IsAbstract);

        Mapper.Initialize(cfg =>
            foreach (var profile in profiles)