Browse Source

Use `IServiceScopeFactory` on UOW completed

pull/270/head
gdlcf88 3 years ago
parent
commit
e710f15271
  1. 28
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs
  2. 20
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCanceledEventHandler.cs
  3. 9
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEventHandler.cs
  4. 16
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSalePlanCacheInvalidator.cs
  5. 8
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandler.cs
  6. 16
      plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Products/Products/ProductCacheInvalidator.cs

28
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs

@ -8,6 +8,7 @@ using EasyAbp.EShop.Products.Options;
using EasyAbp.EShop.Products.ProductInventories; using EasyAbp.EShop.Products.ProductInventories;
using EasyAbp.EShop.Products.Products.CacheItems; using EasyAbp.EShop.Products.Products.CacheItems;
using EasyAbp.EShop.Stores.Stores; using EasyAbp.EShop.Stores.Stores;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Caching; using Volo.Abp.Caching;
@ -28,8 +29,8 @@ namespace EasyAbp.EShop.Products.Products
protected override string CrossStorePolicyName { get; set; } = ProductsPermissions.Products.CrossStore; protected override string CrossStorePolicyName { get; set; } = ProductsPermissions.Products.CrossStore;
private readonly IProductManager _productManager; private readonly IProductManager _productManager;
private readonly IDistributedCache<ProductViewCacheItem> _cache;
private readonly EShopProductsOptions _options; private readonly EShopProductsOptions _options;
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly IProductInventoryProviderResolver _productInventoryProviderResolver; private readonly IProductInventoryProviderResolver _productInventoryProviderResolver;
private readonly IProductViewCacheKeyProvider _productViewCacheKeyProvider; private readonly IProductViewCacheKeyProvider _productViewCacheKeyProvider;
private readonly IProductRepository _repository; private readonly IProductRepository _repository;
@ -37,14 +38,14 @@ namespace EasyAbp.EShop.Products.Products
public ProductAppService( public ProductAppService(
IProductManager productManager, IProductManager productManager,
IOptions<EShopProductsOptions> options, IOptions<EShopProductsOptions> options,
IDistributedCache<ProductViewCacheItem> cache, IServiceScopeFactory serviceScopeFactory,
IProductInventoryProviderResolver productInventoryProviderResolver, IProductInventoryProviderResolver productInventoryProviderResolver,
IProductViewCacheKeyProvider productViewCacheKeyProvider, IProductViewCacheKeyProvider productViewCacheKeyProvider,
IProductRepository repository) : base(repository) IProductRepository repository) : base(repository)
{ {
_productManager = productManager; _productManager = productManager;
_cache = cache;
_options = options.Value; _options = options.Value;
_serviceScopeFactory = serviceScopeFactory;
_productInventoryProviderResolver = productInventoryProviderResolver; _productInventoryProviderResolver = productInventoryProviderResolver;
_productViewCacheKeyProvider = productViewCacheKeyProvider; _productViewCacheKeyProvider = productViewCacheKeyProvider;
_repository = repository; _repository = repository;
@ -87,14 +88,19 @@ namespace EasyAbp.EShop.Products.Products
await LoadDtosExtraDataAsync(items, Clock.Now); await LoadDtosExtraDataAsync(items, Clock.Now);
await LoadDtosProductGroupDisplayNameAsync(items); await LoadDtosProductGroupDisplayNameAsync(items);
UnitOfWorkManager.Current.OnCompleted(async () => { await ClearProductViewCacheAsync(product.StoreId); }); await ClearProductViewCacheOnCurrentUowCompletedAsync(product.StoreId);
return dto; return dto;
} }
protected virtual async Task ClearProductViewCacheAsync(Guid storeId) protected virtual async Task ClearProductViewCacheOnCurrentUowCompletedAsync(Guid storeId)
{ {
await _cache.RemoveAsync(await _productViewCacheKeyProvider.GetCacheKeyAsync(storeId)); UnitOfWorkManager.Current.OnCompleted(async () =>
{
using var scope = _serviceScopeFactory.CreateScope();
var cache = scope.ServiceProvider.GetRequiredService<IDistributedCache<ProductViewCacheItem>>();
await cache.RemoveAsync(await _productViewCacheKeyProvider.GetCacheKeyAsync(storeId));
});
} }
public override async Task<ProductDto> UpdateAsync(Guid id, CreateUpdateProductDto input) public override async Task<ProductDto> UpdateAsync(Guid id, CreateUpdateProductDto input)
@ -123,7 +129,7 @@ namespace EasyAbp.EShop.Products.Products
await LoadDtosExtraDataAsync(items, Clock.Now); await LoadDtosExtraDataAsync(items, Clock.Now);
await LoadDtosProductGroupDisplayNameAsync(items); await LoadDtosProductGroupDisplayNameAsync(items);
UnitOfWorkManager.Current.OnCompleted(async () => { await ClearProductViewCacheAsync(product.StoreId); }); await ClearProductViewCacheOnCurrentUowCompletedAsync(product.StoreId);
return dto; return dto;
} }
@ -351,7 +357,7 @@ namespace EasyAbp.EShop.Products.Products
await _productManager.DeleteAsync(product); await _productManager.DeleteAsync(product);
UnitOfWorkManager.Current.OnCompleted(async () => { await ClearProductViewCacheAsync(product.StoreId); }); await ClearProductViewCacheOnCurrentUowCompletedAsync(product.StoreId);
} }
protected virtual void CheckProductIsNotStatic(Product product) protected virtual void CheckProductIsNotStatic(Product product)
@ -383,7 +389,7 @@ namespace EasyAbp.EShop.Products.Products
await LoadDtosExtraDataAsync(items, Clock.Now); await LoadDtosExtraDataAsync(items, Clock.Now);
await LoadDtosProductGroupDisplayNameAsync(items); await LoadDtosProductGroupDisplayNameAsync(items);
UnitOfWorkManager.Current.OnCompleted(async () => { await ClearProductViewCacheAsync(product.StoreId); }); await ClearProductViewCacheOnCurrentUowCompletedAsync(product.StoreId);
return dto; return dto;
} }
@ -410,7 +416,7 @@ namespace EasyAbp.EShop.Products.Products
await LoadDtosExtraDataAsync(items, Clock.Now); await LoadDtosExtraDataAsync(items, Clock.Now);
await LoadDtosProductGroupDisplayNameAsync(items); await LoadDtosProductGroupDisplayNameAsync(items);
UnitOfWorkManager.Current.OnCompleted(async () => { await ClearProductViewCacheAsync(product.StoreId); }); await ClearProductViewCacheOnCurrentUowCompletedAsync(product.StoreId);
return dto; return dto;
} }
@ -434,7 +440,7 @@ namespace EasyAbp.EShop.Products.Products
await LoadDtosExtraDataAsync(items, Clock.Now); await LoadDtosExtraDataAsync(items, Clock.Now);
await LoadDtosProductGroupDisplayNameAsync(items); await LoadDtosProductGroupDisplayNameAsync(items);
UnitOfWorkManager.Current.OnCompleted(async () => { await ClearProductViewCacheAsync(product.StoreId); }); await ClearProductViewCacheOnCurrentUowCompletedAsync(product.StoreId);
return dto; return dto;
} }

20
plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCanceledEventHandler.cs

@ -2,8 +2,6 @@
using EasyAbp.EShop.Orders.Orders; using EasyAbp.EShop.Orders.Orders;
using EasyAbp.EShop.Plugins.FlashSales.FlashSaleResults; using EasyAbp.EShop.Plugins.FlashSales.FlashSaleResults;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Volo.Abp;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.Abp.EventBus.Distributed; using Volo.Abp.EventBus.Distributed;
@ -13,27 +11,27 @@ namespace EasyAbp.EShop.Plugins.FlashSales.FlashSalePlans;
public class FlashSaleOrderCanceledEventHandler : IDistributedEventHandler<OrderCanceledEto>, ITransientDependency public class FlashSaleOrderCanceledEventHandler : IDistributedEventHandler<OrderCanceledEto>, ITransientDependency
{ {
protected IServiceScopeFactory ServiceScopeFactory { get; }
protected IFlashSaleResultRepository FlashSaleResultRepository { get; } protected IFlashSaleResultRepository FlashSaleResultRepository { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; } protected IUnitOfWorkManager UnitOfWorkManager { get; }
protected IAbpApplication AbpApplication { get; }
public FlashSaleOrderCanceledEventHandler( public FlashSaleOrderCanceledEventHandler(
IServiceScopeFactory serviceScopeFactory,
IFlashSaleResultRepository flashSaleResultRepository, IFlashSaleResultRepository flashSaleResultRepository,
IUnitOfWorkManager unitOfWorkManager, IUnitOfWorkManager unitOfWorkManager)
IAbpApplication abpApplication)
{ {
ServiceScopeFactory = serviceScopeFactory;
FlashSaleResultRepository = flashSaleResultRepository; FlashSaleResultRepository = flashSaleResultRepository;
UnitOfWorkManager = unitOfWorkManager; UnitOfWorkManager = unitOfWorkManager;
AbpApplication = abpApplication;
} }
[UnitOfWork(true)] [UnitOfWork(true)]
public virtual async Task HandleEventAsync(OrderCanceledEto eventData) public virtual async Task HandleEventAsync(OrderCanceledEto eventData)
{ {
var flashSaleResult = await FlashSaleResultRepository var flashSaleResult = await FlashSaleResultRepository
.SingleOrDefaultAsync(x => x.Status != FlashSaleResultStatus.Failed && x.StoreId == eventData.Order.StoreId && x.OrderId == eventData.Order.Id); .SingleOrDefaultAsync(x =>
x.Status != FlashSaleResultStatus.Failed && x.StoreId == eventData.Order.StoreId &&
x.OrderId == eventData.Order.Id);
if (flashSaleResult == null) if (flashSaleResult == null)
{ {
return; return;
@ -45,10 +43,10 @@ public class FlashSaleOrderCanceledEventHandler : IDistributedEventHandler<Order
UnitOfWorkManager.Current.OnCompleted(async () => UnitOfWorkManager.Current.OnCompleted(async () =>
{ {
using var scope = AbpApplication.ServiceProvider.CreateScope(); using var scope = ServiceScopeFactory.CreateScope();
var flashSaleCurrentResultCache = scope.ServiceProvider.GetRequiredService<IFlashSaleCurrentResultCache>(); var flashSaleCurrentResultCache = scope.ServiceProvider.GetRequiredService<IFlashSaleCurrentResultCache>();
// remove the cache so the user can try to order again. // remove the cache so the user can try to order again.
await flashSaleCurrentResultCache.RemoveAsync(flashSaleResult.PlanId, flashSaleResult.UserId); await flashSaleCurrentResultCache.RemoveAsync(flashSaleResult.PlanId, flashSaleResult.UserId);
}); });
} }
} }

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

@ -4,7 +4,6 @@ using EasyAbp.EShop.Plugins.FlashSales.FlashSaleResults.Dtos;
using EasyAbp.EShop.Products.Products; using EasyAbp.EShop.Products.Products;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Volo.Abp;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed; using Volo.Abp.EventBus.Distributed;
using Volo.Abp.ObjectMapping; using Volo.Abp.ObjectMapping;
@ -17,18 +16,18 @@ public class FlashSaleOrderCreationResultEventHandler : IDistributedEventHandler
{ {
protected ILogger<FlashSaleOrderCreationResultEventHandler> Logger { get; } protected ILogger<FlashSaleOrderCreationResultEventHandler> Logger { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; } protected IUnitOfWorkManager UnitOfWorkManager { get; }
protected IAbpApplication AbpApplication { get; } protected IServiceScopeFactory ServiceScopeFactory { get; }
protected IFlashSaleResultRepository FlashSaleResultRepository { get; } protected IFlashSaleResultRepository FlashSaleResultRepository { get; }
public FlashSaleOrderCreationResultEventHandler( public FlashSaleOrderCreationResultEventHandler(
ILogger<FlashSaleOrderCreationResultEventHandler> logger, ILogger<FlashSaleOrderCreationResultEventHandler> logger,
IUnitOfWorkManager unitOfWorkManager, IUnitOfWorkManager unitOfWorkManager,
IAbpApplication abpApplication, IServiceScopeFactory serviceScopeFactory,
IFlashSaleResultRepository flashSaleResultRepository) IFlashSaleResultRepository flashSaleResultRepository)
{ {
Logger = logger; Logger = logger;
UnitOfWorkManager = unitOfWorkManager; UnitOfWorkManager = unitOfWorkManager;
AbpApplication = abpApplication; ServiceScopeFactory = serviceScopeFactory;
FlashSaleResultRepository = flashSaleResultRepository; FlashSaleResultRepository = flashSaleResultRepository;
} }
@ -52,7 +51,7 @@ public class FlashSaleOrderCreationResultEventHandler : IDistributedEventHandler
UnitOfWorkManager.Current.OnCompleted(async () => UnitOfWorkManager.Current.OnCompleted(async () =>
{ {
using var scope = AbpApplication.ServiceProvider.CreateScope(); using var scope = ServiceScopeFactory.CreateScope();
var flashSaleInventoryManager = scope.ServiceProvider.GetRequiredService<IFlashSaleInventoryManager>(); var flashSaleInventoryManager = scope.ServiceProvider.GetRequiredService<IFlashSaleInventoryManager>();
var flashSaleCurrentResultCache = scope.ServiceProvider.GetRequiredService<IFlashSaleCurrentResultCache>(); var flashSaleCurrentResultCache = scope.ServiceProvider.GetRequiredService<IFlashSaleCurrentResultCache>();

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

@ -1,5 +1,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Caching; using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events; using Volo.Abp.Domain.Entities.Events;
@ -8,15 +9,19 @@ using Volo.Abp.Uow;
namespace EasyAbp.EShop.Plugins.FlashSales.FlashSalePlans; namespace EasyAbp.EShop.Plugins.FlashSales.FlashSalePlans;
public class FlashSalePlanCacheInvalidator : ILocalEventHandler<EntityChangedEventData<FlashSalePlan>>, ITransientDependency public class FlashSalePlanCacheInvalidator : ILocalEventHandler<EntityChangedEventData<FlashSalePlan>>,
ITransientDependency
{ {
protected IServiceScopeFactory ServiceScopeFactory { get; }
protected IDistributedCache<FlashSalePlanCacheItem, Guid> DistributedCache { get; } protected IDistributedCache<FlashSalePlanCacheItem, Guid> DistributedCache { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; } protected IUnitOfWorkManager UnitOfWorkManager { get; }
public FlashSalePlanCacheInvalidator( public FlashSalePlanCacheInvalidator(
IServiceScopeFactory serviceScopeFactory,
IDistributedCache<FlashSalePlanCacheItem, Guid> distributedCache, IDistributedCache<FlashSalePlanCacheItem, Guid> distributedCache,
IUnitOfWorkManager unitOfWorkManager) IUnitOfWorkManager unitOfWorkManager)
{ {
ServiceScopeFactory = serviceScopeFactory;
DistributedCache = distributedCache; DistributedCache = distributedCache;
UnitOfWorkManager = unitOfWorkManager; UnitOfWorkManager = unitOfWorkManager;
} }
@ -27,7 +32,12 @@ public class FlashSalePlanCacheInvalidator : ILocalEventHandler<EntityChangedEve
UnitOfWorkManager.Current?.OnCompleted(async () => UnitOfWorkManager.Current?.OnCompleted(async () =>
{ {
await DistributedCache.RemoveAsync(eventData.Entity.Id); using var scope = ServiceScopeFactory.CreateScope();
var distributedCache =
scope.ServiceProvider.GetRequiredService<IDistributedCache<FlashSalePlanCacheItem, Guid>>();
await distributedCache.RemoveAsync(eventData.Entity.Id);
}); });
} }
} }

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

@ -22,10 +22,10 @@ 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; }
protected IAbpApplication AbpApplication { get; }
protected IFlashSaleInventoryManager FlashSaleInventoryManager { get; } protected IFlashSaleInventoryManager FlashSaleInventoryManager { get; }
protected IFlashSaleCurrentResultCache FlashSaleCurrentResultCache { get; } protected IFlashSaleCurrentResultCache FlashSaleCurrentResultCache { get; }
protected IFlashSaleResultRepository FlashSaleResultRepository { get; } protected IFlashSaleResultRepository FlashSaleResultRepository { get; }
@ -34,10 +34,10 @@ 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,
IAbpApplication abpApplication,
IFlashSaleInventoryManager flashSaleInventoryManager, IFlashSaleInventoryManager flashSaleInventoryManager,
IFlashSaleCurrentResultCache flashSaleCurrentResultCache, IFlashSaleCurrentResultCache flashSaleCurrentResultCache,
IFlashSaleResultRepository flashSaleResultRepository) IFlashSaleResultRepository flashSaleResultRepository)
@ -45,10 +45,10 @@ 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;
AbpApplication = abpApplication;
FlashSaleInventoryManager = flashSaleInventoryManager; FlashSaleInventoryManager = flashSaleInventoryManager;
FlashSaleCurrentResultCache = flashSaleCurrentResultCache; FlashSaleCurrentResultCache = flashSaleCurrentResultCache;
FlashSaleResultRepository = flashSaleResultRepository; FlashSaleResultRepository = flashSaleResultRepository;
@ -83,7 +83,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 = AbpApplication.ServiceProvider.CreateScope(); using var scope = ServiceScopeFactory.CreateScope();
var flashSaleInventoryManager = scope.ServiceProvider.GetRequiredService<IFlashSaleInventoryManager>(); var flashSaleInventoryManager = scope.ServiceProvider.GetRequiredService<IFlashSaleInventoryManager>();

16
plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Products/Products/ProductCacheInvalidator.cs

@ -1,4 +1,5 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed; using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus.Distributed; using Volo.Abp.EventBus.Distributed;
@ -13,13 +14,16 @@ public class ProductCacheInvalidator :
{ {
protected IProductCache ProductCache { get; } protected IProductCache ProductCache { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; } protected IUnitOfWorkManager UnitOfWorkManager { get; }
protected IServiceScopeFactory ServiceScopeFactory { get; }
public ProductCacheInvalidator( public ProductCacheInvalidator(
IProductCache productCache, IProductCache productCache,
IUnitOfWorkManager unitOfWorkManager) IUnitOfWorkManager unitOfWorkManager,
IServiceScopeFactory serviceScopeFactory)
{ {
ProductCache = productCache; ProductCache = productCache;
UnitOfWorkManager = unitOfWorkManager; UnitOfWorkManager = unitOfWorkManager;
ServiceScopeFactory = serviceScopeFactory;
} }
public virtual async Task HandleEventAsync(EntityUpdatedEto<ProductEto> eventData) public virtual async Task HandleEventAsync(EntityUpdatedEto<ProductEto> eventData)
@ -28,7 +32,9 @@ public class ProductCacheInvalidator :
UnitOfWorkManager.Current?.OnCompleted(async () => UnitOfWorkManager.Current?.OnCompleted(async () =>
{ {
await ProductCache.RemoveAsync(eventData.Entity.Id); using var scope = ServiceScopeFactory.CreateScope();
var productCache = scope.ServiceProvider.GetRequiredService<IProductCache>();
await productCache.RemoveAsync(eventData.Entity.Id);
}); });
} }
@ -38,7 +44,9 @@ public class ProductCacheInvalidator :
UnitOfWorkManager.Current?.OnCompleted(async () => UnitOfWorkManager.Current?.OnCompleted(async () =>
{ {
await ProductCache.RemoveAsync(eventData.Entity.Id); using var scope = ServiceScopeFactory.CreateScope();
var productCache = scope.ServiceProvider.GetRequiredService<IProductCache>();
await productCache.RemoveAsync(eventData.Entity.Id);
}); });
} }
} }
Loading…
Cancel
Save