298
CHAPTER 7 | Implement resilient applications
// Achieving atomicity between original Catalog database operation and the
// IntegrationEventLog thanks to a local transaction
await _catalogIntegrationEventService.
SaveEventAndCatalogContextChangesAsync
(
priceChangedEvent);
// Publish through the Event Bus and mark the saved event as published
await _catalogIntegrationEventService.
PublishThroughEventBusAsync
(
priceChangedEvent);
}
// Just save the updated product because the Product's Price hasn't changed.
else
{
await _catalogContext.
SaveChangesAsync
();
}
}
The first
DbContext
is
_catalogContext
and the second
DbContext
is within the
_catalogIntegrationEventService
object. The Commit action is performed across all
DbContext
objects using an EF execution strategy.
To achieve this multiple
DbContext
commit, the
SaveEventAndCatalogContextChangesAsync
uses a
ResilientTransaction
class, as shown in the following code:
Dostları ilə paylaş: