You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the OrderingContext class there is the following method:
publicasyncTask<bool>SaveEntitiesAsync(CancellationTokencancellationToken=default){// Dispatch Domain Events collection. // Choices:// A) Right BEFORE committing data (EF SaveChanges) into the DB will make a single transaction including // side effects from the domain event handlers which are using the same DbContext with "InstancePerLifetimeScope" or "scoped" lifetime// B) Right AFTER committing data (EF SaveChanges) into the DB will make multiple transactions. // You will need to handle eventual consistency and compensatory actions in case of failures in any of the Handlers. await_mediator.DispatchDomainEventsAsync(this);// After executing this line all the changes (from the Command Handler and Domain Event Handlers) // performed through the DbContext will be committed_=awaitbase.SaveChangesAsync(cancellationToken);returntrue;}
I'm wondering if the explanation in the comments of this method is correct, given that the commands are handled through a PipelineBehavior TransactionBehavior, which has the following Handle method:
And, as explained in the EF Core docs, using the BeginTransactionAsync method makes that any subsequent call to SaveChangesAsync becomes part of the same transaction.
So, in this situation, it wouldn't matter whether await _mediator.DispatchDomainEventsAsync(this); was called before or after await base.SaveChangesAsync(cancellationToken);, right? Or what am I misunderstanding / missing?
The text was updated successfully, but these errors were encountered:
In the
OrderingContext
class there is the following method:I'm wondering if the explanation in the comments of this method is correct, given that the commands are handled through a PipelineBehavior
TransactionBehavior
, which has the followingHandle
method:And, as explained in the EF Core docs, using the
BeginTransactionAsync
method makes that any subsequent call toSaveChangesAsync
becomes part of the same transaction.So, in this situation, it wouldn't matter whether
await _mediator.DispatchDomainEventsAsync(this);
was called before or afterawait base.SaveChangesAsync(cancellationToken);
, right? Or what am I misunderstanding / missing?The text was updated successfully, but these errors were encountered: