public async Task SaveEventsAndUsersContextChangesAsync(params IntegrationEvent[] events) { _logger.LogInformation("----- (Users.API) UsersIntegrationEventService - Saving changes and integrationEvents: {IntegrationEventsIds}", string.Join(", ", events.Select(evt => evt.Id))); //Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction(): //See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency await ResilientTransaction.New(_usersContext).ExecuteAsync(async() => { // Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction await _usersContext.SaveChangesAsync(); await _eventLogService.SaveEventsAsync(events, _usersContext.Database.CurrentTransaction); }); }