title: Autofac.Hangfire doesn't find registered types
body: <p>I'm trying to use Autofac for DI in my ASP.NET MVC application. It works fine but I cannot solve a problem with Hangfire.</p>
  
  <p>Here my startup.cs code:</p>
  
  <pre><code>public partial class Startup
  {
      public void Configuration(IAppBuilder app)
      {
          GlobalConfiguration.Configuration.UseSqlServerStorage("MyContext");
  
          var container = new AutofacContainer().Container;
          var resolver = new AutofacDependencyResolver(container);
  
          app.UseAutofacMiddleware(container);
          app.MapSignalR(new HubConfiguration
          {
              Resolver = resolver
          });
  
          AddSignalRInjection(container, resolver);
          app.UseHangfireDashboard();
          app.UseHangfireServer();
      }
  
      private void AddSignalRInjection(IContainer container, IDependencyResolver resolver)
      {
          var updater = new ContainerBuilder();
  
          updater.RegisterInstance(resolver.Resolve&lt;IConnectionManager&gt;());
          updater.RegisterInstance(resolver.Resolve&lt;IMyContext&gt;());
          updater.RegisterInstance(resolver.Resolve&lt;ILiveData&gt;());
          updater.RegisterInstance(resolver.Resolve&lt;IErp&gt;());
          updater.Update(container);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>here the AutofacContainer.cs:</p>
  
  <pre><code>public class AutofacContainer
  {
      public IContainer Container { get; set; }
      public AutofacContainer()
      {
          var builder = new ContainerBuilder();
  
          builder.RegisterControllers(typeof(MvcApplication).Assembly);
          builder.RegisterHubs(Assembly.GetExecutingAssembly()).PropertiesAutowired();
          builder.RegisterType&lt;LiveData&gt;().As&lt;ILiveData&gt;().PropertiesAutowired().InstancePerLifetimeScope();
          builder.RegisterType&lt;MyContext&gt;().As&lt;IMyContext&gt;().PropertiesAutowired();
          builder.RegisterType&lt;Erp&gt;().As&lt;IErp&gt;().PropertiesAutowired();
          Container = builder.Build();
          GlobalConfiguration.Configuration.UseAutofacActivator(Container);
          DependencyResolver.SetResolver(new Autofac.Integration.Mvc.AutofacDependencyResolver(Container));
      }
  }
  </code></pre>
  
  <p>here an extract from Erp.cs:</p>
  
  <pre><code>public interface IErp
  {
      void InitializeMachines();
  }
  
  public class Erp : IErp
  {
      public IConnectionManager ConnectionManager { get; set; }
      public IMyContext _context { get; set; }
      public ILiveData _liveData { get; set; }
  
      public Erp(IMyContext context, ILiveData liveData)
      {
          _context = context;
          _liveData = liveData;
      }
  
      public void InitializeMachines()
      {
          // do something
      }
  }
  </code></pre>
  
  <p>I add a job in this way:</p>
  
  <pre><code>Hangfire.BackgroundJob.Enqueue&lt;Erp&gt;(x =&gt; x.InitializeMachines());
  </code></pre>
  
  <p>I get the following Hangfire error:</p>
  
  <pre><code>Failed
  An exception occurred during processing of a background job.
  Autofac.Core.Registration.ComponentNotRegisteredException
  
  The requested service 'MyProject.Classes.Erp' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
  </code></pre>
  
  <p>The message says the Erp service is not registered, but I don't understand why. As you saw above, I actually registered it:</p>
  
  <pre><code>builder.RegisterType&lt;Erp&gt;().As&lt;IErp&gt;().PropertiesAutowired();
  </code></pre>
  
  <p>Is the message saying something different I don't understand?</p>