Created
September 27, 2015 05:54
-
-
Save WilliamBerryiii/d444f262444eb8e05249 to your computer and use it in GitHub Desktop.
An example repository with timing method wrapping the database calls.
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 Repository | |
{ | |
private ISqlExecutioner _sqlExecutioner; | |
private string _connectionString; | |
private long _dbQueryRequestTime; | |
public long DbQueryRequestTime { get { return _dbQueryRequestTime; }} | |
public Repository (ISqlExecutioner sqlExecutioner, string connectionString) | |
{ | |
_sqlExecutioner = sqlExecutioner; | |
_connectionString = connectionString; | |
} | |
public static DataSet GetSomeStuffFromTheDatabase(int thingId) | |
{ | |
const string PROCEDURE_NAME = "GetMeSomeData"; | |
var parameterLisst = new SqlParameterList(); | |
parameterList.Add("@thing_id", SqlDbType.Int, thingId); | |
return TimeCall(() => | |
_sqlExecutioner.ExecuteQuery(_connectionString, PROCEDURE_NAME, parameterList) | |
,ref _dbQueryRequestTime) ; | |
} | |
private static DataSet TimeCall( | |
Func<DataSet> func, | |
ref long dbQueryRequestTime) | |
{ | |
var stopwatch = Stopwatch.StartNew(); | |
var result = func(); | |
stopwatch.Stop(); | |
Interlocked.Add(ref dbQueryRequestTime, stopwatch.ElapsedTicks); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment