Skip to content

Commit

Permalink
Added extension points for creating ProfiledDbCommand and ProfiledDbD…
Browse files Browse the repository at this point in the history
…ataReader
  • Loading branch information
kekekeks committed Sep 14, 2018
1 parent cc91adf commit 0fb7080
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/MiniProfiler.Shared/Data/ProfiledDbCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ public override UpdateRowSource UpdatedRowSource
set => _command.UpdatedRowSource = value;
}

protected virtual DbDataReader CreateDataReader(DbDataReader original, IDbProfiler profiler)
=> new ProfiledDbDataReader(original, profiler);

/// <summary>
/// Executes a database data reader.
/// </summary>
Expand All @@ -213,7 +216,7 @@ protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
try
{
result = _command.ExecuteReader(behavior);
result = new ProfiledDbDataReader(result, _profiler);
result = CreateDataReader(result, _profiler);
}
catch (Exception e)
{
Expand Down Expand Up @@ -246,7 +249,7 @@ protected override async Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBeha
try
{
result = await _command.ExecuteReaderAsync(behavior, cancellationToken).ConfigureAwait(false);
result = new ProfiledDbDataReader(result, _profiler);
result = CreateDataReader(result, _profiler);
}
catch (Exception e)
{
Expand Down
5 changes: 4 additions & 1 deletion src/MiniProfiler.Shared/Data/ProfiledDbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,15 @@ protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLeve
{
return new ProfiledDbTransaction(_connection.BeginTransaction(isolationLevel), this);
}

protected virtual DbCommand CreateDbCommand(DbCommand original, IDbProfiler profiler)
=> new ProfiledDbCommand(original, this, profiler);

/// <summary>
/// Creates and returns a <see cref="DbCommand"/> object associated with the current connection.
/// </summary>
/// <returns>A <see cref="ProfiledDbCommand"/> wrapping the created <see cref="DbCommand"/>.</returns>
protected override DbCommand CreateDbCommand() => new ProfiledDbCommand(_connection.CreateCommand(), this, _profiler);
protected override DbCommand CreateDbCommand() => CreateDbCommand(_connection.CreateCommand(), _profiler);

/// <summary>
/// Dispose the underlying connection.
Expand Down

0 comments on commit 0fb7080

Please sign in to comment.