From 750a57eb1202e6247c4724c3bf0f02a3bc84ad01 Mon Sep 17 00:00:00 2001 From: TheXamlGuy Date: Sun, 29 Sep 2024 16:39:28 +0100 Subject: [PATCH] Amend ScopeServiceFactory to return a tuple of 2 value --- Toolkit.Foundation/IServiceScopeFactory.cs | 6 ++++-- .../{ServiceScopeFactory.cs => ScopeServiceFactory.cs} | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) rename Toolkit.Foundation/{ServiceScopeFactory.cs => ScopeServiceFactory.cs} (77%) diff --git a/Toolkit.Foundation/IServiceScopeFactory.cs b/Toolkit.Foundation/IServiceScopeFactory.cs index 891139d..57ea4b2 100644 --- a/Toolkit.Foundation/IServiceScopeFactory.cs +++ b/Toolkit.Foundation/IServiceScopeFactory.cs @@ -1,6 +1,8 @@ -namespace Toolkit.Foundation; +using Microsoft.Extensions.DependencyInjection; + +namespace Toolkit.Foundation; public interface IServiceScopeFactory { - TService? Create(params object?[] parameters); + (IServiceScope, TService)? Create(params object?[] parameters); } \ No newline at end of file diff --git a/Toolkit.Foundation/ServiceScopeFactory.cs b/Toolkit.Foundation/ScopeServiceFactory.cs similarity index 77% rename from Toolkit.Foundation/ServiceScopeFactory.cs rename to Toolkit.Foundation/ScopeServiceFactory.cs index 2ea2332..fd73932 100644 --- a/Toolkit.Foundation/ServiceScopeFactory.cs +++ b/Toolkit.Foundation/ScopeServiceFactory.cs @@ -2,12 +2,12 @@ namespace Toolkit.Foundation; -public class ServiceScopeFactory(IServiceScopeFactory serviceScopeFactory, +public class ScopeServiceFactory(IServiceScopeFactory serviceScopeFactory, ICache cache) : IServiceScopeFactory where TService : notnull { - public TService? Create(params object?[] parameters) + public (IServiceScope, TService)? Create(params object?[] parameters) { if (serviceScopeFactory.CreateScope() is IServiceScope serviceScope) { @@ -16,7 +16,7 @@ public class ServiceScopeFactory(IServiceScopeFactory serviceScopeFact if (factory.Create(parameters) is TService service) { cache.Add(service, serviceScope); - return service; + return (serviceScope, service); } } }