Created
August 20, 2017 18:51
-
-
Save davidfowl/29829253e4134b379007c541d720511c to your computer and use it in GitHub Desktop.
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
// Whatever shared state you need, the root of the universe | |
public class DapperContext | |
{ | |
private QueryCache _cache = new QueryCache(); | |
public static DapperContext Instance = new DapperContext(); | |
public Task<IEnumerable<dynamic>> QueryAsync(IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null) | |
{ | |
// Real logic happens here | |
} | |
} | |
// Extension methods act as sugar for accessing the "static" default query instance. | |
public static partial class SqlMapper | |
{ | |
public static Task<IEnumerable<dynamic>> QueryAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null) | |
{ | |
return DapperContext.Instance.QueryAsync(conn, sql, param, transaction, commandTimeout, commandType); | |
} | |
} | |
// You now write unit tests against the DapperContext directly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment