title: Autofac & MassTransit - Register Consumer ObjectDisposedException
body: <p>Context: ASP.NET Core App (1.1).</p>
  
  <p>I try to resolve the IRepository that i've already registered when i need a consumer instance, but it looks like i receive a ObjectDisposedException. </p>
  
  <p><a href="https://i.stack.imgur.com/od32c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/od32c.png" alt="BusFactoryMethod"></a></p>
  
  <p>I created a bus factory method that auto activates when i call <code>.Build()</code> method of the <code>ContainerBuilder</code>.</p>
  
  <pre><code> public IServiceProvider ConfigureServices(IServiceCollection services)
   {
    var containerBuilder = new ContainerBuilder();
    containerBuilder.RegisterType&lt;EventTypeResolver&gt;().As&lt;IEventTypeResolver&gt;();
    containerBuilder.RegisterType&lt;Repository&gt;().As&lt;IRepository&gt;();
    containerBuilder.Register(c =&gt; EventStoreConnectionFactory.Create())
                              .As&lt;IEventStoreConnection&gt;();
    containerBuilder.Register(BusFactoryMethod).AsSelf().SingleInstance().AutoActivate();
    containerBuilder.Populate(services);
    return new AutofacServiceProvider(containerBuilder.Build());
  }
  </code></pre>
  
  <p><code>BusFactoryMethod</code> looks like this: </p>
  
  <pre><code> private IBusControl BusFactoryMethod(IComponentContext componentContext)
   {
      var busControl = BusConfigurator.Instance.ConfigureBus((cfg, host) =&gt;
              {
                  cfg.ReceiveEndpoint(host, RabbitMQConstants.UserManagementQueue, e =&gt;
                  {
                      e.Consumer(() =&gt; new CreateUserCommandConsumer(componentContext.Resolve&lt;IRepository&gt;()));
                  });
              });
      busControl.Start();
      return busControl;
   }
  </code></pre>