title: AutoFac+WebAPI not disposing objects
body: <p>I have the following piece of code to build the dependencies:</p>
  
  <pre class="lang-cs prettyprint-override"><code>private static void InitializeContainer(HttpConfiguration config)
  {
      var builder = new ContainerBuilder();
      var controllers = AssemblyUtils.GetAssemblies(true);
  
      controllers.Add(Assembly.GetExecutingAssembly());
  
      builder.RegisterApiControllers(controllers.ToArray()).PropertiesAutowired();
  
      builder
          .RegisterAssemblyTypes(
              new List&lt;Assembly&gt;(AssemblyUtils.GetAssemblies(false))
              {
                  Assembly.GetExecutingAssembly()
              }.ToArray())
          .Where(t =&gt;
              t.GetCustomAttributes(typeof(IocContainerMarkerAttribute), false).Any() ||
              t.IsSubclassOf(typeof(HandlerAspectAttribute)) ||
              typeof(ICoreContract).IsAssignableFrom(t))
          .AsImplementedInterfaces().InstancePerDependency()
          .PropertiesAutowired().OwnedByLifetimeScope();
  
      var container = builder.Build();
  
      GlobalConfiguration.Configuration.DependencyResolver =
         new AutofacWebApiDependencyResolver(container);
  
      config.DependencyResolver =
          GlobalConfiguration.Configuration.DependencyResolver;
  }
  </code></pre>
  
  <p>Handler:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class ArchieveDocumentCommandHandler 
      : IHandler&lt;ArchieveDocumentCommand&gt;, IDisposable
  {
      public IServiceMessageDispatcher Dispatcher { get; set; }
      public IDocumentRepository DocumentRepository { get; set; }
      public IFileSystemProvider FileSystemProvider { get; set; }
      public ICoreSettingRepository CoreSettingRepository { get; set; }
  
      public void Handles(ArchieveDocumentCommand message) { }
  
      public void Dispose() { }
  }
  </code></pre>
  
  <p>But somehow Autofac is not calling the <code>Dispose</code> method in the object after the request has finished. I read about the lifetime scope, but since that in this case it is Autofac managing the scope, I can't understand what is going on.</p>
  
  <p>Am I doing something wrong here?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>public class CommandsController : ApiController
  {
      [HttpPost]
      public HttpResponseMessage Deliver()
      {
      ...
  
          var handler = GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(ICommandValidator&lt;&gt;).MakeGenericType(message.GetType()));
  
          if (handler == null)
          {
              return new Dictionary&lt;string, string&gt;();
          }
  
          return (Dictionary&lt;string, string&gt;)handler.GetType()
              .InvokeMember("ValidateCommand", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, handler, new object[] { message });
      }
  }
  </code></pre>
  
  <p>Also the autofac web api version I am using is: 3.1.1
  Which also broke some exiting functionality:</p>
  
  <p>A controller as such:</p>
  
  <pre><code>public class AProtectedReadModelController : ApiController
  { }
  
  public class AssessmentController : AProtectedReadModelController
  {
      [Route("queries/risk/assessment")]
      [HttpGet]
      public ProcessInitialScreenModel GetProcessInitialScreen()
      {
          return ...;
      }
  }
  </code></pre>
  
  <p>is not loaded.</p>