Catalog. Fixed async/await misuses

This commit is contained in:
Marusyk 2018-03-29 18:03:13 +03:00
parent 0742f941fb
commit 4e90b3f688
4 changed files with 9 additions and 9 deletions

View File

@ -18,11 +18,11 @@
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));
await policy.ExecuteAsync(async () =>
return policy.ExecuteAsync(async () =>
{
var useCustomizationData = settings.Value.UseCustomizationData;
var contentRootPath = env.ContentRootPath;

View File

@ -27,18 +27,18 @@ namespace Catalog.API.IntegrationEvents
_eventLogService = _integrationEventLogServiceFactory(_catalogContext.Database.GetDbConnection());
}
public async Task PublishThroughEventBusAsync(IntegrationEvent evt)
public Task PublishThroughEventBusAsync(IntegrationEvent 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():
//See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
await ResilientTransaction.New(_catalogContext)
return ResilientTransaction.New(_catalogContext)
.ExecuteAsync(async () => {
// Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction
await _catalogContext.SaveChangesAsync();

View File

@ -28,7 +28,7 @@
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 confirmedOrderStockItem = new ConfirmedOrderStockItem(catalogItem.Id, hasStock);

View File

@ -15,7 +15,7 @@
_catalogContext = catalogContext;
}
public async Task Handle(OrderStatusChangedToPaidIntegrationEvent command)
public Task Handle(OrderStatusChangedToPaidIntegrationEvent command)
{
//we're not blocking stock/inventory
foreach (var orderStockItem in command.OrderStockItems)
@ -25,7 +25,7 @@
catalogItem.RemoveStock(orderStockItem.Units);
}
await _catalogContext.SaveChangesAsync();
return _catalogContext.SaveChangesAsync();
}
}
}