Skip to content

Commit 99c677b

Browse files
committed
WIP
\n\nCommit migrated from dotnet/extensions@9c9ac59
1 parent 70b8e10 commit 99c677b

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

src/HttpClientFactory/Http/src/DependencyInjection/HttpClientBuilderExtensions.cs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -566,28 +566,13 @@ private static void ReserveClient(IHttpClientBuilder builder, Type type, string
566566
var registry = (HttpClientMappingRegistry)builder.Services.Single(sd => sd.ServiceType == typeof(HttpClientMappingRegistry)).ImplementationInstance;
567567
Debug.Assert(registry != null);
568568

569-
// Check for same type registered twice. This can't work because typed clients have to be unique for DI to function.
570-
if (registry.TypedClientRegistrations.TryGetValue(type, out var otherName) &&
571-
572-
// Allow duplicate registrations with the same name. This is usually someone calling "AddHttpClient" once
573-
// as part of a library, and the consumer of that library doing the same thing to add further configuration.
574-
// See: https://github.com/aspnet/Extensions/issues/2077
575-
!string.Equals(name, otherName, StringComparison.Ordinal))
576-
{
577-
var message =
578-
$"The HttpClient factory already has a registered client with the type '{type.FullName}'. " +
579-
$"Client types must be unique. " +
580-
$"Consider using inheritance to create multiple unique types with the same API surface.";
581-
throw new InvalidOperationException(message);
582-
}
583-
584569
// Check for same name registered to two types. This won't work because we rely on named options for the configuration.
585570
if (registry.NamedClientRegistrations.TryGetValue(name, out var otherType) &&
586571

587572
// Allow using the same name with multiple types in some cases (see callers).
588573
validateSingleType &&
589574

590-
// Allow registering the same name twice to the same type (see above).
575+
// Allow registering the same name twice to the same type.
591576
type != otherType)
592577
{
593578
var message =
@@ -597,8 +582,10 @@ private static void ReserveClient(IHttpClientBuilder builder, Type type, string
597582
throw new InvalidOperationException(message);
598583
}
599584

600-
registry.TypedClientRegistrations[type] = name;
601-
registry.NamedClientRegistrations[name] = type;
585+
if (validateSingleType)
586+
{
587+
registry.NamedClientRegistrations[name] = type;
588+
}
602589
}
603590
}
604591
}

src/HttpClientFactory/Http/src/DependencyInjection/HttpClientMappingRegistry.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ namespace Microsoft.Extensions.DependencyInjection
1313
// See: https://github.com/aspnet/Extensions/issues/960
1414
internal class HttpClientMappingRegistry
1515
{
16-
public Dictionary<Type, string> TypedClientRegistrations { get; } = new Dictionary<Type, string>();
17-
1816
public Dictionary<string, Type> NamedClientRegistrations { get; } = new Dictionary<string, Type>();
1917
}
2018
}

0 commit comments

Comments
 (0)