title: Register AutoMapper 5.1.1 with Castle Windsor
body: <p>I'm trying to register AutoMapper 5.1.1 with CastleWindsor, but I don't know, where to properly call Mapper.Initialize().</p>
  
  <p>AutoMapper profile:</p>
  
  <pre><code>namespace AutoMapper_DI.Mappings
  {
      public class WebMappingProfile : Profile
      {        
          public WebMappingProfile()
          {
            CreateMap&lt;Person, PersonDTO&gt;();            
          }
      }
  }
  </code></pre>
  
  <p>Castle Windsor registration:</p>
  
  <pre><code>class MainInstaller : IWindsorInstaller
  {
      public void Install(IWindsorContainer container, IConfigurationStore store)
      {            
          container.AddFacility&lt;TypedFactoryFacility&gt;();
  
          container.Register(Component.For&lt;IMapper&gt;().UsingFactoryMethod(x =&gt;
          {
              return new MapperConfiguration(c =&gt;
              {
                  c.AddProfile&lt;WebMappingProfile&gt;();
              }).CreateMapper();
          }));
  
          container.Register(Component.For&lt;MainClass&gt;());
      }
  }
  </code></pre>
  
  <p>And then when I use _mapper I got  Mapper not initialized exception:</p>
  
  <pre><code>class MainClass
  {
      private readonly IMapper _mapper;
  
      public MainClass(IMapper mapper)
      {
          _mapper = mapper;
      }
  
      public void Start()
      {            
          Person p = new Person
          {
              Name = "Somebody",
              Surname = "Nobody",
              Birth = new DateTime(1984, 06, 18)
          };            
          var personDTO = Mapper.Map&lt;Person, PersonDTO&gt;(p);
  
      }
  
  }
  </code></pre>
  
  <p>Thanks for any advices.</p>