Updated OrderingIntegrationEvent svc
This commit is contained in:
parent
db35a5c369
commit
9adda02b18
@ -9,6 +9,7 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
|
|||||||
using System;
|
using System;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Ordering.API.Application.IntegrationEvents
|
namespace Ordering.API.Application.IntegrationEvents
|
||||||
@ -35,15 +36,21 @@ namespace Ordering.API.Application.IntegrationEvents
|
|||||||
|
|
||||||
public async Task PublishThroughEventBusAsync(IntegrationEvent evt)
|
public async Task PublishThroughEventBusAsync(IntegrationEvent evt)
|
||||||
{
|
{
|
||||||
await SaveEventAndOrderingContextChangesAsync(evt);
|
await SaveEventAsync(evt);
|
||||||
_eventBus.Publish(evt);
|
_eventBus.Publish(evt);
|
||||||
await _eventLogService.MarkEventAsPublishedAsync(evt);
|
await _eventLogService.MarkEventAsPublishedAsync(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SaveEventAndOrderingContextChangesAsync(IntegrationEvent evt)
|
private async Task SaveEventAsync(IntegrationEvent evt)
|
||||||
{
|
{
|
||||||
await _orderingContext.SaveChangesAsync();
|
var strategy = _orderingContext.Database.CreateExecutionStrategy();
|
||||||
await _eventLogContext.SaveChangesAsync();
|
await strategy.ExecuteAsync(async () =>
|
||||||
|
{
|
||||||
|
await _orderingContext.BeginTransactionAsync();
|
||||||
|
await _eventLogService.SaveEventAsync(evt, _orderingContext.GetCurrentTransaction.GetDbTransaction());
|
||||||
|
await _orderingContext.CommitTransactionAsync();
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
|||||||
|
|
||||||
private OrderingContext(DbContextOptions<OrderingContext> options) : base (options) { }
|
private OrderingContext(DbContextOptions<OrderingContext> options) : base (options) { }
|
||||||
|
|
||||||
|
public IDbContextTransaction GetCurrentTransaction => _currentTransaction;
|
||||||
|
|
||||||
public OrderingContext(DbContextOptions<OrderingContext> options, IMediator mediator) : base(options)
|
public OrderingContext(DbContextOptions<OrderingContext> options, IMediator mediator) : base(options)
|
||||||
{
|
{
|
||||||
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user