Amend ScopeServiceFactory to return a tuple of 2 value

This commit is contained in:
TheXamlGuy
2024-09-29 16:39:28 +01:00
parent 9c1f5fd690
commit 750a57eb12
2 changed files with 7 additions and 5 deletions
-26
View File
@@ -1,26 +0,0 @@
using Microsoft.Extensions.DependencyInjection;
namespace Toolkit.Foundation;
public class ServiceScopeFactory<TService>(IServiceScopeFactory serviceScopeFactory,
ICache<TService, IServiceScope> cache) :
IServiceScopeFactory<TService>
where TService : notnull
{
public TService? Create(params object?[] parameters)
{
if (serviceScopeFactory.CreateScope() is IServiceScope serviceScope)
{
if (serviceScope.ServiceProvider.GetService<IServiceFactory>() is IServiceFactory factory)
{
if (factory.Create<TService>(parameters) is TService service)
{
cache.Add(service, serviceScope);
return service;
}
}
}
return default;
}
}