Improve scoped service

This commit is contained in:
Dan Clark
2025-02-11 19:45:02 +00:00
parent 66d61a3917
commit 92ea28d647
25 changed files with 149 additions and 111 deletions
@@ -0,0 +1,21 @@
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;
}
}