|
|
@ -52,7 +52,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure |
|
|
|
modelBuilder.ApplyConfiguration(new BuyerEntityTypeConfiguration()); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<bool> SaveEntitiesAsync(CancellationToken cancellationToken = default(CancellationToken)) |
|
|
|
public override async Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
// Dispatch Domain Events collection.
|
|
|
|
// Choices:
|
|
|
@ -64,9 +64,22 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure |
|
|
|
|
|
|
|
// After executing this line all the changes (from the Command Handler and Domain Event Handlers)
|
|
|
|
// performed through the DbContext will be committed
|
|
|
|
var result = await base.SaveChangesAsync(cancellationToken); |
|
|
|
return await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
public override int SaveChanges(bool acceptAllChangesOnSuccess) |
|
|
|
{ |
|
|
|
// 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.
|
|
|
|
_mediator.DispatchDomainEventsAsync(this).Wait(); |
|
|
|
|
|
|
|
// After executing this line all the changes (from the Command Handler and Domain Event Handlers)
|
|
|
|
// performed through the DbContext will be committed
|
|
|
|
return base.SaveChanges(acceptAllChangesOnSuccess); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<IDbContextTransaction> BeginTransactionAsync() |
|
|
|