Castle Windsor Dependency Injection for AutoMapper 4.2.0

361 views
Skip to first unread message

jesse....@gmail.com

unread,
Feb 1, 2016, 1:45:38 PM2/1/16
to AutoMapper-users
I'm updating a project to AutoMapper 4.2.0 and am running into some issues while moving away from the static Mapper class. So far, I have everything building properly. I'm a Castle Windsor and Dependency Injection rookie, however, and I can't get the AutoMapper installer working properly. Here's what I've got now:

public class AutoMapperInstaller : IWindsorInstaller
  {
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
      container.Register(
        Component
          .For<IMappingEngine>()
          .UsingFactoryMethod(cc => Mapper.Engine)
          .LifestyleSingleton());
    }
  }
}

This, of course, gives me the warning that AutoMapper.Mapper.Engine is obsolete. The end result is that several of my unit tests fail, and AutoMapper is not properly installed for dependency injection to work.

What's the proper way to register AutoMapper after the move to 4.2.0?

Jimmy Bogard

unread,
Feb 1, 2016, 2:14:47 PM2/1/16
to automapper-users
I'm not a Windsor person, but you can check out the wiki on migrations for StructureMap:


--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jesse Temple

unread,
Feb 1, 2016, 4:33:33 PM2/1/16
to AutoMapper-users
That helped a little, and I fixed a few things. I still can't get the controller tests running anywhere there's an automapper dependency. When I try to map something in the controller, automapper is returning null, like the dependency injection isn't set up correctly. I'll keep trying.
Reply all
Reply to author
Forward
0 new messages