Files
Toolkit2/Toolkit.Foundation/ScopedServiceProvider.cs
T
2025-02-11 19:45:02 +00:00

21 lines
529 B
C#

using Microsoft.Extensions.DependencyInjection;
namespace Toolkit.Foundation;
public class ScopedServiceProvider<TService>(ICache<TService, IServiceScope> cache) :
IScopedServiceProvider<TService>
where TService : notnull
{
public bool TryGet(TService service,
out IServiceScope? serviceScope)
{
if (cache.TryGetValue(service, out IServiceScope? value))
{
serviceScope = value;
return true;
}
serviceScope = null;
return false;
}
}