Skip to content

The Unity Automapper API

Isaac Abraham edited this page Apr 25, 2014 · 19 revisions

The main API consists of a single static class: Lydian.Unity.Automapper.Mapper. It contains two public extension methods on the IUnityContainer: -

###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 may contain many interfaces whose implementations live inside MySecondAssembly and MyThirdAssembly. Unity Automapper makes no distinction between the source of those types - it concatenates them all together and treats them as a single set.

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

using System.Reflection;

container.AutomapTypes(typeof(IMyService), typeof(MyService)); // explicit
container.AutomapTypes(Assembly.GetExecutingAssembly().GetTypes()) // all types in this assembly.

###Overrides Both methods also offer an override that takes in an instance of a MappingOptions object. This object contains further guidance on how the Automapper behaves in certain circumstances; see [here](Default Behaviours) for details on it.