title: How can I inject dependency for Automapper Resolver in .Net Core 2.0 project
body: <p>In my ASPNET Core 2.0 project, when adding a Cache Dependency to my CustomResolver, such dependency is not resolved. I have a complex dependency structure and many mapping profiles which I register as below:</p>
  
  <pre><code>services.AddAutomapper(typeof(Startup))
  </code></pre>
  
  <p>How can I successfully inject that dependency into my custom resolver?</p>
  
  <p>I tried below link for reference:
  <a href="https://lostechies.com/jimmybogard/2016/07/20/integrating-automapper-with-asp-net-core-di/" rel="nofollow noreferrer">https://lostechies.com/jimmybogard/2016/07/20/integrating-automapper-with-asp-net-core-di/</a>
  But I didn't get the ServiceLocator.Resolve(t) part [I'm new to .Net Core and DI stuff]</p>
  
  <p>My resolver CustomResolver has below code:</p>
  
  <pre><code>public class ProductIdResolver : IValueResolver&lt;Request.Product, Entities.Product, int&gt;
  {
  private readonly ICacheService cacheService;
  
      public ProductIdResolver(ICacheService cacheService)
      {
          this.cacheService = cacheService;
      }
  
      public Entities.Product Resolve(Request.Product source, Entities.Product destination, int destMember, ResolutionContext context)
      {
          if (source == null)
              return null;
  
          var product = Mapper.Map&lt;Entities.Product&gt;(source);
  
          product.Id = TranformProductId(source);
  
          return product;
      }
  
      private int TranformProductId(Request.PBI source)
      {
          var frombase = cacheService.GetProducts().FirstOrDefault(p =&gt; p.Sku == source.Sku);
  
          if (frombase == null)
              throw new NullReferenceException("Invalid Product");
  
          return frombase.Id;
      }
  }
  </code></pre>
  
  <p>The resolver reference is inside my SharedProfile, which is called by both Create and Change profile (I broke those profile classes into a third one for code re-using).
  The problem is that my CacheService is not being resolved by DI and I always get an "Error mapping types" exception.
  For reference, my code works if I remove the CacheService object.</p>
  
  <p>How can I successfully inject that dependency into my custom resolver?</p>