Table of Contents

Class ApplicationSaveChangesInterceptor

Namespace
ProjectTemplate.Infrastructure.Data
Assembly
ProjectTemplate.Infrastructure.dll

Invokes the application save pipeline from the EF Core SaveChanges interception lifecycle.

public sealed class ApplicationSaveChangesInterceptor : SaveChangesInterceptor, ISaveChangesInterceptor, IInterceptor
Inheritance
ApplicationSaveChangesInterceptor
Implements
Inherited Members

Constructors

ApplicationSaveChangesInterceptor(IApplicationSaveChangesPipeline)

Initializes a new instance of the ApplicationSaveChangesInterceptor class.

public ApplicationSaveChangesInterceptor(IApplicationSaveChangesPipeline saveChangesPipeline)

Parameters

saveChangesPipeline IApplicationSaveChangesPipeline

The application-owned save pipeline.

Methods

SavedChanges(SaveChangesCompletedEventData, int)

Called at the end of .

public override int SavedChanges(SaveChangesCompletedEventData eventData, int result)

Parameters

eventData SaveChangesCompletedEventData

Contextual information about the DbContext being used.

result int

The result of the call to . This value is typically used as the return value for the implementation of this method.

Returns

int

The result that EF will use. An implementation of this method for any interceptor that is not attempting to change the result is to return the result value passed in.

Remarks

This method is still called if an interceptor suppressed creation of a command in SavingChanges(DbContextEventData, InterceptionResult<int>). In this case, result is the result returned by SavingChanges(DbContextEventData, InterceptionResult<int>).

SavedChangesAsync(SaveChangesCompletedEventData, int, CancellationToken)

Called at the end of .

public override ValueTask<int> SavedChangesAsync(SaveChangesCompletedEventData eventData, int result, CancellationToken cancellationToken = default)

Parameters

eventData SaveChangesCompletedEventData

Contextual information about the DbContext being used.

result int

The result of the call to . This value is typically used as the return value for the implementation of this method.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

ValueTask<int>

The result that EF will use. An implementation of this method for any interceptor that is not attempting to change the result is to return the result value passed in.

Remarks

This method is still called if an interceptor suppressed creation of a command in SavingChangesAsync(DbContextEventData, InterceptionResult<int>, CancellationToken). In this case, result is the result returned by SavingChangesAsync(DbContextEventData, InterceptionResult<int>, CancellationToken).

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

SavingChanges(DbContextEventData, InterceptionResult<int>)

Called at the start of .

public override InterceptionResult<int> SavingChanges(DbContextEventData eventData, InterceptionResult<int> result)

Parameters

eventData DbContextEventData

Contextual information about the DbContext being used.

result InterceptionResult<int>

Represents the current result if one exists. This value will have HasResult set to true if some previous interceptor suppressed execution by calling SuppressWithResult(TResult). This value is typically used as the return value for the implementation of this method.

Returns

InterceptionResult<int>

If HasResult is false, the EF will continue as normal. If HasResult is true, then EF will suppress the operation it was about to perform and use Result instead. An implementation of this method for any interceptor that is not attempting to change the result is to return the result value passed in.

SavingChangesAsync(DbContextEventData, InterceptionResult<int>, CancellationToken)

Called at the start of .

public override ValueTask<InterceptionResult<int>> SavingChangesAsync(DbContextEventData eventData, InterceptionResult<int> result, CancellationToken cancellationToken = default)

Parameters

eventData DbContextEventData

Contextual information about the DbContext being used.

result InterceptionResult<int>

Represents the current result if one exists. This value will have HasResult set to true if some previous interceptor suppressed execution by calling SuppressWithResult(TResult). This value is typically used as the return value for the implementation of this method.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

ValueTask<InterceptionResult<int>>

If HasResult is false, the EF will continue as normal. If HasResult is true, then EF will suppress the operation it was about to perform and use Result instead. An implementation of this method for any interceptor that is not attempting to change the result is to return the result value passed in.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.