title: Autofac with WebApi & Business Layer
body: <p>I am very new to AutoFac and am trying to use it for my new project with WebApi and Business Layer with contracts and their respective implementations. </p>
  
  <p>I have written the IocConfiguration for webapi and invoke from global.asax. </p>
  
  <p>However, for my Business Logic how do I setup all my contracts and implementations with autofac?</p>
  
  <p>I did go through some tutorials online but however I could not find anything helpful, If someone has a sample app, links that really helps.</p>
  
  <p><strong><em>Edit:</em></strong></p>
  
  <p>AutoMapper profile.</p>
  
  <pre><code>public class CustomProfile : Profile
  {
      protected override void Configure()
      {
          CreateMap&lt;MyViewModel, MyModel&gt;()
              .ForMember(d =&gt; d.Id, s =&gt; s.MapFrom(src =&gt; src.Id));
      }
  }
  </code></pre>
  
  <p><strong><em>Edit:</em></strong></p>
  
  <p>After few long hours spent on this I figured out how to setup AutoMapper 4.2.1 with AutoFac. Apparently I was using ConfigurationStore in AutoMapper 3.3.0 but I upgraded to 4.2.1 the profile registration changed a little bit. Below is what worked for me. </p>
  
  <pre><code>public class AutoMapperModule : Module
  {
      protected override void Load(ContainerBuilder builder)
      {
          Mapper.Initialize(cfg =&gt;
          {
              cfg.AddProfile&lt;MyProfile1&gt;();
              cfg.AddProfile&lt;MyProfile2&gt;();
          });
  
          base.Load(builder);
      }
  }
  </code></pre>