Browse Source

Revert "Fix UOW OnCompleted usage"

pull/212/head
Super 4 years ago
committed by GitHub
parent
commit
8f344e6189
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEventHandler.cs
  2. 10
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandler.cs

16
plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEventHandler.cs

@ -2,7 +2,6 @@
using EasyAbp.EShop.Plugins.FlashSales.FlashSaleResults; using EasyAbp.EShop.Plugins.FlashSales.FlashSaleResults;
using EasyAbp.EShop.Plugins.FlashSales.FlashSaleResults.Dtos; using EasyAbp.EShop.Plugins.FlashSales.FlashSaleResults.Dtos;
using EasyAbp.Eshop.Products.Products; using EasyAbp.Eshop.Products.Products;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed; using Volo.Abp.EventBus.Distributed;
@ -17,7 +16,7 @@ public class FlashSaleOrderCreationResultEventHandler : IDistributedEventHandler
protected ILogger<FlashSaleOrderCreationResultEventHandler> Logger { get; } protected ILogger<FlashSaleOrderCreationResultEventHandler> Logger { get; }
protected IFlashSaleInventoryManager FlashSaleInventoryManager { get; } protected IFlashSaleInventoryManager FlashSaleInventoryManager { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; } protected IUnitOfWorkManager UnitOfWorkManager { get; }
protected IServiceScopeFactory ServiceScopeFactory { get; } protected IObjectMapper ObjectMapper { get; }
protected IFlashSaleCurrentResultCache FlashSaleCurrentResultCache { get; } protected IFlashSaleCurrentResultCache FlashSaleCurrentResultCache { get; }
protected IFlashSaleResultRepository FlashSaleResultRepository { get; } protected IFlashSaleResultRepository FlashSaleResultRepository { get; }
@ -25,14 +24,14 @@ public class FlashSaleOrderCreationResultEventHandler : IDistributedEventHandler
ILogger<FlashSaleOrderCreationResultEventHandler> logger, ILogger<FlashSaleOrderCreationResultEventHandler> logger,
IFlashSaleInventoryManager flashSaleInventoryManager, IFlashSaleInventoryManager flashSaleInventoryManager,
IUnitOfWorkManager unitOfWorkManager, IUnitOfWorkManager unitOfWorkManager,
IServiceScopeFactory serviceScopeFactory, IObjectMapper objectMapper,
IFlashSaleCurrentResultCache flashSaleCurrentResultCache, IFlashSaleCurrentResultCache flashSaleCurrentResultCache,
IFlashSaleResultRepository flashSaleResultRepository) IFlashSaleResultRepository flashSaleResultRepository)
{ {
Logger = logger; Logger = logger;
FlashSaleInventoryManager = flashSaleInventoryManager; FlashSaleInventoryManager = flashSaleInventoryManager;
UnitOfWorkManager = unitOfWorkManager; UnitOfWorkManager = unitOfWorkManager;
ServiceScopeFactory = serviceScopeFactory; ObjectMapper = objectMapper;
FlashSaleCurrentResultCache = flashSaleCurrentResultCache; FlashSaleCurrentResultCache = flashSaleCurrentResultCache;
FlashSaleResultRepository = flashSaleResultRepository; FlashSaleResultRepository = flashSaleResultRepository;
} }
@ -87,16 +86,11 @@ public class FlashSaleOrderCreationResultEventHandler : IDistributedEventHandler
protected virtual async Task ResetFlashSaleCurrentResultCacheAsync(FlashSaleResult flashSaleResult) protected virtual async Task ResetFlashSaleCurrentResultCacheAsync(FlashSaleResult flashSaleResult)
{ {
using var scope = ServiceScopeFactory.CreateScope(); await FlashSaleCurrentResultCache.SetAsync(flashSaleResult.PlanId, flashSaleResult.UserId,
var objectMapper = scope.ServiceProvider.GetRequiredService<IObjectMapper>();
var flashSaleCurrentResultCache = scope.ServiceProvider.GetRequiredService<IFlashSaleCurrentResultCache>();
await flashSaleCurrentResultCache.SetAsync(flashSaleResult.PlanId, flashSaleResult.UserId,
new FlashSaleCurrentResultCacheItem new FlashSaleCurrentResultCacheItem
{ {
TenantId = flashSaleResult.TenantId, TenantId = flashSaleResult.TenantId,
ResultDto = objectMapper.Map<FlashSaleResult, FlashSaleResultDto>(flashSaleResult) ResultDto = ObjectMapper.Map<FlashSaleResult, FlashSaleResultDto>(flashSaleResult)
}); });
} }
} }

10
plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandler.cs

@ -3,7 +3,6 @@ using EasyAbp.EShop.Plugins.FlashSales.FlashSalePlans;
using EasyAbp.EShop.Plugins.FlashSales.FlashSaleResults.Dtos; using EasyAbp.EShop.Plugins.FlashSales.FlashSaleResults.Dtos;
using EasyAbp.Eshop.Products.Products; using EasyAbp.Eshop.Products.Products;
using EasyAbp.EShop.Products.Products; using EasyAbp.EShop.Products.Products;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -23,7 +22,6 @@ public class CreateFlashSaleResultEventHandler : IDistributedEventHandler<Create
protected IObjectMapper ObjectMapper { get; } protected IObjectMapper ObjectMapper { get; }
protected ICurrentTenant CurrentTenant { get; } protected ICurrentTenant CurrentTenant { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; } protected IUnitOfWorkManager UnitOfWorkManager { get; }
protected IServiceScopeFactory ServiceScopeFactory { get; }
protected ILogger<CreateFlashSaleResultEventHandler> Logger { get; } protected ILogger<CreateFlashSaleResultEventHandler> Logger { get; }
protected IAbpDistributedLock AbpDistributedLock { get; } protected IAbpDistributedLock AbpDistributedLock { get; }
protected IDistributedEventBus DistributedEventBus { get; } protected IDistributedEventBus DistributedEventBus { get; }
@ -35,7 +33,6 @@ public class CreateFlashSaleResultEventHandler : IDistributedEventHandler<Create
IObjectMapper objectMapper, IObjectMapper objectMapper,
ICurrentTenant currentTenant, ICurrentTenant currentTenant,
IUnitOfWorkManager unitOfWorkManager, IUnitOfWorkManager unitOfWorkManager,
IServiceScopeFactory serviceScopeFactory,
ILogger<CreateFlashSaleResultEventHandler> logger, ILogger<CreateFlashSaleResultEventHandler> logger,
IAbpDistributedLock abpDistributedLock, IAbpDistributedLock abpDistributedLock,
IDistributedEventBus distributedEventBus, IDistributedEventBus distributedEventBus,
@ -46,7 +43,6 @@ public class CreateFlashSaleResultEventHandler : IDistributedEventHandler<Create
ObjectMapper = objectMapper; ObjectMapper = objectMapper;
CurrentTenant = currentTenant; CurrentTenant = currentTenant;
UnitOfWorkManager = unitOfWorkManager; UnitOfWorkManager = unitOfWorkManager;
ServiceScopeFactory = serviceScopeFactory;
Logger = logger; Logger = logger;
AbpDistributedLock = abpDistributedLock; AbpDistributedLock = abpDistributedLock;
DistributedEventBus = distributedEventBus; DistributedEventBus = distributedEventBus;
@ -84,11 +80,7 @@ public class CreateFlashSaleResultEventHandler : IDistributedEventHandler<Create
// try to roll back the inventory. // try to roll back the inventory.
UnitOfWorkManager.Current.OnCompleted(async () => UnitOfWorkManager.Current.OnCompleted(async () =>
{ {
using var scope = ServiceScopeFactory.CreateScope(); if (!await FlashSaleInventoryManager.TryRollBackInventoryAsync(eventData.TenantId,
var flashSaleInventoryManager = scope.ServiceProvider.GetRequiredService<IFlashSaleInventoryManager>();
if (!await flashSaleInventoryManager.TryRollBackInventoryAsync(eventData.TenantId,
eventData.ProductInventoryProviderName, eventData.Plan.StoreId, eventData.ProductInventoryProviderName, eventData.Plan.StoreId,
eventData.Plan.ProductId, eventData.Plan.ProductSkuId)) eventData.Plan.ProductId, eventData.Plan.ProductSkuId))
{ {

Loading…
Cancel
Save