title: How to dispose of DbContext in WebApi?
body: <p>My controllers reference my services using DI. The controllers have no knowledge of EF or its DbContext. Even the services have no knowledge of EF or the DbContext because they reference UoW (also through DI):</p>
  
  <pre><code>public class CustomerController : ApiController
  {
      private readonly ICustomerService customerService;
  
      public CustomerController(ILogService logService,
                                ICustomerService customerService)
      {
          this.customerService = customerService;
      }
  }
  
  public CustomerService(ILogService logService, IUnitOfWork unitOfWork) {}
  </code></pre>
  
  <p>The UoW obviously references the DbContext:</p>
  
  <pre><code>public interface IUnitOfWork : IDisposable { }
  
  public class UnitOfWork : IUnitOfWork
  {
      private DbContext context;
  }
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li><p>Should the UoW implement the IDisposable so that the context is disposed of once the UoW goes out of scope?</p></li>
  <li><p>Should the services implement IDisposable to dispose of the UoW?</p></li>
  <li><p>Or is the disposing of UoW and services handled by Autofac (my DI)?</p></li>
  </ol>