title: Multiple AutoMapper.Configure() in Global.asax
body: <p>I am using AutoMapper to map between DTO objects and my business objects. I've two AutoMapperConfiguration.cs files - one in my service layer and another one in my web api layer.</p>
  
  <p>As shown in the answer at the following link 
  <a href="https://stackoverflow.com/questions/6825244/where-to-place-automapper-createmaps">Where to place AutoMapper.CreateMaps?</a></p>
  
  <p>I am calling the Configure() of both these files in my Global.asax class </p>
  
  <pre><code>AutoMapperWebConfiguration.Configure();
  AutoMapperServiceConfiguration.Configure();
  </code></pre>
  
  <p>but it seems like the my Service Configure call (the second call) is overwriting the mappings of the web api layer (the first call) and I get an exception saying the Mapping is missing.</p>
  
  <p>If I reverse the Configure calls to look like this </p>
  
  <pre><code>AutoMapperServiceConfiguration.Configure();
  AutoMapperWebConfiguration.Configure();
  </code></pre>
  
  <p>I don't get the exception for web api mapping but I get the same mapping exception for the Service layer.</p>
  
  <p>Am I doing something wrong because this is clearly marked as an answer in the above stack overflow link?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>public static class AutoMapperServiceConfiguration
  {
      public static void Configure()
      {
          Mapper.Initialize(x =&gt;
          {
              x.AddProfile&lt;CmciFlowTestToGenericFlowTestSimpleMappingProfile&gt;();
              x.AddProfile&lt;FsrsFlowTestToGenericFlowTestSimpleMappingProfile&gt;();
          });
      }
  }
  
  public class FsrsFlowTestToGenericFlowTestSimpleMappingProfile : Profile
  {
      protected override void Configure()
      {
          Mapper.CreateMap&lt;FsrsFlowTest, GenericFlowTest&gt;()
              .ConvertUsing&lt;FsrsFlowTestToGenericFlowTestSimpleConverter&gt;();
      }
  }
  
  public class FsrsFlowTestToGenericFlowTestSimpleConverter : TypeConverter&lt;FsrsFlowTest, GenericFlowTest&gt;
  {
      protected override GenericFlowTest ConvertCore(FsrsFlowTest source)
      {
          if (source == null)
          {
              return null;
          }
  
          return new GenericFlowTest
              {
                  FlowTestDate = source.FlowTestDates,
                  StaticPsi = source.HydrantStaticPsi.ToString(),
                  ResidualPsi = source.HydrantResidualPsi.ToString(),
                  TotalFlow = source.NffGallonsPerMinute.ToString(),
                  FlowTestLocation = source.FsrsFlowTestLocations.Any()
                            ? source.FsrsFlowTestLocations.First().LocationDescription
                            : null
              };
      }
  
  public class CmciFlowTestToGenericFlowTestSimpleMappingProfile : Profile
  {
      protected override void Configure()
      {
          Mapper.CreateMap&lt;CmciFlowTest, GenericFlowTest&gt;()
              .ConvertUsing&lt;CmciFlowTestToGenericFlowTestSimpleConverter&gt;();
      }
  }
  
  public class CmciFlowTestToGenericFlowTestSimpleConverter : TypeConverter&lt;CmciFlowTest, GenericFlowTest&gt;
  {
      protected override GenericFlowTest ConvertCore(CmciFlowTest source)
      {
          if (source == null)
          {
              return null;
          }
  
          return new GenericFlowTest
              {
                  FlowTestDate = source.FlowTestDates,
                  StaticPsi = source.HydrantStaticPsi.ToString(),
                  ResidualPsi = source.HydrantResidualPsi.ToString(),
                  TotalFlow = source.CalculatedHydrantGallonsPerMinute.ToString(),
                  FlowTestLocation = source.StaticLocationHydrantFlowPSI
              };
      }
  }    
  
  public static class AutoMapperWebConfiguration
  {
      public static void Configure()
      {
          Mapper.Initialize(x =&gt;
              {
                  x.AddProfile&lt;ServiceToWebApiMappingProfile&gt;();
                  x.AddProfile&lt;WebApiToServiceMappingProfile&gt;();
              });
      }
  }
  
  public class ServiceToWebApiMappingProfile : Profile
  {
      protected override void Configure()
      {
          Mapper.CreateMap&lt;ServiceFlowTest, FlowTest&gt;();
      }
  }
  
  public class WebApiToServiceMappingProfile : Profile
  {
      protected override void Configure()
      {
          Mapper.CreateMap&lt;PropertyAddress, ServicePropertyAddress&gt;();
      }
  }
  </code></pre>
  
  <p>To get around this issue, I am adding the service profiles in the AutoMapperWebConfiguration class and only calling AutoMapperWebConfiguration.Configure() in global.asax.</p>