Don't use default params for AddUnique extension methods (breaks v9) (#12485)

This commit is contained in:
Matt Brailsford
2022-05-26 08:25:02 +01:00
committed by GitHub
parent 8609314314
commit f3c4c677f3

View File

@@ -37,6 +37,19 @@ namespace Umbraco.Extensions
services.Add(ServiceDescriptor.Describe(typeof(TService), typeof(TImplementing), lifetime));
}
/// <summary>
/// Adds services of types <typeparamref name="TService1"/> &amp; <typeparamref name="TService2"/> with a shared implementation type of <typeparamref name="TImplementing"/> to the specified <see cref="IServiceCollection"/>.
/// </summary>
/// <remarks>
/// Removes all previous registrations for the types <typeparamref name="TService1"/> &amp; <typeparamref name="TService2"/>.
/// </remarks>
public static void AddMultipleUnique<TService1, TService2, TImplementing>(
this IServiceCollection services)
where TService1 : class
where TService2 : class
where TImplementing : class, TService1, TService2
=> services.AddMultipleUnique<TService1, TService2, TImplementing>(ServiceLifetime.Singleton);
/// <summary>
/// Adds services of types <typeparamref name="TService1"/> &amp; <typeparamref name="TService2"/> with a shared implementation type of <typeparamref name="TImplementing"/> to the specified <see cref="IServiceCollection"/>.
/// </summary>
@@ -45,7 +58,7 @@ namespace Umbraco.Extensions
/// </remarks>
public static void AddMultipleUnique<TService1, TService2, TImplementing>(
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<TImplementing>();
}
/// <summary>
/// Adds a service of type <typeparamref name="TService"/> with an implementation factory method to the specified <see cref="IServiceCollection"/>.
/// </summary>
/// <remarks>
/// Removes all previous registrations for the type <typeparamref name="TService"/>.
/// </remarks>
public static void AddUnique<TService>(
this IServiceCollection services,
Func<IServiceProvider, TService> factory)
where TService : class
=> services.AddUnique(factory, ServiceLifetime.Singleton);
/// <summary>
/// Adds a service of type <typeparamref name="TService"/> with an implementation factory method to the specified <see cref="IServiceCollection"/>.
/// </summary>
@@ -72,7 +97,7 @@ namespace Umbraco.Extensions
public static void AddUnique<TService>(
this IServiceCollection services,
Func<IServiceProvider, TService> factory,
ServiceLifetime lifetime = ServiceLifetime.Singleton)
ServiceLifetime lifetime)
where TService : class
{
services.RemoveAll<TService>();