Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option for a custom ProfiledDbDataReader implementation #325

Merged
merged 3 commits into from
Sep 16, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/MiniProfiler.Shared/Data/ProfiledDbCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ public override UpdateRowSource UpdatedRowSource
set => _command.UpdatedRowSource = value;
}

/// <summary>
/// Creates a wrapper data reader for <see cref="ExecuteDbDataReader"/> and <see cref="ExecuteDbDataReaderAsync"/> />
/// </summary>
protected virtual DbDataReader CreateDataReader(DbDataReader original, IDbProfiler profiler)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's align the naming here - we have CreateDbCommand with Db elsewhere and CreateDataReader here - can you please change this to CreateDbDataReader (more correct given the return type).

=> new ProfiledDbDataReader(original, profiler);

/// <summary>
/// Executes a database data reader.
/// </summary>
Expand All @@ -213,7 +219,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 +252,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
9 changes: 8 additions & 1 deletion src/MiniProfiler.Shared/Data/ProfiledDbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,19 @@ protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLeve
{
return new ProfiledDbTransaction(_connection.BeginTransaction(isolationLevel), this);
}

/// <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 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