Created
August 24, 2016 14:21
-
-
Save jehugaleahsa/e460f9e168e89bc450f328eefb2c2a21 to your computer and use it in GitHub Desktop.
Connection Lifetime Manager
This file contains 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 ConnectionLifetimeManager : IDisposable | |
{ | |
private readonly IDbConnection connection; | |
private readonly bool needsClosed; | |
public ConnectionLifetimeManager(IDbConnection connection) | |
{ | |
this.connection = connection; | |
if (connection.State == ConnectionState.Closed) | |
{ | |
connection.Open(); | |
needsClosed = true; | |
} | |
} | |
public void Dispose() | |
{ | |
if (needsClosed) | |
{ | |
connection.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment