Skip to content

The Unity Automapper API

isaacabraham edited this page Dec 21, 2012 · 19 revisions

The main API consists of a single static class Lydian.Unity.Automapper.Mapper. It contains two extension methods, each with two overrides: -

###AutomapAssemblies() Takes in a set of assembly names, searches out all types in those assemblies, and wires them up.

        container.AutomapAssemblies("MyFirstAssembly", "MySecondAssembly", "MyThirdAssembly");

In the example above, MyFirstAssembly main contain many interfaces whose implementations live inside MySecondAssembly and MyThirdAssembly. Unity Autmapper makes no distinction between the source of those types - it unions them all together and treats them as an single set.

###AutomapTypes() Takes in a set of types and wires them up.

      using System.Reflection;

      container.AutomapAssemblies(typeof(IMyService), typeof(MyService); // explicit
      container.AutomapAssemblies(Assembly.GetExecutingAssembly().GetTypes()) // all types in this assembly.
Clone this wiki locally