Created
March 27, 2022 12:43
-
-
Save dcagnetta/d8119b3eca9a586cbd6ce1c7636e7188 to your computer and use it in GitHub Desktop.
IDisposable Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DbRepository : IDisposable | |
{ | |
public IDbConnection Connection { get; set; } | |
private bool _disposedValue; | |
protected virtual void Dispose(bool disposing) | |
{ | |
if (!_disposedValue) | |
{ | |
if (disposing) | |
{ | |
Connection.Dispose(); | |
} | |
// Free unmanaged resources (unmanaged objects) and override finalizer | |
// Set large fields to null | |
Connection = null; | |
_disposedValue = true; | |
} | |
} | |
public virtual void Dispose() | |
{ | |
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method | |
Dispose(disposing: true); | |
GC.SuppressFinalize(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment