title: Autofac not working with background tasks
body: <p>I have a task that needs to be run in a separate thread in the background, and I am using SignalR to report progress.  This worked some time ago, and I had made some code modifications, but I am at a complete loss as to the error I receive now:</p>
  
  <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>
  
  <p>Any help is greatly appreciated!</p>
  
  <pre><code>    public ActionResult DoAction(IEnumerable&lt;string&gt; items){
  
      //...
      Func&lt;CancellationToken, Task&gt; taskFunc = CancellationToken =&gt; performAction(items);
      HostingEnvironment.QueueBackgroundWorkItem(taskFunc);
      //...
      }
  
      private async Task performAction(IEnumerable&lt;string&gt; items){
      var svc = AutofacDependencyResolver.Current.AppicationContainer.BeginLifetimeScope().Resolve&lt;MyService&gt;();
      svc.Method(items);
      }
  
  public class MyService{
     private EntityContext db;
  
     public MyService(EntityContext db){
  
     this.db = db;
     }
  }
  </code></pre>
  
  <p>In my Startup.Container.cs file:</p>
  
  <pre><code>builder.RegisterType&lt;MyService&gt;().As&lt;MyService&gt;().InstancePerLifetimeScope();
     builder.RegisterType&lt;EntityContext&gt;().InstancePerRequest();
  </code></pre>