From 5ffcbf8ec34c9a7bbb04994823bd53ae96decc40 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Sun, 13 Mar 2022 14:47:48 +0100 Subject: [PATCH] Add default interface implementations to interceptors Plus some cleanup Closes #27625 --- .../Diagnostics/DbCommandInterceptor.cs | 358 ++---------------- .../Diagnostics/DbConnectionInterceptor.cs | 143 +------ .../Diagnostics/DbTransactionInterceptor.cs | 279 ++------------ .../Diagnostics/IDbCommandInterceptor.cs | 94 ++--- .../Diagnostics/IDbConnectionInterceptor.cs | 56 ++- .../Diagnostics/IDbTransactionInterceptor.cs | 120 +++--- .../Diagnostics/ISaveChangesInterceptor.cs | 33 +- .../Diagnostics/SaveChangesInterceptor.cs | 104 +---- 8 files changed, 217 insertions(+), 970 deletions(-) diff --git a/src/EFCore.Relational/Diagnostics/DbCommandInterceptor.cs b/src/EFCore.Relational/Diagnostics/DbCommandInterceptor.cs index 4393f7d221d..165cde4038f 100644 --- a/src/EFCore.Relational/Diagnostics/DbCommandInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/DbCommandInterceptor.cs @@ -12,141 +12,33 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics; /// public abstract class DbCommandInterceptor : IDbCommandInterceptor { - /// - /// Called just before EF intends to call . - /// - /// Contextual information about the command and execution. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in. - /// - public virtual InterceptionResult CommandCreating( - CommandCorrelatedEventData eventData, - InterceptionResult result) + /// + public virtual InterceptionResult CommandCreating(CommandCorrelatedEventData eventData, InterceptionResult result) => result; - /// - /// Called immediately after EF calls . - /// - /// - /// This method is still called if an interceptor suppressed creation of a command in - /// . - /// In this case, is the result returned by . - /// - /// Contextual information about the command and execution. - /// - /// The result of the call to . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// The result that EF will use. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in. - /// + /// public virtual DbCommand CommandCreated(CommandEndEventData eventData, DbCommand result) => result; - /// - /// Called just before EF intends to call . - /// - /// The command. - /// Contextual information about the command and execution. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// + /// public virtual InterceptionResult ReaderExecuting( DbCommand command, CommandEventData eventData, InterceptionResult result) => result; - /// - /// Called just before EF intends to call . - /// - /// The command. - /// Contextual information about the command and execution. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// + /// public virtual InterceptionResult ScalarExecuting( DbCommand command, CommandEventData eventData, InterceptionResult result) => result; - /// - /// Called just before EF intends to call . - /// - /// The command. - /// Contextual information about the command and execution. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// - public virtual InterceptionResult NonQueryExecuting( - DbCommand command, - CommandEventData eventData, - InterceptionResult result) + /// + public virtual InterceptionResult NonQueryExecuting(DbCommand command, CommandEventData eventData, InterceptionResult result) => result; - /// - /// Called just before EF intends to call . - /// - /// The command. - /// Contextual information about the command and execution. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// - /// If the is canceled. + /// public virtual ValueTask> ReaderExecutingAsync( DbCommand command, CommandEventData eventData, @@ -154,26 +46,7 @@ public virtual ValueTask> ReaderExecutingAsync( CancellationToken cancellationToken = default) => new(result); - /// - /// Called just before EF intends to call . - /// - /// The command. - /// Contextual information about the command and execution. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// - /// If the is canceled. + /// public virtual ValueTask> ScalarExecutingAsync( DbCommand command, CommandEventData eventData, @@ -181,26 +54,7 @@ public virtual ValueTask> ScalarExecutingAsync( CancellationToken cancellationToken = default) => new(result); - /// - /// Called just before EF intends to call . - /// - /// The command. - /// Contextual information about the command and execution. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// - /// If the is canceled. + /// public virtual ValueTask> NonQueryExecutingAsync( DbCommand command, CommandEventData eventData, @@ -208,98 +62,19 @@ public virtual ValueTask> NonQueryExecutingAsync( CancellationToken cancellationToken = default) => new(result); - /// - /// Called immediately after EF calls . - /// - /// - /// This method is still called if an interceptor suppressed execution of a command in . - /// In this case, is the result returned by . - /// - /// The command. - /// Contextual information about the command and execution. - /// - /// The result of the call to . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// The result that EF will use. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in. - /// - public virtual DbDataReader ReaderExecuted( - DbCommand command, - CommandExecutedEventData eventData, - DbDataReader result) + /// + public virtual DbDataReader ReaderExecuted(DbCommand command, CommandExecutedEventData eventData, DbDataReader result) => result; - /// - /// Called immediately after EF calls . - /// - /// - /// This method is still called if an interceptor suppressed execution of a command in . - /// In this case, is the result returned by . - /// - /// The command. - /// Contextual information about the command and execution. - /// - /// The result of the call to . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// The result that EF will use. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in. - /// - public virtual object? ScalarExecuted( - DbCommand command, - CommandExecutedEventData eventData, - object? result) + /// + public virtual object? ScalarExecuted(DbCommand command, CommandExecutedEventData eventData, object? result) => result; - /// - /// Called immediately after EF calls . - /// - /// - /// This method is still called if an interceptor suppressed execution of a command in . - /// In this case, is the result returned by . - /// - /// The command. - /// Contextual information about the command and execution. - /// - /// The result of the call to . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// The result that EF will use. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in. - /// - public virtual int NonQueryExecuted( - DbCommand command, - CommandExecutedEventData eventData, - int result) + /// + public virtual int NonQueryExecuted(DbCommand command, CommandExecutedEventData eventData, int result) => result; - /// - /// Called immediately after EF calls . - /// - /// - /// This method is still called if an interceptor suppressed execution of a command in . - /// In this case, is the result returned by . - /// - /// The command. - /// Contextual information about the command and execution. - /// - /// The result of the call to . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// A providing the result that EF will use. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// - /// If the is canceled. + /// public virtual ValueTask ReaderExecutedAsync( DbCommand command, CommandExecutedEventData eventData, @@ -307,26 +82,7 @@ public virtual ValueTask ReaderExecutedAsync( CancellationToken cancellationToken = default) => new(result); - /// - /// Called immediately after EF calls . - /// - /// - /// This method is still called if an interceptor suppressed execution of a command in . - /// In this case, is the result returned by . - /// - /// The command. - /// Contextual information about the command and execution. - /// - /// The result of the call to . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// A providing the result that EF will use. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// - /// If the is canceled. + /// public virtual ValueTask ScalarExecutedAsync( DbCommand command, CommandExecutedEventData eventData, @@ -334,26 +90,7 @@ public virtual ValueTask ReaderExecutedAsync( CancellationToken cancellationToken = default) => new(result); - /// - /// Called immediately after EF calls . - /// - /// - /// This method is still called if an interceptor suppressed execution of a command in . - /// In this case, is the result returned by . - /// - /// The command. - /// Contextual information about the command and execution. - /// - /// The result of the call to . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// A providing the result that EF will use. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// - /// If the is canceled. + /// public virtual ValueTask NonQueryExecutedAsync( DbCommand command, CommandExecutedEventData eventData, @@ -361,74 +98,31 @@ public virtual ValueTask NonQueryExecutedAsync( CancellationToken cancellationToken = default) => new(result); - /// - /// Called when a command was canceled. - /// - /// The command. - /// Contextual information about the command and execution. - public virtual void CommandCanceled( - DbCommand command, - CommandEndEventData eventData) + /// + public virtual void CommandCanceled(DbCommand command, CommandEndEventData eventData) { } - /// - /// Called when a command was canceled. - /// - /// The command. - /// Contextual information about the command and execution. - /// A to observe while waiting for the task to complete. - /// A representing the asynchronous operation. - /// If the is canceled. + /// public virtual Task CommandCanceledAsync( DbCommand command, CommandEndEventData eventData, CancellationToken cancellationToken = default) => Task.CompletedTask; - /// - /// Called when execution of a command has failed with an exception. - /// - /// The command. - /// Contextual information about the command and execution. - public virtual void CommandFailed( - DbCommand command, - CommandErrorEventData eventData) + /// + public virtual void CommandFailed(DbCommand command, CommandErrorEventData eventData) { } - /// - /// Called when execution of a command has failed with an exception. - /// - /// The command. - /// Contextual information about the command and execution. - /// A to observe while waiting for the task to complete. - /// A representing the asynchronous operation. - /// If the is canceled. + /// public virtual Task CommandFailedAsync( DbCommand command, CommandErrorEventData eventData, CancellationToken cancellationToken = default) => Task.CompletedTask; - /// - /// Called when execution of a is about to be disposed. - /// - /// The command. - /// Contextual information about the command and reader. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// If is false, the EF will continue as normal. - /// If 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 value passed in. - /// + /// public virtual InterceptionResult DataReaderDisposing( DbCommand command, DataReaderDisposingEventData eventData, diff --git a/src/EFCore.Relational/Diagnostics/DbConnectionInterceptor.cs b/src/EFCore.Relational/Diagnostics/DbConnectionInterceptor.cs index b0786e93323..135e4c01cc4 100644 --- a/src/EFCore.Relational/Diagnostics/DbConnectionInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/DbConnectionInterceptor.cs @@ -12,50 +12,11 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics; /// public abstract class DbConnectionInterceptor : IDbConnectionInterceptor { - /// - /// Called just before EF intends to call . - /// - /// The connection. - /// Contextual information about the connection. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// If is false, the EF will continue as normal. - /// If 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 value passed in. - /// - public virtual InterceptionResult ConnectionOpening( - DbConnection connection, - ConnectionEventData eventData, - InterceptionResult result) + /// + public virtual InterceptionResult ConnectionOpening(DbConnection connection, ConnectionEventData eventData, InterceptionResult result) => result; - /// - /// Called just before EF intends to call . - /// - /// The connection. - /// Contextual information about the connection. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// If is false, the EF will continue as normal. - /// If 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 value passed in. - /// - /// If the is canceled. + /// public virtual ValueTask ConnectionOpeningAsync( DbConnection connection, ConnectionEventData eventData, @@ -63,118 +24,44 @@ public virtual ValueTask ConnectionOpeningAsync( CancellationToken cancellationToken = default) => new(result); - /// - /// Called just after EF has called . - /// - /// The connection. - /// Contextual information about the connection. + /// public virtual void ConnectionOpened(DbConnection connection, ConnectionEndEventData eventData) { } - /// - /// Called just after EF has called . - /// - /// The connection. - /// Contextual information about the connection. - /// A to observe while waiting for the task to complete. - /// A representing the asynchronous operation. - /// If the is canceled. + /// public virtual Task ConnectionOpenedAsync( DbConnection connection, ConnectionEndEventData eventData, CancellationToken cancellationToken = default) => Task.CompletedTask; - /// - /// Called just before EF intends to call . - /// - /// The connection. - /// Contextual information about the connection. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// If is false, the EF will continue as normal. - /// If 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 value passed in. - /// - public virtual InterceptionResult ConnectionClosing( - DbConnection connection, - ConnectionEventData eventData, - InterceptionResult result) + /// + public virtual InterceptionResult ConnectionClosing(DbConnection connection, ConnectionEventData eventData, InterceptionResult result) => result; - /// - /// Called just before EF intends to call in an async context. - /// - /// The connection. - /// Contextual information about the connection. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// If is false, the EF will continue as normal. - /// If 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 value passed in. - /// + /// public virtual ValueTask ConnectionClosingAsync( DbConnection connection, ConnectionEventData eventData, InterceptionResult result) => new(result); - /// - /// Called just after EF has called in an async context. - /// - /// The connection. - /// Contextual information about the connection. - public virtual void ConnectionClosed( - DbConnection connection, - ConnectionEndEventData eventData) + /// + public virtual void ConnectionClosed(DbConnection connection, ConnectionEndEventData eventData) { } - /// - /// Called just after EF has called . - /// - /// The connection. - /// Contextual information about the connection. - /// A representing the asynchronous operation. - public virtual Task ConnectionClosedAsync( - DbConnection connection, - ConnectionEndEventData eventData) + /// + public virtual Task ConnectionClosedAsync(DbConnection connection, ConnectionEndEventData eventData) => Task.CompletedTask; - /// - /// Called when opening of a connection has failed with an exception. - /// - /// The connection. - /// Contextual information about the connection. - public virtual void ConnectionFailed( - DbConnection connection, - ConnectionErrorEventData eventData) + /// + public virtual void ConnectionFailed(DbConnection connection, ConnectionErrorEventData eventData) { } - /// - /// Called when opening of a connection has failed with an exception. - /// - /// The connection. - /// Contextual information about the connection. - /// A to observe while waiting for the task to complete. - /// A representing the asynchronous operation. - /// If the is canceled. + /// public virtual Task ConnectionFailedAsync( DbConnection connection, ConnectionErrorEventData eventData, diff --git a/src/EFCore.Relational/Diagnostics/DbTransactionInterceptor.cs b/src/EFCore.Relational/Diagnostics/DbTransactionInterceptor.cs index 1fa41428e5c..801330c4a95 100644 --- a/src/EFCore.Relational/Diagnostics/DbTransactionInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/DbTransactionInterceptor.cs @@ -14,75 +14,18 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics; /// public abstract class DbTransactionInterceptor : IDbTransactionInterceptor { - /// - /// Called just before EF intends to call . - /// - /// The connection. - /// Contextual information about connection and transaction. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// + /// public virtual InterceptionResult TransactionStarting( DbConnection connection, TransactionStartingEventData eventData, InterceptionResult result) => result; - /// - /// Called immediately after EF calls . - /// - /// - /// This method is still called if an interceptor suppressed creation in . - /// In this case, is the result returned by . - /// - /// The connection. - /// Contextual information about connection and transaction. - /// - /// The result of the call to . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// The result that EF will use. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in. - /// - public virtual DbTransaction TransactionStarted( - DbConnection connection, - TransactionEndEventData eventData, - DbTransaction result) + /// + public virtual DbTransaction TransactionStarted(DbConnection connection, TransactionEndEventData eventData, DbTransaction result) => result; - /// - /// Called just before EF intends to call - /// . - /// - /// The connection. - /// Contextual information about connection and transaction. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// - /// If the is canceled. + /// public virtual ValueTask> TransactionStartingAsync( DbConnection connection, TransactionStartingEventData eventData, @@ -90,27 +33,7 @@ public virtual ValueTask> TransactionStartingA CancellationToken cancellationToken = default) => new(result); - /// - /// Called immediately after EF calls . - /// - /// - /// This method is still called if an interceptor suppressed creation in . - /// In this case, is the result returned by . - /// - /// The connection. - /// Contextual information about connection and transaction. - /// - /// The result of the call to - /// . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// A providing the result that EF will use. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// - /// If the is canceled. + /// public virtual ValueTask TransactionStartedAsync( DbConnection connection, TransactionEndEventData eventData, @@ -118,43 +41,11 @@ public virtual ValueTask TransactionStartedAsync( CancellationToken cancellationToken = default) => new(result); - /// - /// Called immediately after is called. - /// - /// The connection. - /// Contextual information about connection and transaction. - /// - /// The that was passed to . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// The value that will be used as the effective value passed to - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in. - /// - public virtual DbTransaction TransactionUsed( - DbConnection connection, - TransactionEventData eventData, - DbTransaction result) + /// + public virtual DbTransaction TransactionUsed(DbConnection connection, TransactionEventData eventData, DbTransaction result) => result; - /// - /// Called immediately after is called. - /// - /// The connection. - /// Contextual information about connection and transaction. - /// - /// The that was passed to . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// A containing the value that will be used as the effective value passed - /// to - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in, often using - /// - /// If the is canceled. + /// public virtual ValueTask TransactionUsedAsync( DbConnection connection, TransactionEventData eventData, @@ -162,62 +53,19 @@ public virtual ValueTask TransactionUsedAsync( CancellationToken cancellationToken = default) => new(result); - /// - /// Called just before EF intends to call . - /// - /// The transaction. - /// Contextual information about connection and transaction. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// If is false, the EF will continue as normal. - /// If 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 value passed in. - /// + /// public virtual InterceptionResult TransactionCommitting( DbTransaction transaction, TransactionEventData eventData, InterceptionResult result) => result; - /// - /// Called immediately after EF calls . - /// - /// The transaction. - /// Contextual information about connection and transaction. - public virtual void TransactionCommitted( - DbTransaction transaction, - TransactionEndEventData eventData) + /// + public virtual void TransactionCommitted(DbTransaction transaction, TransactionEndEventData eventData) { } - /// - /// Called just before EF intends to call - /// . - /// - /// The transaction. - /// Contextual information about connection and transaction. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// If is false, the EF will continue as normal. - /// If 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 value passed in. - /// - /// If the is canceled. + /// public virtual ValueTask TransactionCommittingAsync( DbTransaction transaction, TransactionEventData eventData, @@ -225,76 +73,26 @@ public virtual ValueTask TransactionCommittingAsync( CancellationToken cancellationToken = default) => new(result); - /// - /// Called immediately after EF calls . - /// - /// The transaction. - /// Contextual information about connection and transaction. - /// A to observe while waiting for the task to complete. - /// A representing the asynchronous operation. - /// If the is canceled. + /// public virtual Task TransactionCommittedAsync( DbTransaction transaction, TransactionEndEventData eventData, CancellationToken cancellationToken = default) => Task.CompletedTask; - /// - /// Called just before EF intends to call . - /// - /// The transaction. - /// Contextual information about connection and transaction. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// If is false, the EF will continue as normal. - /// If 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 value passed in. - /// + /// public virtual InterceptionResult TransactionRollingBack( DbTransaction transaction, TransactionEventData eventData, InterceptionResult result) => result; - /// - /// Called immediately after EF calls . - /// - /// The transaction. - /// Contextual information about connection and transaction. - public virtual void TransactionRolledBack( - DbTransaction transaction, - TransactionEndEventData eventData) + /// + public virtual void TransactionRolledBack(DbTransaction transaction, TransactionEndEventData eventData) { } - /// - /// Called just before EF intends to call - /// . - /// - /// The transaction. - /// Contextual information about connection and transaction. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// If is false, the EF will continue as normal. - /// If 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 value passed in. - /// - /// If the is canceled. + /// public virtual ValueTask TransactionRollingBackAsync( DbTransaction transaction, TransactionEventData eventData, @@ -302,14 +100,7 @@ public virtual ValueTask TransactionRollingBackAsync( CancellationToken cancellationToken = default) => new(result); - /// - /// Called immediately after EF calls . - /// - /// The transaction. - /// Contextual information about connection and transaction. - /// A to observe while waiting for the task to complete. - /// A representing the asynchronous operation. - /// If the is canceled. + /// public virtual Task TransactionRolledBackAsync( DbTransaction transaction, TransactionEndEventData eventData, @@ -324,9 +115,7 @@ public virtual InterceptionResult CreatingSavepoint( => result; /// - public virtual void CreatedSavepoint( - DbTransaction transaction, - TransactionEventData eventData) + public virtual void CreatedSavepoint(DbTransaction transaction, TransactionEventData eventData) { } @@ -353,9 +142,7 @@ public virtual InterceptionResult RollingBackToSavepoint( => result; /// - public virtual void RolledBackToSavepoint( - DbTransaction transaction, - TransactionEventData eventData) + public virtual void RolledBackToSavepoint(DbTransaction transaction, TransactionEventData eventData) { } @@ -382,9 +169,7 @@ public virtual InterceptionResult ReleasingSavepoint( => result; /// - public virtual void ReleasedSavepoint( - DbTransaction transaction, - TransactionEventData eventData) + public virtual void ReleasedSavepoint(DbTransaction transaction, TransactionEventData eventData) { } @@ -403,27 +188,13 @@ public virtual Task ReleasedSavepointAsync( CancellationToken cancellationToken = default) => Task.CompletedTask; - /// - /// Called when use of a has failed with an exception. - /// - /// The transaction. - /// Contextual information about connection and transaction. - public virtual void TransactionFailed( - DbTransaction transaction, - TransactionErrorEventData eventData) + /// + public virtual void TransactionFailed(DbTransaction transaction, TransactionErrorEventData eventData) { } - /// - /// Called when use of a has failed with an exception. - /// - /// The transaction. - /// Contextual information about connection and transaction. - /// A to observe while waiting for the task to complete. - /// A representing the asynchronous operation. - /// If the is canceled. - public virtual Task TransactionFailedAsync( - DbTransaction transaction, + /// + public virtual Task TransactionFailedAsync(DbTransaction transaction, TransactionErrorEventData eventData, CancellationToken cancellationToken = default) => Task.CompletedTask; diff --git a/src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs b/src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs index 6a3d3f50350..dddca4631ad 100644 --- a/src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs @@ -46,9 +46,8 @@ public interface IDbCommandInterceptor : IInterceptor /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - InterceptionResult CommandCreating( - CommandCorrelatedEventData eventData, - InterceptionResult result); + InterceptionResult CommandCreating(CommandCorrelatedEventData eventData, InterceptionResult result) + => result; /// /// Called immediately after EF calls . @@ -67,9 +66,8 @@ InterceptionResult CommandCreating( /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - DbCommand CommandCreated( - CommandEndEventData eventData, - DbCommand result); + DbCommand CommandCreated(CommandEndEventData eventData, DbCommand result) + => result; /// /// Called just before EF intends to call . @@ -89,10 +87,8 @@ DbCommand CommandCreated( /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - InterceptionResult ReaderExecuting( - DbCommand command, - CommandEventData eventData, - InterceptionResult result); + InterceptionResult ReaderExecuting(DbCommand command,CommandEventData eventData, InterceptionResult result) + => result; /// /// Called just before EF intends to call . @@ -112,10 +108,8 @@ InterceptionResult ReaderExecuting( /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - InterceptionResult ScalarExecuting( - DbCommand command, - CommandEventData eventData, - InterceptionResult result); + InterceptionResult ScalarExecuting(DbCommand command, CommandEventData eventData, InterceptionResult result) + => result; /// /// Called just before EF intends to call . @@ -135,10 +129,8 @@ InterceptionResult ScalarExecuting( /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - InterceptionResult NonQueryExecuting( - DbCommand command, - CommandEventData eventData, - InterceptionResult result); + InterceptionResult NonQueryExecuting(DbCommand command, CommandEventData eventData, InterceptionResult result) + => result; /// /// Called just before EF intends to call . @@ -164,7 +156,8 @@ ValueTask> ReaderExecutingAsync( DbCommand command, CommandEventData eventData, InterceptionResult result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called just before EF intends to call . @@ -190,7 +183,8 @@ ValueTask> ScalarExecutingAsync( DbCommand command, CommandEventData eventData, InterceptionResult result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called just before EF intends to call . @@ -216,7 +210,8 @@ ValueTask> NonQueryExecutingAsync( DbCommand command, CommandEventData eventData, InterceptionResult result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called immediately after EF calls . @@ -236,10 +231,8 @@ ValueTask> NonQueryExecutingAsync( /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - DbDataReader ReaderExecuted( - DbCommand command, - CommandExecutedEventData eventData, - DbDataReader result); + DbDataReader ReaderExecuted(DbCommand command, CommandExecutedEventData eventData, DbDataReader result) + => result; /// /// Called immediately after EF calls . @@ -259,10 +252,8 @@ DbDataReader ReaderExecuted( /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - object? ScalarExecuted( - DbCommand command, - CommandExecutedEventData eventData, - object? result); + object? ScalarExecuted(DbCommand command, CommandExecutedEventData eventData, object? result) + => result; /// /// Called immediately after EF calls . @@ -282,10 +273,8 @@ DbDataReader ReaderExecuted( /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - int NonQueryExecuted( - DbCommand command, - CommandExecutedEventData eventData, - int result); + int NonQueryExecuted(DbCommand command, CommandExecutedEventData eventData, int result) + => result; /// /// Called immediately after EF calls . @@ -311,7 +300,8 @@ ValueTask ReaderExecutedAsync( DbCommand command, CommandExecutedEventData eventData, DbDataReader result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called immediately after EF calls . @@ -337,7 +327,8 @@ ValueTask ReaderExecutedAsync( DbCommand command, CommandExecutedEventData eventData, object? result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called immediately after EF calls . @@ -363,16 +354,17 @@ ValueTask NonQueryExecutedAsync( DbCommand command, CommandExecutedEventData eventData, int result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called when a command was canceled. /// /// The command. /// Contextual information about the command and execution. - void CommandCanceled( - DbCommand command, - CommandEndEventData eventData); + void CommandCanceled(DbCommand command, CommandEndEventData eventData) + { + } /// /// Called when a command was canceled. @@ -382,19 +374,17 @@ void CommandCanceled( /// A to observe while waiting for the task to complete. /// A representing the asynchronous operation. /// If the is canceled. - Task CommandCanceledAsync( - DbCommand command, - CommandEndEventData eventData, - CancellationToken cancellationToken = default); + Task CommandCanceledAsync(DbCommand command, CommandEndEventData eventData, CancellationToken cancellationToken = default) + => Task.CompletedTask; /// /// Called when execution of a command has failed with an exception. /// /// The command. /// Contextual information about the command and execution. - void CommandFailed( - DbCommand command, - CommandErrorEventData eventData); + void CommandFailed(DbCommand command, CommandErrorEventData eventData) + { + } /// /// Called when execution of a command has failed with an exception. @@ -404,10 +394,8 @@ void CommandFailed( /// A to observe while waiting for the task to complete. /// A representing the asynchronous operation. /// If the is canceled. - Task CommandFailedAsync( - DbCommand command, - CommandErrorEventData eventData, - CancellationToken cancellationToken = default); + Task CommandFailedAsync(DbCommand command, CommandErrorEventData eventData, CancellationToken cancellationToken = default) + => Task.CompletedTask; /// /// Called when execution of a is about to be disposed. @@ -427,8 +415,6 @@ Task CommandFailedAsync( /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. /// - InterceptionResult DataReaderDisposing( - DbCommand command, - DataReaderDisposingEventData eventData, - InterceptionResult result); + InterceptionResult DataReaderDisposing(DbCommand command, DataReaderDisposingEventData eventData, InterceptionResult result) + => result; } diff --git a/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs b/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs index 684f4e3825e..a036cc633d6 100644 --- a/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs @@ -47,10 +47,8 @@ public interface IDbConnectionInterceptor : IInterceptor /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. /// - InterceptionResult ConnectionOpening( - DbConnection connection, - ConnectionEventData eventData, - InterceptionResult result); + InterceptionResult ConnectionOpening(DbConnection connection, ConnectionEventData eventData, InterceptionResult result) + => result; /// /// Called just before EF intends to call . @@ -76,16 +74,17 @@ ValueTask ConnectionOpeningAsync( DbConnection connection, ConnectionEventData eventData, InterceptionResult result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called just after EF has called . /// /// The connection. /// Contextual information about the connection. - void ConnectionOpened( - DbConnection connection, - ConnectionEndEventData eventData); + void ConnectionOpened(DbConnection connection, ConnectionEndEventData eventData) + { + } /// /// Called just after EF has called . @@ -95,10 +94,8 @@ void ConnectionOpened( /// A to observe while waiting for the task to complete. /// A representing the asynchronous operation. /// If the is canceled. - Task ConnectionOpenedAsync( - DbConnection connection, - ConnectionEndEventData eventData, - CancellationToken cancellationToken = default); + Task ConnectionOpenedAsync(DbConnection connection, ConnectionEndEventData eventData, CancellationToken cancellationToken = default) + => Task.CompletedTask; /// /// Called just before EF intends to call . @@ -118,10 +115,8 @@ Task ConnectionOpenedAsync( /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. /// - InterceptionResult ConnectionClosing( - DbConnection connection, - ConnectionEventData eventData, - InterceptionResult result); + InterceptionResult ConnectionClosing(DbConnection connection, ConnectionEventData eventData, InterceptionResult result) + => result; /// /// Called just before EF intends to call in an async context. @@ -141,19 +136,17 @@ InterceptionResult ConnectionClosing( /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. /// - ValueTask ConnectionClosingAsync( - DbConnection connection, - ConnectionEventData eventData, - InterceptionResult result); + ValueTask ConnectionClosingAsync(DbConnection connection, ConnectionEventData eventData, InterceptionResult result) + => new(result); /// /// Called just after EF has called in an async context. /// /// The connection. /// Contextual information about the connection. - void ConnectionClosed( - DbConnection connection, - ConnectionEndEventData eventData); + void ConnectionClosed(DbConnection connection, ConnectionEndEventData eventData) + { + } /// /// Called just after EF has called . @@ -161,18 +154,17 @@ void ConnectionClosed( /// The connection. /// Contextual information about the connection. /// A representing the asynchronous operation. - Task ConnectionClosedAsync( - DbConnection connection, - ConnectionEndEventData eventData); + Task ConnectionClosedAsync(DbConnection connection, ConnectionEndEventData eventData) + => Task.CompletedTask; /// /// Called when closing of a connection has failed with an exception. /// /// The connection. /// Contextual information about the connection. - void ConnectionFailed( - DbConnection connection, - ConnectionErrorEventData eventData); + void ConnectionFailed(DbConnection connection, ConnectionErrorEventData eventData) + { + } /// /// Called when closing of a connection has failed with an exception. @@ -182,8 +174,6 @@ void ConnectionFailed( /// A to observe while waiting for the task to complete. /// A representing the asynchronous operation. /// If the is canceled. - Task ConnectionFailedAsync( - DbConnection connection, - ConnectionErrorEventData eventData, - CancellationToken cancellationToken = default); + Task ConnectionFailedAsync(DbConnection connection, ConnectionErrorEventData eventData, CancellationToken cancellationToken = default) + => Task.CompletedTask; } diff --git a/src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs b/src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs index 8a6e4db77fa..dc579ba8f6e 100644 --- a/src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs @@ -52,7 +52,8 @@ public interface IDbTransactionInterceptor : IInterceptor InterceptionResult TransactionStarting( DbConnection connection, TransactionStartingEventData eventData, - InterceptionResult result); + InterceptionResult result) + => result; /// /// Called immediately after EF calls . @@ -72,10 +73,8 @@ InterceptionResult TransactionStarting( /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - DbTransaction TransactionStarted( - DbConnection connection, - TransactionEndEventData eventData, - DbTransaction result); + DbTransaction TransactionStarted(DbConnection connection, TransactionEndEventData eventData, DbTransaction result) + => result; /// /// Called just before EF intends to call @@ -102,7 +101,8 @@ ValueTask> TransactionStartingAsync( DbConnection connection, TransactionStartingEventData eventData, InterceptionResult result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called immediately after EF calls . @@ -129,7 +129,8 @@ ValueTask TransactionStartedAsync( DbConnection connection, TransactionEndEventData eventData, DbTransaction result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called immediately after is called. @@ -145,10 +146,8 @@ ValueTask TransactionStartedAsync( /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - DbTransaction TransactionUsed( - DbConnection connection, - TransactionEventData eventData, - DbTransaction result); + DbTransaction TransactionUsed(DbConnection connection, TransactionEventData eventData, DbTransaction result) + => result; /// /// Called immediately after is called. @@ -171,7 +170,8 @@ ValueTask TransactionUsedAsync( DbConnection connection, TransactionEventData eventData, DbTransaction result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called just before EF intends to call . @@ -191,19 +191,17 @@ ValueTask TransactionUsedAsync( /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. /// - InterceptionResult TransactionCommitting( - DbTransaction transaction, - TransactionEventData eventData, - InterceptionResult result); + InterceptionResult TransactionCommitting(DbTransaction transaction, TransactionEventData eventData, InterceptionResult result) + => result; /// /// Called immediately after EF calls . /// /// The transaction. /// Contextual information about connection and transaction. - void TransactionCommitted( - DbTransaction transaction, - TransactionEndEventData eventData); + void TransactionCommitted(DbTransaction transaction, TransactionEndEventData eventData) + { + } /// /// Called just before EF intends to call @@ -230,7 +228,8 @@ ValueTask TransactionCommittingAsync( DbTransaction transaction, TransactionEventData eventData, InterceptionResult result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called immediately after EF calls . @@ -243,7 +242,8 @@ ValueTask TransactionCommittingAsync( Task TransactionCommittedAsync( DbTransaction transaction, TransactionEndEventData eventData, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => Task.CompletedTask; /// /// Called just before EF intends to call . @@ -263,19 +263,17 @@ Task TransactionCommittedAsync( /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. /// - InterceptionResult TransactionRollingBack( - DbTransaction transaction, - TransactionEventData eventData, - InterceptionResult result); + InterceptionResult TransactionRollingBack(DbTransaction transaction, TransactionEventData eventData, InterceptionResult result) + => result; /// /// Called immediately after EF calls . /// /// The transaction. /// Contextual information about connection and transaction. - void TransactionRolledBack( - DbTransaction transaction, - TransactionEndEventData eventData); + void TransactionRolledBack(DbTransaction transaction, TransactionEndEventData eventData) + { + } /// /// Called just before EF intends to call @@ -302,7 +300,8 @@ ValueTask TransactionRollingBackAsync( DbTransaction transaction, TransactionEventData eventData, InterceptionResult result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called immediately after EF calls . @@ -315,7 +314,8 @@ ValueTask TransactionRollingBackAsync( Task TransactionRolledBackAsync( DbTransaction transaction, TransactionEndEventData eventData, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => Task.CompletedTask; /// /// Called just before EF intends to create a transaction savepoint. @@ -335,19 +335,17 @@ Task TransactionRolledBackAsync( /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. /// - InterceptionResult CreatingSavepoint( - DbTransaction transaction, - TransactionEventData eventData, - InterceptionResult result); + InterceptionResult CreatingSavepoint(DbTransaction transaction, TransactionEventData eventData, InterceptionResult result) + => result; /// /// Called immediately after EF creates a transaction savepoint. /// /// The transaction. /// Contextual information about connection and transaction. - void CreatedSavepoint( - DbTransaction transaction, - TransactionEventData eventData); + void CreatedSavepoint(DbTransaction transaction, TransactionEventData eventData) + { + } /// /// Called just before EF intends to create a transaction savepoint. @@ -373,7 +371,8 @@ ValueTask CreatingSavepointAsync( DbTransaction transaction, TransactionEventData eventData, InterceptionResult result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called immediately after EF calls . @@ -386,7 +385,8 @@ ValueTask CreatingSavepointAsync( Task CreatedSavepointAsync( DbTransaction transaction, TransactionEventData eventData, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => Task.CompletedTask; /// /// Called just before EF intends to roll back to a transaction savepoint. @@ -409,16 +409,17 @@ Task CreatedSavepointAsync( InterceptionResult RollingBackToSavepoint( DbTransaction transaction, TransactionEventData eventData, - InterceptionResult result); + InterceptionResult result) + => result; /// /// Called immediately after EF rolls back to a transaction savepoint. /// /// The transaction. /// Contextual information about connection and transaction. - void RolledBackToSavepoint( - DbTransaction transaction, - TransactionEventData eventData); + void RolledBackToSavepoint(DbTransaction transaction, TransactionEventData eventData) + { + } /// /// Called just before EF intends to roll back to a transaction savepoint. @@ -444,7 +445,8 @@ ValueTask RollingBackToSavepointAsync( DbTransaction transaction, TransactionEventData eventData, InterceptionResult result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called immediately after EF rolls back to a transaction savepoint. @@ -457,7 +459,8 @@ ValueTask RollingBackToSavepointAsync( Task RolledBackToSavepointAsync( DbTransaction transaction, TransactionEventData eventData, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => Task.CompletedTask; /// /// Called just before EF intends to release a transaction savepoint. @@ -477,19 +480,17 @@ Task RolledBackToSavepointAsync( /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. /// - InterceptionResult ReleasingSavepoint( - DbTransaction transaction, - TransactionEventData eventData, - InterceptionResult result); + InterceptionResult ReleasingSavepoint(DbTransaction transaction, TransactionEventData eventData, InterceptionResult result) + => result; /// /// Called immediately after EF releases a transaction savepoint. /// /// The transaction. /// Contextual information about connection and transaction. - void ReleasedSavepoint( - DbTransaction transaction, - TransactionEventData eventData); + void ReleasedSavepoint(DbTransaction transaction, TransactionEventData eventData) + { + } /// /// Called just before EF intends to release a transaction savepoint. @@ -515,7 +516,8 @@ ValueTask ReleasingSavepointAsync( DbTransaction transaction, TransactionEventData eventData, InterceptionResult result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called immediately after EF releases a transaction savepoint. @@ -528,16 +530,17 @@ ValueTask ReleasingSavepointAsync( Task ReleasedSavepointAsync( DbTransaction transaction, TransactionEventData eventData, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => Task.CompletedTask; /// /// Called when use of a has failed with an exception. /// /// The transaction. /// Contextual information about connection and transaction. - void TransactionFailed( - DbTransaction transaction, - TransactionErrorEventData eventData); + void TransactionFailed(DbTransaction transaction, TransactionErrorEventData eventData) + { + } /// /// Called when use of a has failed with an exception. @@ -550,5 +553,6 @@ void TransactionFailed( Task TransactionFailedAsync( DbTransaction transaction, TransactionErrorEventData eventData, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => Task.CompletedTask; } diff --git a/src/EFCore/Diagnostics/ISaveChangesInterceptor.cs b/src/EFCore/Diagnostics/ISaveChangesInterceptor.cs index a9ac93030d2..cf9215e8e89 100644 --- a/src/EFCore/Diagnostics/ISaveChangesInterceptor.cs +++ b/src/EFCore/Diagnostics/ISaveChangesInterceptor.cs @@ -46,9 +46,8 @@ public interface ISaveChangesInterceptor : IInterceptor /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - InterceptionResult SavingChanges( - DbContextEventData eventData, - InterceptionResult result); + InterceptionResult SavingChanges(DbContextEventData eventData, InterceptionResult result) + => result; /// /// Called at the end of . @@ -67,16 +66,16 @@ InterceptionResult SavingChanges( /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - int SavedChanges( - SaveChangesCompletedEventData eventData, - int result); + int SavedChanges(SaveChangesCompletedEventData eventData, int result) + => result; /// /// Called when an exception has been thrown in . /// /// Contextual information about the failure. - void SaveChangesFailed( - DbContextErrorEventData eventData); + void SaveChangesFailed(DbContextErrorEventData eventData) + { + } /// /// Called at the start of . @@ -100,7 +99,8 @@ void SaveChangesFailed( ValueTask> SavingChangesAsync( DbContextEventData eventData, InterceptionResult result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called at the end of . @@ -124,7 +124,8 @@ ValueTask> SavingChangesAsync( ValueTask SavedChangesAsync( SaveChangesCompletedEventData eventData, int result, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default) + => new(result); /// /// Called when an exception has been thrown in . @@ -133,15 +134,16 @@ ValueTask SavedChangesAsync( /// A to observe while waiting for the task to complete. /// A representing the asynchronous operation. /// If the is canceled. - Task SaveChangesFailedAsync( - DbContextErrorEventData eventData, - CancellationToken cancellationToken = default); + Task SaveChangesFailedAsync(DbContextErrorEventData eventData, CancellationToken cancellationToken = default) + => Task.CompletedTask; /// /// Called when was canceled. /// /// Contextual information about the failure. - void SaveChangesCanceled(DbContextEventData eventData); + void SaveChangesCanceled(DbContextEventData eventData) + { + } /// /// Called when was canceled. @@ -150,5 +152,6 @@ Task SaveChangesFailedAsync( /// A to observe while waiting for the task to complete. /// A representing the asynchronous operation. /// If the is canceled. - Task SaveChangesCanceledAsync(DbContextEventData eventData, CancellationToken cancellationToken = default); + Task SaveChangesCanceledAsync(DbContextEventData eventData, CancellationToken cancellationToken = default) + => Task.CompletedTask; } diff --git a/src/EFCore/Diagnostics/SaveChangesInterceptor.cs b/src/EFCore/Diagnostics/SaveChangesInterceptor.cs index e190f9045b8..b190b96539c 100644 --- a/src/EFCore/Diagnostics/SaveChangesInterceptor.cs +++ b/src/EFCore/Diagnostics/SaveChangesInterceptor.cs @@ -12,133 +12,45 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics; /// public abstract class SaveChangesInterceptor : ISaveChangesInterceptor { - /// - /// Called at the start of . - /// - /// Contextual information about the being used. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in. - /// + /// public virtual InterceptionResult SavingChanges(DbContextEventData eventData, InterceptionResult result) => result; - /// - /// Called at the end of . - /// - /// - /// This method is still called if an interceptor suppressed creation of a command in - /// . - /// In this case, is the result returned by . - /// - /// Contextual information about the being used. - /// - /// The result of the call to . - /// This value is typically used as the return value for the implementation of this method. - /// - /// - /// The result that EF will use. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in. - /// + /// public virtual int SavedChanges(SaveChangesCompletedEventData eventData, int result) => result; - /// - /// Called when an exception has been thrown in . - /// - /// Contextual information about the failure. + /// public virtual void SaveChangesFailed(DbContextErrorEventData eventData) { } - /// - /// Called when was canceled. - /// - /// Contextual information about the failure. + /// public virtual void SaveChangesCanceled(DbContextEventData eventData) { } - /// - /// Called at the start of . - /// - /// Contextual information about the being used. - /// - /// Represents the current result if one exists. - /// This value will have set to if some previous - /// interceptor suppressed execution by calling . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in. - /// - /// If the is canceled. + /// public virtual ValueTask> SavingChangesAsync( DbContextEventData eventData, InterceptionResult result, CancellationToken cancellationToken = default) => new(result); - /// - /// Called at the end of . - /// - /// - /// This method is still called if an interceptor suppressed creation of a command in - /// . - /// In this case, is the result returned by . - /// - /// Contextual information about the being used. - /// - /// The result of the call to . - /// This value is typically used as the return value for the implementation of this method. - /// - /// A to observe while waiting for the task to complete. - /// - /// The result that EF will use. - /// A normal implementation of this method for any interceptor that is not attempting to change the result - /// is to return the value passed in. - /// - /// If the is canceled. + /// public virtual ValueTask SavedChangesAsync( SaveChangesCompletedEventData eventData, int result, CancellationToken cancellationToken = default) => new(result); - /// - /// Called when an exception has been thrown in . - /// - /// Contextual information about the failure. - /// A to observe while waiting for the task to complete. - /// A representing the asynchronous operation. - /// If the is canceled. + /// public virtual Task SaveChangesFailedAsync( DbContextErrorEventData eventData, CancellationToken cancellationToken = default) => Task.CompletedTask; - /// - /// Called when was canceled. - /// - /// Contextual information about the cancellation. - /// A to observe while waiting for the task to complete. - /// A representing the asynchronous operation. - /// If the is canceled. + /// public virtual Task SaveChangesCanceledAsync( DbContextEventData eventData, CancellationToken cancellationToken = default)