diff --git a/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEventHandler.cs b/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEventHandler.cs index 852d3fa9..ba59e962 100644 --- a/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEventHandler.cs +++ b/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEventHandler.cs @@ -2,6 +2,7 @@ using EasyAbp.EShop.Plugins.FlashSales.FlashSaleResults; using EasyAbp.EShop.Plugins.FlashSales.FlashSaleResults.Dtos; using EasyAbp.Eshop.Products.Products; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Volo.Abp.DependencyInjection; using Volo.Abp.EventBus.Distributed; @@ -16,7 +17,7 @@ public class FlashSaleOrderCreationResultEventHandler : IDistributedEventHandler protected ILogger Logger { get; } protected IFlashSaleInventoryManager FlashSaleInventoryManager { get; } protected IUnitOfWorkManager UnitOfWorkManager { get; } - protected IObjectMapper ObjectMapper { get; } + protected IServiceScopeFactory ServiceScopeFactory { get; } protected IFlashSaleCurrentResultCache FlashSaleCurrentResultCache { get; } protected IFlashSaleResultRepository FlashSaleResultRepository { get; } @@ -24,14 +25,14 @@ public class FlashSaleOrderCreationResultEventHandler : IDistributedEventHandler ILogger logger, IFlashSaleInventoryManager flashSaleInventoryManager, IUnitOfWorkManager unitOfWorkManager, - IObjectMapper objectMapper, + IServiceScopeFactory serviceScopeFactory, IFlashSaleCurrentResultCache flashSaleCurrentResultCache, IFlashSaleResultRepository flashSaleResultRepository) { Logger = logger; FlashSaleInventoryManager = flashSaleInventoryManager; UnitOfWorkManager = unitOfWorkManager; - ObjectMapper = objectMapper; + ServiceScopeFactory = serviceScopeFactory; FlashSaleCurrentResultCache = flashSaleCurrentResultCache; FlashSaleResultRepository = flashSaleResultRepository; } @@ -86,11 +87,16 @@ public class FlashSaleOrderCreationResultEventHandler : IDistributedEventHandler protected virtual async Task ResetFlashSaleCurrentResultCacheAsync(FlashSaleResult flashSaleResult) { - await FlashSaleCurrentResultCache.SetAsync(flashSaleResult.PlanId, flashSaleResult.UserId, + using var scope = ServiceScopeFactory.CreateScope(); + + var objectMapper = scope.ServiceProvider.GetRequiredService(); + var flashSaleCurrentResultCache = scope.ServiceProvider.GetRequiredService(); + + await flashSaleCurrentResultCache.SetAsync(flashSaleResult.PlanId, flashSaleResult.UserId, new FlashSaleCurrentResultCacheItem { TenantId = flashSaleResult.TenantId, - ResultDto = ObjectMapper.Map(flashSaleResult) + ResultDto = objectMapper.Map(flashSaleResult) }); } } \ No newline at end of file diff --git a/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandler.cs b/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandler.cs index e691edd7..ef53a8d7 100644 --- a/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandler.cs +++ b/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandler.cs @@ -3,6 +3,7 @@ using EasyAbp.EShop.Plugins.FlashSales.FlashSalePlans; 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 Volo.Abp; using Volo.Abp.DependencyInjection; @@ -22,6 +23,7 @@ public class CreateFlashSaleResultEventHandler : IDistributedEventHandler Logger { get; } protected IAbpDistributedLock AbpDistributedLock { get; } protected IDistributedEventBus DistributedEventBus { get; } @@ -33,6 +35,7 @@ public class CreateFlashSaleResultEventHandler : IDistributedEventHandler logger, IAbpDistributedLock abpDistributedLock, IDistributedEventBus distributedEventBus, @@ -43,6 +46,7 @@ public class CreateFlashSaleResultEventHandler : IDistributedEventHandler { - if (!await FlashSaleInventoryManager.TryRollBackInventoryAsync(eventData.TenantId, + using var scope = ServiceScopeFactory.CreateScope(); + + var flashSaleInventoryManager = scope.ServiceProvider.GetRequiredService(); + + if (!await flashSaleInventoryManager.TryRollBackInventoryAsync(eventData.TenantId, eventData.ProductInventoryProviderName, eventData.Plan.StoreId, eventData.Plan.ProductId, eventData.Plan.ProductSkuId)) {