Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bootstrap AutoMapper with Unity?

I need to use Unity as my DI container and want to bootstrap AutoMapper.

Using StructureMap I can do it like this;

For<IMappingEngine>().Use(() => Mapper.Engine);

How do I do this in Unity?

I have used the Package Manager to get hold of the currently newest version of AutoMapper 2.2.1-ci9000, but could also use 2.2.0 in case that is simpler. I use version 2.1.505.0 of Microsoft.Practices.Unity.

like image 450
Halvard Avatar asked Dec 12 '12 09:12

Halvard


1 Answers

This should work:

container.RegisterType<IMappingEngine>(new InjectionFactory(_ => Mapper.Engine));
like image 200
Sebastian Weber Avatar answered Oct 02 '22 03:10

Sebastian Weber