Skip to content

Commit

Permalink
Add default interface implementations to interceptors
Browse files Browse the repository at this point in the history
Plus some cleanup

Closes dotnet#27625
  • Loading branch information
roji committed Mar 13, 2022
1 parent 96f7bb8 commit 5ffcbf8
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 970 deletions.
358 changes: 26 additions & 332 deletions src/EFCore.Relational/Diagnostics/DbCommandInterceptor.cs

Large diffs are not rendered by default.

143 changes: 15 additions & 128 deletions src/EFCore.Relational/Diagnostics/DbConnectionInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,169 +12,56 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics;
/// </remarks>
public abstract class DbConnectionInterceptor : IDbConnectionInterceptor
{
/// <summary>
/// Called just before EF intends to call <see cref="DbConnection.Open()" />.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="eventData">Contextual information about the connection.</param>
/// <param name="result">
/// Represents the current result if one exists.
/// This value will have <see cref="InterceptionResult.IsSuppressed" /> set to <see langword="true" /> if some previous
/// interceptor suppressed execution by calling <see cref="InterceptionResult.Suppress" />.
/// This value is typically used as the return value for the implementation of this method.
/// </param>
/// <returns>
/// If <see cref="InterceptionResult.IsSuppressed" /> is false, the EF will continue as normal.
/// If <see cref="InterceptionResult.IsSuppressed" /> is true, then EF will suppress the operation
/// it was about to perform.
/// A normal implementation of this method for any interceptor that is not attempting to suppress
/// the operation is to return the <paramref name="result" /> value passed in.
/// </returns>
public virtual InterceptionResult ConnectionOpening(
DbConnection connection,
ConnectionEventData eventData,
InterceptionResult result)
/// <inheritdoc />
public virtual InterceptionResult ConnectionOpening(DbConnection connection, ConnectionEventData eventData, InterceptionResult result)
=> result;

/// <summary>
/// Called just before EF intends to call <see cref="DbConnection.OpenAsync()" />.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="eventData">Contextual information about the connection.</param>
/// <param name="result">
/// Represents the current result if one exists.
/// This value will have <see cref="InterceptionResult.IsSuppressed" /> set to <see langword="true" /> if some previous
/// interceptor suppressed execution by calling <see cref="InterceptionResult.Suppress" />.
/// This value is typically used as the return value for the implementation of this method.
/// </param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>
/// If <see cref="InterceptionResult.IsSuppressed" /> is false, the EF will continue as normal.
/// If <see cref="InterceptionResult.IsSuppressed" /> is true, then EF will suppress the operation
/// it was about to perform.
/// A normal implementation of this method for any interceptor that is not attempting to suppress
/// the operation is to return the <paramref name="result" /> value passed in.
/// </returns>
/// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception>
/// <inheritdoc />
public virtual ValueTask<InterceptionResult> ConnectionOpeningAsync(
DbConnection connection,
ConnectionEventData eventData,
InterceptionResult result,
CancellationToken cancellationToken = default)
=> new(result);

/// <summary>
/// Called just after EF has called <see cref="DbConnection.Open()" />.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="eventData">Contextual information about the connection.</param>
/// <inheritdoc />
public virtual void ConnectionOpened(DbConnection connection, ConnectionEndEventData eventData)
{
}

/// <summary>
/// Called just after EF has called <see cref="DbConnection.OpenAsync()" />.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="eventData">Contextual information about the connection.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task" /> representing the asynchronous operation.</returns>
/// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception>
/// <inheritdoc />
public virtual Task ConnectionOpenedAsync(
DbConnection connection,
ConnectionEndEventData eventData,
CancellationToken cancellationToken = default)
=> Task.CompletedTask;

/// <summary>
/// Called just before EF intends to call <see cref="DbConnection.Close()" />.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="eventData">Contextual information about the connection.</param>
/// <param name="result">
/// Represents the current result if one exists.
/// This value will have <see cref="InterceptionResult.IsSuppressed" /> set to <see langword="true" /> if some previous
/// interceptor suppressed execution by calling <see cref="InterceptionResult.Suppress" />.
/// This value is typically used as the return value for the implementation of this method.
/// </param>
/// <returns>
/// If <see cref="InterceptionResult.IsSuppressed" /> is false, the EF will continue as normal.
/// If <see cref="InterceptionResult.IsSuppressed" /> is true, then EF will suppress the operation
/// it was about to perform.
/// A normal implementation of this method for any interceptor that is not attempting to suppress
/// the operation is to return the <paramref name="result" /> value passed in.
/// </returns>
public virtual InterceptionResult ConnectionClosing(
DbConnection connection,
ConnectionEventData eventData,
InterceptionResult result)
/// <inheritdoc />
public virtual InterceptionResult ConnectionClosing(DbConnection connection, ConnectionEventData eventData, InterceptionResult result)
=> result;

/// <summary>
/// Called just before EF intends to call <see cref="DbConnection.CloseAsync()" /> in an async context.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="eventData">Contextual information about the connection.</param>
/// <param name="result">
/// Represents the current result if one exists.
/// This value will have <see cref="InterceptionResult.IsSuppressed" /> set to <see langword="true" /> if some previous
/// interceptor suppressed execution by calling <see cref="InterceptionResult.Suppress" />.
/// This value is typically used as the return value for the implementation of this method.
/// </param>
/// <returns>
/// If <see cref="InterceptionResult.IsSuppressed" /> is false, the EF will continue as normal.
/// If <see cref="InterceptionResult.IsSuppressed" /> is true, then EF will suppress the operation
/// it was about to perform.
/// A normal implementation of this method for any interceptor that is not attempting to suppress
/// the operation is to return the <paramref name="result" /> value passed in.
/// </returns>
/// <inheritdoc />
public virtual ValueTask<InterceptionResult> ConnectionClosingAsync(
DbConnection connection,
ConnectionEventData eventData,
InterceptionResult result)
=> new(result);

/// <summary>
/// Called just after EF has called <see cref="DbConnection.Close()" /> in an async context.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="eventData">Contextual information about the connection.</param>
public virtual void ConnectionClosed(
DbConnection connection,
ConnectionEndEventData eventData)
/// <inheritdoc />
public virtual void ConnectionClosed(DbConnection connection, ConnectionEndEventData eventData)
{
}

/// <summary>
/// Called just after EF has called <see cref="DbConnection.CloseAsync()" />.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="eventData">Contextual information about the connection.</param>
/// <returns>A <see cref="Task" /> representing the asynchronous operation.</returns>
public virtual Task ConnectionClosedAsync(
DbConnection connection,
ConnectionEndEventData eventData)
/// <inheritdoc />
public virtual Task ConnectionClosedAsync(DbConnection connection, ConnectionEndEventData eventData)
=> Task.CompletedTask;

/// <summary>
/// Called when opening of a connection has failed with an exception.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="eventData">Contextual information about the connection.</param>
public virtual void ConnectionFailed(
DbConnection connection,
ConnectionErrorEventData eventData)
/// <inheritdoc />
public virtual void ConnectionFailed(DbConnection connection, ConnectionErrorEventData eventData)
{
}

/// <summary>
/// Called when opening of a connection has failed with an exception.
/// </summary>
/// <param name="connection">The connection.</param>
/// <param name="eventData">Contextual information about the connection.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="Task" /> representing the asynchronous operation.</returns>
/// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception>
/// <inheritdoc />
public virtual Task ConnectionFailedAsync(
DbConnection connection,
ConnectionErrorEventData eventData,
Expand Down
Loading

0 comments on commit 5ffcbf8

Please sign in to comment.