title: How to dispose resources with dependency injection
body: <p>I'm using StructureMap to resolve references to my repository class. My repository interface implements IDisposable, e.g.</p>
  
  <pre><code>public interface IMyRepository : IDisposable
  {
    SomeClass GetById(int id);
  }
  </code></pre>
  
  <p>An implementation of the interface using Entity Framework:</p>
  
  <pre><code>public MyRepository : IMyRepository
  {
      private MyDbContext _dbContext;
  
      public MyDbContext()
      {
          _dbContext = new MyDbContext();
      }
  
      public SomeClass GetById(int id)
      {
          var query = from x in _dbContext
                      where x.Id = id
                      select x;
          return x.FirstOrDefault();
      }
  
      public void Dispose()
      {
          _dbContext.Dispose();
      }
  }
  </code></pre>
  
  <p>Anyway as mentioned I'm using StructureMap to resolve IMyRepository. So <strong>when, where and how</strong> should I call my dispose method?</p>