title: Resolver lifetime when mapping with a custom value resolver
body: <p>I am using <code>AutoMapper</code> v9.0.0, I have source and destination objects which both contain a one to many parent/child relationship.</p>
  
  <p>When the map is invoked, a sequence of ~100k <code>SrcParent</code> objects with &lt; 100 <code>SrcChild</code> objects are processed. Each parent map is invoked individually so an existing instance of a <code>DstParent</code> object can be seeded with a <code>DstParent.ConfigurationId</code> value, the <code>MyValueResolver</code> value resolver can only perform the <code>SrcChild</code> to <code>DstChild</code> conversion with this data.</p>
  
  <p>The mapper is added to the asp.net core di container with the lifetime overridden using <code>services.AddAutoMapper(assemblies, ServiceLifetime.Singleton);</code>.</p>
  
  <p>However, the mapping configuration instantiates a new resolver for each child regardless of the specified lifetime. What other options exist to efficiently convert a collection of parents where each child instance in the children sequence needs a hint that is only available at runtime on the destination parent?</p>
  
  <pre><code>public class SrcParent
  {
      public int Id { get; set; }
      public List&lt;SrcChild&gt; SrcChildren { get; set; }
  }
  
  public class SrcChild
  {
      public int Id { get; set; }
      public int SrcParentId { get; set; }
      public string Name { get; set; }
      public string Value { get; set; }
  }
  
  public class DstParent
  {
      public int Id { get; set; }
      public int ConfigurationId { get; set; }
      public List&lt;DstChild&gt; DstChildren { get; set; }
  }
  
  public class DstChild
  {
      public int Id { get; set; }
      public int DstParentId { get; set; }
      public string Name { get; set; }
      public string Value { get; set; }
  }
  
  this.CreateMap&lt;SrcParent, DstParent&gt;()
      .ForMember(dst =&gt; dst.Id, opt =&gt; opt.Ignore())
      .ForMember(dst =&gt; dst.ConfigurationId, opt =&gt; opt.Ignore())
      .ForMember(dst =&gt; dst.DstChildren, opt =&gt; opt.MapFrom&lt;MyValueResolver&gt;());
  
  public class MyValueResolver : IValueResolver&lt;SrcParent, DstParent, List&lt;DstChild&gt;&gt;
  {
      public List&lt;DstChild&gt; Resolve(SrcParent source, DstParent destination, List&lt;DstChild&gt; destMember, ResolutionContext context)
      {
          /*
           * Many expensive operations that can be safely cached
           * on the resolver instance through the lifetime.
           */
      }
  }
  
  // Seed the mapper with an existing instance to hint the child conversion.
  var dst = new DstParent
  {
      ConfigurationId = 42
  };
  
  this.mapper.Map(src, dst);
  </code></pre>