title: Must I implement IDisposable on all classes, or is a base class sufficient?
body: <p>I am told I need to <a href="http://www.asp.net/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application" rel="nofollow">dispose of instances of my Entity Framework repository classes</a> and I created a base class to enforce this implementation.</p>
  
  <p>I need to check with the experts: is it acceptable to implement <code>IDisposable</code> through a base class? </p>
  
  <p>Note that the repository class has no class member variables.</p>
  
  <pre><code>/// Sample repository.  Note that I return List&lt;T&gt; as IEnumerable, 
  /// and I use IDisposable 
  ///
  public class CompanyRepository : DisposableBase, ICompanyRepository
  {
      public IEnumerable&lt;CompanyDetail&gt; GetOneCompany(int? CompanyID)
      {
          var t = from c in _entities.CompanyDetail
                  where c.CompanyID == CompanyID.Value
                  select c;
          return t.ToList();
      }
  }
  
  /// &lt;summary&gt;
  /// Disposable implementation based on advice from this link:
  /// from Http://www.asp.net/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
  /// &lt;/summary&gt;
  public class DisposableBase : IDisposable
  {
      protected TLSAdminEntities1 _entities;
  
      public DisposableBase()
      {
          _entities = new TLSAdminEntities1();
          disposed = false;
      }
  
      private bool disposed ;
      protected virtual void Dispose(bool disposing)
      {
          if (!this.disposed)
          {
              if (disposing)
              {
                  _entities.Dispose();
              }
          }
          this.disposed = true;
      }
      public void Dispose()
      {
          Dispose(true);
          GC.SuppressFinalize(this);
      }
  }
  </code></pre>