Catalog. Fixed async/await misuses
This commit is contained in:
parent
0742f941fb
commit
4e90b3f688
@ -18,11 +18,11 @@
|
|||||||
|
|
||||||
public class CatalogContextSeed
|
public class CatalogContextSeed
|
||||||
{
|
{
|
||||||
public async Task SeedAsync(CatalogContext context,IHostingEnvironment env,IOptions<CatalogSettings> settings,ILogger<CatalogContextSeed> logger)
|
public Task SeedAsync(CatalogContext context,IHostingEnvironment env,IOptions<CatalogSettings> settings,ILogger<CatalogContextSeed> logger)
|
||||||
{
|
{
|
||||||
var policy = CreatePolicy(logger, nameof(CatalogContextSeed));
|
var policy = CreatePolicy(logger, nameof(CatalogContextSeed));
|
||||||
|
|
||||||
await policy.ExecuteAsync(async () =>
|
return policy.ExecuteAsync(async () =>
|
||||||
{
|
{
|
||||||
var useCustomizationData = settings.Value.UseCustomizationData;
|
var useCustomizationData = settings.Value.UseCustomizationData;
|
||||||
var contentRootPath = env.ContentRootPath;
|
var contentRootPath = env.ContentRootPath;
|
||||||
|
@ -27,18 +27,18 @@ namespace Catalog.API.IntegrationEvents
|
|||||||
_eventLogService = _integrationEventLogServiceFactory(_catalogContext.Database.GetDbConnection());
|
_eventLogService = _integrationEventLogServiceFactory(_catalogContext.Database.GetDbConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PublishThroughEventBusAsync(IntegrationEvent evt)
|
public Task PublishThroughEventBusAsync(IntegrationEvent evt)
|
||||||
{
|
{
|
||||||
_eventBus.Publish(evt);
|
_eventBus.Publish(evt);
|
||||||
|
|
||||||
await _eventLogService.MarkEventAsPublishedAsync(evt);
|
return _eventLogService.MarkEventAsPublishedAsync(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt)
|
public Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt)
|
||||||
{
|
{
|
||||||
//Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction():
|
//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
|
//See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
|
||||||
await ResilientTransaction.New(_catalogContext)
|
return ResilientTransaction.New(_catalogContext)
|
||||||
.ExecuteAsync(async () => {
|
.ExecuteAsync(async () => {
|
||||||
// Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction
|
// Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction
|
||||||
await _catalogContext.SaveChangesAsync();
|
await _catalogContext.SaveChangesAsync();
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
foreach (var orderStockItem in command.OrderStockItems)
|
foreach (var orderStockItem in command.OrderStockItems)
|
||||||
{
|
{
|
||||||
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
|
var catalogItem = await _catalogContext.CatalogItems.FindAsync(orderStockItem.ProductId);
|
||||||
var hasStock = catalogItem.AvailableStock >= orderStockItem.Units;
|
var hasStock = catalogItem.AvailableStock >= orderStockItem.Units;
|
||||||
var confirmedOrderStockItem = new ConfirmedOrderStockItem(catalogItem.Id, hasStock);
|
var confirmedOrderStockItem = new ConfirmedOrderStockItem(catalogItem.Id, hasStock);
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
_catalogContext = catalogContext;
|
_catalogContext = catalogContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Handle(OrderStatusChangedToPaidIntegrationEvent command)
|
public Task Handle(OrderStatusChangedToPaidIntegrationEvent command)
|
||||||
{
|
{
|
||||||
//we're not blocking stock/inventory
|
//we're not blocking stock/inventory
|
||||||
foreach (var orderStockItem in command.OrderStockItems)
|
foreach (var orderStockItem in command.OrderStockItems)
|
||||||
@ -25,7 +25,7 @@
|
|||||||
catalogItem.RemoveStock(orderStockItem.Units);
|
catalogItem.RemoveStock(orderStockItem.Units);
|
||||||
}
|
}
|
||||||
|
|
||||||
await _catalogContext.SaveChangesAsync();
|
return _catalogContext.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user