diff --git a/src/OLT.Extensions.Caching.Memory/Services/OltHybridCache.cs b/src/OLT.Extensions.Caching.Memory/Services/OltHybridCache.cs index e4b4e6d..68a13c1 100644 --- a/src/OLT.Extensions.Caching.Memory/Services/OltHybridCache.cs +++ b/src/OLT.Extensions.Caching.Memory/Services/OltHybridCache.cs @@ -6,13 +6,13 @@ namespace OLT.Core; public class OltHybridCache : IOltHybridCache { - private readonly IServiceScopeFactory _serviceScopeFactory; + private readonly IServiceScopeFactory _scopeFactory; private readonly IFusionCache _cache; - public OltHybridCache(IFusionCache cache, IServiceScopeFactory serviceScopeFactory) + public OltHybridCache(IFusionCache cache, IServiceScopeFactory scopeFactory) { _cache = cache ?? throw new ArgumentNullException(nameof(cache)); - _serviceScopeFactory = serviceScopeFactory; + _scopeFactory = scopeFactory; } /// @@ -58,14 +58,14 @@ public async Task GetOrSetAsync(string key, Func(); return await _cache.GetOrSetAsync( key, - async (ctx, ct) => await factory(scope.ServiceProvider, new OltHybridCacheContext(ctx, ct)), + async (ctx, ct) => + { + await using var scope = _scopeFactory.CreateAsyncScope(); + return await factory(scope.ServiceProvider, new OltHybridCacheContext(ctx, ct)); + }, options, cancellationToken);