using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using Tanshu.Data.DAO; namespace Tanshu.Accounts.SqlDAO { public abstract class BaseDAO : IDisposable { protected IConnectionDAO connection; protected BaseDAO(IConnectionDAO connection) { this.connection = connection; } #region IDisposable Members private bool disposed = false; ~BaseDAO() { // call Dispose with false. Since we're in the // destructor call, the managed resources will be // disposed of anyways. Dispose(false); } public void Dispose() { // dispose of the managed and unmanaged resources Dispose(true); // tell the GC that the Finalize process no longer needs // to be run for this object. GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposeManagedResources) { // process only if mananged and unmanaged resources have // not been disposed of. if (!this.disposed) { Trace.WriteLine("Tanshu.WebAccounts.SqlDAO.BaseDAO: Resources not disposed"); if (disposeManagedResources) { Trace.WriteLine("Tanshu.WebAccounts.SqlDAO.BaseDAO: Disposing managed resources"); // dispose managed resources //if (connection != null) //{ // connection.Dispose(); // connection = null; //} } // dispose unmanaged resources Trace.WriteLine("Tanshu.WebAccounts.SqlDAO.BaseDAO: Disposing unmanaged resouces"); disposed = true; } else { Trace.WriteLine("Tanshu.WebAccounts.SqlDAO.BaseDAO: Resources already disposed"); } } #endregion } }