title: DbContext has been disposed and autofac
body: <p>I have a controller:</p>
  
  <pre><code>private readonly ILogger _logger;    
  private readonly IRepository _repository;
  
  public HomeController(ILogger logger, IRepository repository)
  {
     _logger = logger;
     _repository = repository;
  }
  </code></pre>
  
  <p>This is the repository:</p>
  
  <pre><code>public class EfRepository : IRepository
  {
      // ...methods for add, delete, update entities
      // ....
  
      public void Dispose()
      {
           if (this._context != null)
           {
               this._context.SaveChanges();
               (this._context as IDisposable).Dispose();
               this._context = null;
           }
      }
  }
  </code></pre>
  
  <p>Finally, registration types in IoC:</p>
  
  <pre><code>_builder.RegisterType&lt;Logger&gt;().As&lt;ILogger&gt;();
  _builder.RegisterType&lt;EfRepository&gt;().As&lt;IRepository&gt;().WithParameter("context", new PcpContext());
  </code></pre>
  
  <p>When I run the application I get this error:</p>
  
  <blockquote>
    <p>The operation cannot be completed because the DbContext has been
    disposed.</p>
  </blockquote>
  
  <p>I tried to change registration EfRepository like this:</p>
  
  <pre><code>_builder.RegisterType&lt;EfRepository&gt;()
     .As&lt;IRepository&gt;()
     .WithParameter("context", new PcpContext()).InstancePerLifetimeScope();
  </code></pre>
  
  <p>In this case the first request finish, but when trying to open other pages, I get the error again. Where is the problem?</p>