From f3c4c677f3cc67d7d505a7d1c227ad6d9b32e71c Mon Sep 17 00:00:00 2001 From: Matt Brailsford Date: Thu, 26 May 2022 08:25:02 +0100 Subject: [PATCH] Don't use default params for AddUnique extension methods (breaks v9) (#12485) --- .../ServiceCollectionExtensions.cs | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/DependencyInjection/ServiceCollectionExtensions.cs b/src/Umbraco.Core/DependencyInjection/ServiceCollectionExtensions.cs index 6c806ce0db..d0f198557f 100644 --- a/src/Umbraco.Core/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/Umbraco.Core/DependencyInjection/ServiceCollectionExtensions.cs @@ -37,6 +37,19 @@ namespace Umbraco.Extensions services.Add(ServiceDescriptor.Describe(typeof(TService), typeof(TImplementing), lifetime)); } + /// + /// Adds services of types & with a shared implementation type of to the specified . + /// + /// + /// Removes all previous registrations for the types & . + /// + public static void AddMultipleUnique( + this IServiceCollection services) + where TService1 : class + where TService2 : class + where TImplementing : class, TService1, TService2 + => services.AddMultipleUnique(ServiceLifetime.Singleton); + /// /// Adds services of types & with a shared implementation type of to the specified . /// @@ -45,7 +58,7 @@ namespace Umbraco.Extensions /// public static void AddMultipleUnique( this IServiceCollection services, - ServiceLifetime lifetime = ServiceLifetime.Singleton) + ServiceLifetime lifetime) where TService1 : class where TService2 : class where TImplementing : class, TService1, TService2 @@ -63,6 +76,18 @@ namespace Umbraco.Extensions services.AddSingleton(); } + /// + /// Adds a service of type with an implementation factory method to the specified . + /// + /// + /// Removes all previous registrations for the type . + /// + public static void AddUnique( + this IServiceCollection services, + Func factory) + where TService : class + => services.AddUnique(factory, ServiceLifetime.Singleton); + /// /// Adds a service of type with an implementation factory method to the specified . /// @@ -72,7 +97,7 @@ namespace Umbraco.Extensions public static void AddUnique( this IServiceCollection services, Func factory, - ServiceLifetime lifetime = ServiceLifetime.Singleton) + ServiceLifetime lifetime) where TService : class { services.RemoveAll();