add a central cache, for easy data retriveal

This commit is contained in:
TheXamlGuy
2024-01-14 20:35:38 +00:00
parent 1283e8ff58
commit 80f4d5a702
14 changed files with 154 additions and 122 deletions
+2 -3
View File
@@ -1,10 +1,9 @@
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Concurrent;
namespace Hyperbar;
public class ServiceScopeFactory<TService>(IServiceScopeFactory serviceScopeFactory,
ConcurrentDictionary<TService, IServiceScope> services) :
ICache<TService, IServiceScope> cache) :
IServiceScopeFactory<TService>
where TService : notnull
{
@@ -16,7 +15,7 @@ public class ServiceScopeFactory<TService>(IServiceScopeFactory serviceScopeFact
{
if (serviceFactory.Create<TService>(parameters) is TService service)
{
services.TryAdd(service, serviceScope);
cache.Add(service, serviceScope);
return service;
}
}