From bb1aac4ec7992bd0c14e620830046f8062d44149 Mon Sep 17 00:00:00 2001 From: Chris Straw Date: Wed, 25 Feb 2026 17:21:52 -0500 Subject: [PATCH] change to how the scoped factory is created --- .../Services/OltHybridCache.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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);