title: How to add global configuration options to Automapper v8 using instance api with .net core 2.2
body: <p>I'm using:</p>
  
  <ul>
  <li>.net core v2.2.0</li>
  <li>Microsoft.EntityFrameworkCore v2.2.4</li>
  <li>automapper v8.1.1</li>
  <li>AutoMapper.Extensions.Microsoft.DependencyInjection v6.1.1</li>
  <li>VS2017 Community Edition v15.9.12</li>
  </ul>
  
  <p>In my solution i have:</p>
  
  <ul>
  <li>TVC_DATA: handles all data access and contains the mapping profile classes</li>
  <li>TVC_PORTAL: react web app</li>
  </ul>
  
  <p>I have setup automapper using dependency injection following the guide as described <a href="https://stackoverflow.com/questions/40275195/how-to-setup-automapper-in-asp-net-core">here</a></p>
  
  <p>So: in startup.cs of TVC_PORTAL in ConfigureServices method i have: </p>
  
  <pre><code>services.AddAutoMapper(typeof(AutomapProfileGen));
  </code></pre>
  
  <p>where i use AutoMapProfileGen is one of the marker types for AddAutoMapper to locate the TVC_DATA assembly where the other profiles are located as well.</p>
  
  <p>In my ObjectController i inject IMapper:</p>
  
  <pre><code>public ObjectController(IHostingEnvironment environment, IMapper mapper)
  {
          _hostingEnvironment = environment;            
          _mapper = mapper;
  }
  </code></pre>
  
  <p>And i use the mapper later on:</p>
  
  <pre><code>IEnumerable&lt;ObjectViewType&gt; vList = _mapper.Map&lt;IEnumerable&lt;ObjectType&gt;, IEnumerable&lt;ObjectViewType&gt;&gt;(mList);
  </code></pre>
  
  <p>My profiles are pretty straightforward, for example:</p>
  
  <pre><code>public class AutomapProfileSrc : Profile
  {
      public AutomapProfileSrc()
      {
          //source data
          CreateMap&lt;AirlineView, Airline&gt;().ReverseMap();
          CreateMap&lt;AirlineListView, Airline&gt;().ReverseMap();
          CreateMap&lt;AirportView, Airport&gt;().ReverseMap();
          CreateMap&lt;AirportListView, Airport&gt;().ReverseMap();
          CreateMap&lt;CountryView, Country&gt;().ReverseMap();
          CreateMap&lt;CountryListView, Country&gt;().ReverseMap();
      }
  }
  </code></pre>
  
  <p>My question: i want to set some global config options for automapper and cannot figure out where/how to set them. For example: i want to set ValidateInlineMaps to false (because that was mentioned as a solution when AssertConfigurationIsValid throws 'member not mapped' exceptions). Also i want to set MaxDepth to 1 for all maps to avoid circular references. What i tried:</p>
  
  <p>1) Set ValidateInlineMaps to false in all profile constructors: doesn't work.</p>
  
  <pre><code>public class AutomapProfileCfg : Profile
  {
      public AutomapProfileCfg()
      {
          ValidateInlineMaps = false;
  ...
  </code></pre>
  
  <p>2) Create a MapperConfiguration object in ConfigureServices like:</p>
  
  <pre><code>'var config = new MapperConfiguration(cfg =&gt;
      {
          cfg.ForAllMaps((typeMap, mappingExpression) =&gt; {  mappingExpression.MaxDepth(1); });
          cfg.AllowNullCollections = true;
          cfg.ValidateInlineMaps = false;
          //cfg.Advanced.MaxExecutionPlanDepth = 1;
      });'
  </code></pre>
  
  <p>But i do not know how to link it to the mapper instance: just creating is not changing the mapper's behaviour.</p>
  
  <p>Have been going through documentation and searching this site for almost a day now: is getting frustrating because this looks like it must be simple....but somehow i can't get it to work. Any help would be much appreciated</p>