title: Autofac + Automapper + custom ValueResolver
body: <p>Let's say I have custom <code>ValueResolver</code></p>
  
  <pre><code>public class AssessmentAttendiesResolver : ValueResolver&lt;List&lt;int&gt;, ICollection&lt;Expert&gt;&gt;
  {
      private readonly IRepository&lt;Expert&gt; _expertRepository; 
  
      public AssessmentAttendiesResolver(IRepository&lt;Expert&gt; expertRepository)
      {
          _expertRepository = expertRepository;
      }
  
      protected override ICollection&lt;Expert&gt; ResolveCore(List&lt;int&gt; source)
      {
          return (ICollection&lt;Expert&gt;)_expertRepository.Query();
      }
  }
  </code></pre>
  
  <p>In my Global.asax I registered my custom resolver and override Mapper.Initialize method like this.</p>
  
  <pre><code>builder.RegisterAssemblyTypes(currentAssembly).AsClosedTypesOf(typeof(ValueResolver&lt;,&gt;)).AsSelf();
  
      var container = builder.Build();
      Mapper.Initialize(conf =&gt; conf.ConstructServicesUsing(container.Resolve));
  </code></pre>
  
  <p>And <code>CreateMap</code> method</p>
  
  <pre><code>    Mapper.CreateMap&lt;AssessmentCreateRequestModel, Assessment&gt;()
          .ForMember(dest =&gt; dest.Attendies, opt =&gt; opt.ResolveUsing&lt;AssessmentAttendiesResolver&gt;().FromMember(item =&gt; item.Attendies));
  </code></pre>
  
  <p>When I run the code I get such exception</p>
  
  <blockquote>
    <p>No scope with a Tag matching 'AutofacWebRequest' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being requested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.</p>
  </blockquote>
  
  <p>What should I change in order to successfully inject my repositories in my custom value resolver?</p>