diff --git a/modules/Common/src/EasyAbp.BookingService.Common.Domain/EasyAbp/BookingService/AssetSchedules/AssetScheduleCacheInvalidator.cs b/modules/Common/src/EasyAbp.BookingService.Common.Domain/EasyAbp/BookingService/AssetSchedules/AssetScheduleCacheInvalidator.cs index 7646661..7e6764c 100644 --- a/modules/Common/src/EasyAbp.BookingService.Common.Domain/EasyAbp/BookingService/AssetSchedules/AssetScheduleCacheInvalidator.cs +++ b/modules/Common/src/EasyAbp.BookingService.Common.Domain/EasyAbp/BookingService/AssetSchedules/AssetScheduleCacheInvalidator.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities.Events; @@ -12,17 +13,20 @@ public class AssetScheduleCacheInvalidator : ILocalEventHandler DistributedCache { get; } - - protected IUnitOfWorkManager UnitOfWorkManager { get; } protected ICurrentTenant CurrentTenant { get; } + protected IUnitOfWorkManager UnitOfWorkManager { get; } + protected IServiceScopeFactory ServiceScopeFactory { get; } - public AssetScheduleCacheInvalidator(IDistributedCache distributedCache, + public AssetScheduleCacheInvalidator( + IDistributedCache distributedCache, ICurrentTenant currentTenant, - IUnitOfWorkManager unitOfWorkManager) + IUnitOfWorkManager unitOfWorkManager, + IServiceScopeFactory serviceScopeFactory) { DistributedCache = distributedCache; CurrentTenant = currentTenant; UnitOfWorkManager = unitOfWorkManager; + ServiceScopeFactory = serviceScopeFactory; } public virtual async Task HandleEventAsync(EntityChangedEventData eventData) @@ -31,7 +35,14 @@ public virtual async Task HandleEventAsync(EntityChangedEventData eventData.Entity.AssetId, eventData.Entity.PeriodSchemeId, CurrentTenant.Id); + await DistributedCache.RemoveAsync(key); - UnitOfWorkManager.Current?.OnCompleted(() => DistributedCache.RemoveAsync(key)); + + UnitOfWorkManager.Current?.OnCompleted(async () => + { + using var scope = ServiceScopeFactory.CreateScope(); + var cache = scope.ServiceProvider.GetRequiredService>(); + await cache.RemoveAsync(key); + }); } } \ No newline at end of file