diff --git a/Directory.Build.props b/Directory.Build.props
index 9d86b4fa778..33383a24a88 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -55,7 +55,7 @@
-
+
diff --git a/eng/ProjectReferences.props b/eng/ProjectReferences.props
index 4340aa36c00..f5d77a5ec8f 100644
--- a/eng/ProjectReferences.props
+++ b/eng/ProjectReferences.props
@@ -56,7 +56,6 @@
-
diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml
index 74bceb7221f..48175e9ca66 100644
--- a/eng/Version.Details.xml
+++ b/eng/Version.Details.xml
@@ -10,73 +10,73 @@
-->
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
https://github.com/dotnet/corefx
@@ -96,9 +96,9 @@
https://github.com/dotnet/arcade
250782df013aa8586e21bb225f8efd715372dcf1
-
+
https://github.com/dotnet/runtime
- f57d49bb711fda8ac0bd231229d91919f4fca8e8
+ 5c9338e09ad0a2f282c3dd14b0cc06aab37887a0
https://github.com/dotnet/roslyn
diff --git a/eng/Versions.props b/eng/Versions.props
index c3844def76c..cd301920684 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -55,26 +55,26 @@
-->
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
- 2.1.0-alpha.1.20064.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
+ 2.1.0-alpha.1.20065.4
1.0.0
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
- 5.0.0-alpha.1.20064.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
+ 5.0.0-alpha.1.20065.4
- 5.0.0-alpha.1.20064.4
+ 5.0.0-alpha.1.20065.4
5.0.0-beta.20062.1
diff --git a/src/Hosting/IntegrationTesting/src/Microsoft.Extensions.Hosting.IntegrationTesting.csproj b/src/Hosting/IntegrationTesting/src/Microsoft.Extensions.Hosting.IntegrationTesting.csproj
index 74e72701e30..1bc0de97a55 100644
--- a/src/Hosting/IntegrationTesting/src/Microsoft.Extensions.Hosting.IntegrationTesting.csproj
+++ b/src/Hosting/IntegrationTesting/src/Microsoft.Extensions.Hosting.IntegrationTesting.csproj
@@ -15,7 +15,6 @@
-
diff --git a/src/HttpClientFactory/Http/src/DependencyInjection/HttpClientBuilderExtensions.cs b/src/HttpClientFactory/Http/src/DependencyInjection/HttpClientBuilderExtensions.cs
index 3dd496394ad..5adcd907972 100644
--- a/src/HttpClientFactory/Http/src/DependencyInjection/HttpClientBuilderExtensions.cs
+++ b/src/HttpClientFactory/Http/src/DependencyInjection/HttpClientBuilderExtensions.cs
@@ -324,7 +324,13 @@ public static IHttpClientBuilder AddTypedClient(this IHttpClientBuilder
throw new ArgumentNullException(nameof(builder));
}
- ReserveClient(builder, typeof(TClient), builder.Name);
+ return AddTypedClientCore(builder, validateSingleType: false);
+ }
+
+ internal static IHttpClientBuilder AddTypedClientCore(this IHttpClientBuilder builder, bool validateSingleType)
+ where TClient : class
+ {
+ ReserveClient(builder, typeof(TClient), builder.Name, validateSingleType);
builder.Services.AddTransient(s =>
{
@@ -378,7 +384,14 @@ public static IHttpClientBuilder AddTypedClient(this I
throw new ArgumentNullException(nameof(builder));
}
- ReserveClient(builder, typeof(TClient), builder.Name);
+ return AddTypedClientCore(builder, validateSingleType: false);
+ }
+
+ internal static IHttpClientBuilder AddTypedClientCore(this IHttpClientBuilder builder, bool validateSingleType)
+ where TClient : class
+ where TImplementation : class, TClient
+ {
+ ReserveClient(builder, typeof(TClient), builder.Name, validateSingleType);
builder.Services.AddTransient(s =>
{
@@ -426,7 +439,13 @@ public static IHttpClientBuilder AddTypedClient(this IHttpClientBuilder
throw new ArgumentNullException(nameof(factory));
}
- ReserveClient(builder, typeof(TClient), builder.Name);
+ return AddTypedClientCore(builder, factory, validateSingleType: false);
+ }
+
+ internal static IHttpClientBuilder AddTypedClientCore(this IHttpClientBuilder builder, Func factory, bool validateSingleType)
+ where TClient : class
+ {
+ ReserveClient(builder, typeof(TClient), builder.Name, validateSingleType);
builder.Services.AddTransient(s =>
{
@@ -473,7 +492,23 @@ public static IHttpClientBuilder AddTypedClient(this IHttpClientBuilder
throw new ArgumentNullException(nameof(factory));
}
- ReserveClient(builder, typeof(TClient), builder.Name);
+ return AddTypedClientCore(builder, factory, validateSingleType: false);
+ }
+
+ internal static IHttpClientBuilder AddTypedClientCore(this IHttpClientBuilder builder, Func factory, bool validateSingleType)
+ where TClient : class
+ {
+ if (builder == null)
+ {
+ throw new ArgumentNullException(nameof(builder));
+ }
+
+ if (factory == null)
+ {
+ throw new ArgumentNullException(nameof(factory));
+ }
+
+ ReserveClient(builder, typeof(TClient), builder.Name, validateSingleType);
builder.Services.AddTransient(s =>
{
@@ -583,23 +618,19 @@ public static IHttpClientBuilder SetHandlerLifetime(this IHttpClientBuilder buil
}
// See comments on HttpClientMappingRegistry.
- private static void ReserveClient(IHttpClientBuilder builder, Type type, string name)
+ private static void ReserveClient(IHttpClientBuilder builder, Type type, string name, bool validateSingleType)
{
var registry = (HttpClientMappingRegistry)builder.Services.Single(sd => sd.ServiceType == typeof(HttpClientMappingRegistry)).ImplementationInstance;
Debug.Assert(registry != null);
- // Check for same type registered twice. This can't work because typed clients have to be unique for DI to function.
- if (registry.TypedClientRegistrations.TryGetValue(type, out var otherName))
- {
- var message =
- $"The HttpClient factory already has a registered client with the type '{type.FullName}'. " +
- $"Client types must be unique. " +
- $"Consider using inheritance to create multiple unique types with the same API surface.";
- throw new InvalidOperationException(message);
- }
-
// Check for same name registered to two types. This won't work because we rely on named options for the configuration.
- if (registry.NamedClientRegistrations.TryGetValue(name, out var otherType))
+ if (registry.NamedClientRegistrations.TryGetValue(name, out var otherType) &&
+
+ // Allow using the same name with multiple types in some cases (see callers).
+ validateSingleType &&
+
+ // Allow registering the same name twice to the same type.
+ type != otherType)
{
var message =
$"The HttpClient factory already has a registered client with the name '{name}', bound to the type '{otherType.FullName}'. " +
@@ -608,8 +639,10 @@ private static void ReserveClient(IHttpClientBuilder builder, Type type, string
throw new InvalidOperationException(message);
}
- registry.TypedClientRegistrations[type] = name;
- registry.NamedClientRegistrations[name] = type;
+ if (validateSingleType)
+ {
+ registry.NamedClientRegistrations[name] = type;
+ }
}
}
}
diff --git a/src/HttpClientFactory/Http/src/DependencyInjection/HttpClientFactoryServiceCollectionExtensions.cs b/src/HttpClientFactory/Http/src/DependencyInjection/HttpClientFactoryServiceCollectionExtensions.cs
index 9351aef3b68..eda6e893099 100644
--- a/src/HttpClientFactory/Http/src/DependencyInjection/HttpClientFactoryServiceCollectionExtensions.cs
+++ b/src/HttpClientFactory/Http/src/DependencyInjection/HttpClientFactoryServiceCollectionExtensions.cs
@@ -210,7 +210,7 @@ public static IHttpClientBuilder AddHttpClient(this IServiceCollection
var name = TypeNameHelper.GetTypeDisplayName(typeof(TClient), fullName: false);
var builder = new DefaultHttpClientBuilder(services, name);
- builder.AddTypedClient();
+ builder.AddTypedClientCore(validateSingleType: true);
return builder;
}
@@ -253,7 +253,7 @@ public static IHttpClientBuilder AddHttpClient(this IS
var name = TypeNameHelper.GetTypeDisplayName(typeof(TClient), fullName: false);
var builder = new DefaultHttpClientBuilder(services, name);
- builder.AddTypedClient();
+ builder.AddTypedClientCore(validateSingleType: true);
return builder;
}
@@ -298,7 +298,7 @@ public static IHttpClientBuilder AddHttpClient(this IServiceCollection
AddHttpClient(services);
var builder = new DefaultHttpClientBuilder(services, name);
- builder.AddTypedClient();
+ builder.AddTypedClientCore(validateSingleType: false); // Name was explicitly provided.
return builder;
}
@@ -349,7 +349,7 @@ public static IHttpClientBuilder AddHttpClient(this IS
AddHttpClient(services);
var builder = new DefaultHttpClientBuilder(services, name);
- builder.AddTypedClient();
+ builder.AddTypedClientCore(validateSingleType: false); // name was explicitly provided
return builder;
}
@@ -394,7 +394,7 @@ public static IHttpClientBuilder AddHttpClient(this IServiceCollection
var name = TypeNameHelper.GetTypeDisplayName(typeof(TClient), fullName: false);
var builder = new DefaultHttpClientBuilder(services, name);
builder.ConfigureHttpClient(configureClient);
- builder.AddTypedClient();
+ builder.AddTypedClientCore(validateSingleType: true);
return builder;
}
@@ -439,7 +439,7 @@ public static IHttpClientBuilder AddHttpClient(this IServiceCollection
var name = TypeNameHelper.GetTypeDisplayName(typeof(TClient), fullName: false);
var builder = new DefaultHttpClientBuilder(services, name);
builder.ConfigureHttpClient(configureClient);
- builder.AddTypedClient();
+ builder.AddTypedClientCore(validateSingleType: true);
return builder;
}
@@ -489,7 +489,7 @@ public static IHttpClientBuilder AddHttpClient(this IS
var name = TypeNameHelper.GetTypeDisplayName(typeof(TClient), fullName: false);
var builder = new DefaultHttpClientBuilder(services, name);
builder.ConfigureHttpClient(configureClient);
- builder.AddTypedClient();
+ builder.AddTypedClientCore(validateSingleType: true);
return builder;
}
@@ -539,7 +539,7 @@ public static IHttpClientBuilder AddHttpClient(this IS
var name = TypeNameHelper.GetTypeDisplayName(typeof(TClient), fullName: false);
var builder = new DefaultHttpClientBuilder(services, name);
builder.ConfigureHttpClient(configureClient);
- builder.AddTypedClient();
+ builder.AddTypedClientCore(validateSingleType: true);
return builder;
}
@@ -591,7 +591,7 @@ public static IHttpClientBuilder AddHttpClient(this IServiceCollection
var builder = new DefaultHttpClientBuilder(services, name);
builder.ConfigureHttpClient(configureClient);
- builder.AddTypedClient();
+ builder.AddTypedClientCore(validateSingleType: false); // name was explicitly provided
return builder;
}
@@ -643,7 +643,7 @@ public static IHttpClientBuilder AddHttpClient(this IServiceCollection
var builder = new DefaultHttpClientBuilder(services, name);
builder.ConfigureHttpClient(configureClient);
- builder.AddTypedClient();
+ builder.AddTypedClientCore(validateSingleType: false); // name was explictly provided
return builder;
}
@@ -700,7 +700,7 @@ public static IHttpClientBuilder AddHttpClient(this IS
var builder = new DefaultHttpClientBuilder(services, name);
builder.ConfigureHttpClient(configureClient);
- builder.AddTypedClient();
+ builder.AddTypedClientCore(validateSingleType: false); // name was explicitly provided
return builder;
}
@@ -757,7 +757,7 @@ public static IHttpClientBuilder AddHttpClient(this IS
var builder = new DefaultHttpClientBuilder(services, name);
builder.ConfigureHttpClient(configureClient);
- builder.AddTypedClient();
+ builder.AddTypedClientCore(validateSingleType: false); // name was explicitly provided
return builder;
}
}
diff --git a/src/HttpClientFactory/Http/src/DependencyInjection/HttpClientMappingRegistry.cs b/src/HttpClientFactory/Http/src/DependencyInjection/HttpClientMappingRegistry.cs
index 7537293808d..42839d675bb 100644
--- a/src/HttpClientFactory/Http/src/DependencyInjection/HttpClientMappingRegistry.cs
+++ b/src/HttpClientFactory/Http/src/DependencyInjection/HttpClientMappingRegistry.cs
@@ -13,8 +13,6 @@ namespace Microsoft.Extensions.DependencyInjection
// See: https://github.com/dotnet/extensions/issues/960
internal class HttpClientMappingRegistry
{
- public Dictionary TypedClientRegistrations { get; } = new Dictionary();
-
public Dictionary NamedClientRegistrations { get; } = new Dictionary();
}
}
diff --git a/src/HttpClientFactory/Http/test/DependencyInjection/HttpClientFactoryServiceCollectionExtensionsTest.cs b/src/HttpClientFactory/Http/test/DependencyInjection/HttpClientFactoryServiceCollectionExtensionsTest.cs
index 0f2efd748fc..82f5b811e1b 100644
--- a/src/HttpClientFactory/Http/test/DependencyInjection/HttpClientFactoryServiceCollectionExtensionsTest.cs
+++ b/src/HttpClientFactory/Http/test/DependencyInjection/HttpClientFactoryServiceCollectionExtensionsTest.cs
@@ -2,6 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
@@ -26,7 +29,7 @@ public void AddHttpClient_IsSelfContained_CanCreateClient()
var serviceCollection = new ServiceCollection();
// Act1
- serviceCollection.AddHttpClient();
+ serviceCollection.AddHttpClient();
var services = serviceCollection.BuildServiceProvider();
var options = services.GetRequiredService>();
@@ -383,39 +386,82 @@ public void AddHttpClient_AddTypedClient_WithDelegate_ConfiguresNamedClient()
}
[Fact]
- public void AddHttpClient_AddSameTypedClientTwice_ThrowsError()
+ public void AddHttpClient_AddSameTypedClientTwice_WithSameName_Works()
{
// Arrange
var serviceCollection = new ServiceCollection();
serviceCollection.AddHttpClient();
// Act
- var ex = Assert.Throws(() => serviceCollection.AddHttpClient("Test"));
+ serviceCollection.AddHttpClient(c =>
+ {
+ c.BaseAddress = new Uri("http://example.com");
+ });
+
+ var services = serviceCollection.BuildServiceProvider();
+
+ // Act2
+ var client = services.GetRequiredService();
// Assert
- Assert.Equal(
- "The HttpClient factory already has a registered client with the type 'Microsoft.Extensions.Http.TestTypedClient'. " +
- "Client types must be unique. " +
- "Consider using inheritance to create multiple unique types with the same API surface.",
- ex.Message);
+ Assert.Equal("http://example.com/", client.HttpClient.BaseAddress.AbsoluteUri);
}
[Fact]
- public void AddHttpClient_AddSameTypedClientTwice_WithAddTypedClient_ThrowsError()
+ public void AddHttpClient_AddSameTypedClientTwice_WithSameName_WithAddTypedClient_Works()
{
// Arrange
var serviceCollection = new ServiceCollection();
serviceCollection.AddHttpClient();
// Act
- var ex = Assert.Throws(() => serviceCollection.AddHttpClient("Test").AddTypedClient());
+ serviceCollection.AddHttpClient(nameof(TestTypedClient), c =>
+ {
+ c.BaseAddress = new Uri("http://example.com");
+ })
+ .AddTypedClient();
+
+ var services = serviceCollection.BuildServiceProvider();
+
+ // Act2
+ var client = services.GetRequiredService();
// Assert
- Assert.Equal(
- "The HttpClient factory already has a registered client with the type 'Microsoft.Extensions.Http.TestTypedClient'. " +
- "Client types must be unique. " +
- "Consider using inheritance to create multiple unique types with the same API surface.",
- ex.Message);
+ Assert.Equal("http://example.com/", client.HttpClient.BaseAddress.AbsoluteUri);
+ }
+
+ [Fact]
+ public void AddHttpClient_AddSameTypedClientTwice_WithDifferentNames_IsAllowed()
+ {
+ // Arrange
+ var serviceCollection = new ServiceCollection();
+ serviceCollection.AddHttpClient("Test1");
+ serviceCollection.AddHttpClient("Test2");
+
+ var services = serviceCollection.BuildServiceProvider();
+
+ // Act
+ var clients = services.GetRequiredService>();
+
+ // Assert
+ Assert.Equal(2, clients.Count());
+ }
+
+ [Fact]
+ public void AddHttpClient_AddSameTypedClientTwice_WithDifferentNames_WithAddTypedClient_IsAllowed()
+ {
+ // Arrange
+ var serviceCollection = new ServiceCollection();
+ serviceCollection.AddHttpClient();
+ serviceCollection.AddHttpClient("Test").AddTypedClient();
+
+ var services = serviceCollection.BuildServiceProvider();
+
+ // Act
+ var clients = services.GetRequiredService>();
+
+ // Assert
+ Assert.Equal(2, clients.Count());
}
[Fact]
@@ -437,21 +483,88 @@ public void AddHttpClient_AddSameNameWithTypedClientTwice_ThrowsError()
}
[Fact]
- public void AddHttpClient_AddSameNameWithTypedClientTwice_WithAddTypedClient_ThrowsError()
+ public void AddHttpClient_AddSameNameWithTypedClientTwice_WithAddTypedClient_IsAllowed()
{
// Arrange
var serviceCollection = new ServiceCollection();
- serviceCollection.AddHttpClient();
+ serviceCollection.AddHttpClient(c =>
+ {
+ c.BaseAddress = new Uri("http://example.com");
+ });
+
+ // Act
+ serviceCollection.AddHttpClient("TestTypedClient").AddTypedClient();
+
+ var services = serviceCollection.BuildServiceProvider();
// Act
- var ex = Assert.Throws(() => serviceCollection.AddHttpClient("TestTypedClient").AddTypedClient());
+ var client = services.GetRequiredService();
// Assert
- Assert.Equal(
- "The HttpClient factory already has a registered client with the name 'TestTypedClient', bound to the type 'Microsoft.Extensions.Http.TestTypedClient'. " +
- "Client names are computed based on the type name without considering the namespace ('TestTypedClient'). " +
- "Use an overload of AddHttpClient that accepts a string and provide a unique name to resolve the conflict.",
- ex.Message);
+ Assert.Equal("http://example.com/", client.HttpClient.BaseAddress.AbsoluteUri);
+
+ // Act
+ var client2 = services.GetRequiredService();
+
+ // Assert
+ Assert.Equal("http://example.com/", client2.HttpClient.BaseAddress.AbsoluteUri);
+ }
+
+ [Fact]
+ public void AddHttpClient_AddSameNameWithTypedClientTwice_WithExplicitName_IsAllowed()
+ {
+ // Arrange
+ var serviceCollection = new ServiceCollection();
+ serviceCollection.AddHttpClient(c =>
+ {
+ c.BaseAddress = new Uri("http://example.com");
+ });
+
+ // Act
+ serviceCollection.AddHttpClient("TestTypedClient");
+
+ var services = serviceCollection.BuildServiceProvider();
+
+ // Act
+ var client = services.GetRequiredService();
+
+ // Assert
+ Assert.Equal("http://example.com/", client.HttpClient.BaseAddress.AbsoluteUri);
+
+ // Act
+ var client2 = services.GetRequiredService();
+
+ // Assert
+ Assert.Equal("http://example.com/", client2.HttpClient.BaseAddress.AbsoluteUri);
+ }
+
+ [Fact]
+ public void AddHttpClient_RegisteringMultipleTypes_WithAddTypedClient_IsAllowed()
+ {
+ // Arrange
+ var serviceCollection = new ServiceCollection();
+
+ // Act
+ serviceCollection.AddHttpClient("Test", c =>
+ {
+ c.BaseAddress = new Uri("http://example.com");
+ })
+ .AddTypedClient()
+ .AddTypedClient();
+
+ var services = serviceCollection.BuildServiceProvider();
+
+ // Act
+ var client = services.GetRequiredService();
+
+ // Assert
+ Assert.Equal("http://example.com/", client.HttpClient.BaseAddress.AbsoluteUri);
+
+ // Act
+ var client2 = services.GetRequiredService();
+
+ // Assert
+ Assert.Equal("http://example.com/", client2.HttpClient.BaseAddress.AbsoluteUri);
}
[Fact]
@@ -466,7 +579,7 @@ public void AddHttpClient_AddTypedClient_WithServiceDelegate_ConfiguresNamedClie
});
// Act
- serviceCollection.AddHttpClient("test").AddTypedClient((c,s) =>
+ serviceCollection.AddHttpClient("test").AddTypedClient((c, s) =>
{
Assert.Equal("http://example.com/", c.BaseAddress.AbsoluteUri);
c.BaseAddress = new Uri("http://example2.com");
@@ -555,7 +668,7 @@ public void AddHttpClient_WithTypedClient_AndServiceDelegate_ConfiguresClient()
});
// Act1
- serviceCollection.AddHttpClient((s,c) =>
+ serviceCollection.AddHttpClient((s, c) =>
{
var options = s.GetRequiredService>();
c.BaseAddress = new Uri(options.Value.BaseAddress);
@@ -565,7 +678,7 @@ public void AddHttpClient_WithTypedClient_AndServiceDelegate_ConfiguresClient()
// Act2
var client = services.GetRequiredService();
-
+
// Assert
Assert.Equal("http://example.com/", client.HttpClient.BaseAddress.AbsoluteUri);
}
@@ -582,7 +695,7 @@ public void AddHttpClient_WithTypedClientAndImplementation_AndServiceDelegate_Co
});
// Act1
- serviceCollection.AddHttpClient((s,c) =>
+ serviceCollection.AddHttpClient((s, c) =>
{
var options = s.GetRequiredService>();
c.BaseAddress = new Uri(options.Value.BaseAddress);
@@ -592,7 +705,7 @@ public void AddHttpClient_WithTypedClientAndImplementation_AndServiceDelegate_Co
// Act2
var client = services.GetRequiredService();
-
+
// Assert
Assert.Equal("http://example.com/", client.HttpClient.BaseAddress.AbsoluteUri);
}
@@ -609,7 +722,7 @@ public void AddHttpClient_WithTypedClient_AndServiceDelegate_ConfiguresNamedClie
});
// Act1
- serviceCollection.AddHttpClient("test", (s,c) =>
+ serviceCollection.AddHttpClient("test", (s, c) =>
{
var options = s.GetRequiredService>();
c.BaseAddress = new Uri(options.Value.BaseAddress);
@@ -619,7 +732,7 @@ public void AddHttpClient_WithTypedClient_AndServiceDelegate_ConfiguresNamedClie
// Act2
var client = services.GetRequiredService();
-
+
// Assert
Assert.Equal("http://example.com/", client.HttpClient.BaseAddress.AbsoluteUri);
}
@@ -636,7 +749,7 @@ public void AddHttpClient_WithTypedClientAndImplementation_AndServiceDelegate_Co
});
// Act1
- serviceCollection.AddHttpClient("test", (s,c) =>
+ serviceCollection.AddHttpClient("test", (s, c) =>
{
var options = s.GetRequiredService>();
c.BaseAddress = new Uri(options.Value.BaseAddress);
@@ -646,7 +759,7 @@ public void AddHttpClient_WithTypedClientAndImplementation_AndServiceDelegate_Co
// Act2
var client = services.GetRequiredService();
-
+
// Assert
Assert.Equal("http://example.com/", client.HttpClient.BaseAddress.AbsoluteUri);
}
@@ -1162,6 +1275,9 @@ public class TestTypedClient
{
public TestTypedClient(HttpClient httpClient)
{
+ HttpClient = httpClient;
}
+
+ public HttpClient HttpClient { get; }
}
}
diff --git a/src/Logging/Logging.Testing/src/Microsoft.Extensions.Logging.Testing.csproj b/src/Logging/Logging.Testing/src/Microsoft.Extensions.Logging.Testing.csproj
index 0670cffcc90..0c07c01c103 100644
--- a/src/Logging/Logging.Testing/src/Microsoft.Extensions.Logging.Testing.csproj
+++ b/src/Logging/Logging.Testing/src/Microsoft.Extensions.Logging.Testing.csproj
@@ -18,7 +18,7 @@
-
+
diff --git a/src/TestingUtils/Microsoft.AspNetCore.Testing/ref/Microsoft.AspNetCore.Testing.csproj b/src/TestingUtils/Microsoft.AspNetCore.Testing/ref/Microsoft.AspNetCore.Testing.csproj
deleted file mode 100644
index 4606a541110..00000000000
--- a/src/TestingUtils/Microsoft.AspNetCore.Testing/ref/Microsoft.AspNetCore.Testing.csproj
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
- netstandard2.0;net46
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/TestingUtils/Microsoft.AspNetCore.Testing/ref/Microsoft.AspNetCore.Testing.net46.cs b/src/TestingUtils/Microsoft.AspNetCore.Testing/ref/Microsoft.AspNetCore.Testing.net46.cs
deleted file mode 100644
index 17a922a6c7b..00000000000
--- a/src/TestingUtils/Microsoft.AspNetCore.Testing/ref/Microsoft.AspNetCore.Testing.net46.cs
+++ /dev/null
@@ -1,374 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-namespace Microsoft.AspNetCore.Testing
-{
- public partial class AspNetTestAssemblyRunner : Xunit.Sdk.XunitTestAssemblyRunner
- {
- public AspNetTestAssemblyRunner(Xunit.Abstractions.ITestAssembly testAssembly, System.Collections.Generic.IEnumerable testCases, Xunit.Abstractions.IMessageSink diagnosticMessageSink, Xunit.Abstractions.IMessageSink executionMessageSink, Xunit.Abstractions.ITestFrameworkExecutionOptions executionOptions) : base (default(Xunit.Abstractions.ITestAssembly), default(System.Collections.Generic.IEnumerable), default(Xunit.Abstractions.IMessageSink), default(Xunit.Abstractions.IMessageSink), default(Xunit.Abstractions.ITestFrameworkExecutionOptions)) { }
- [System.Diagnostics.DebuggerStepThroughAttribute]
- protected override System.Threading.Tasks.Task AfterTestAssemblyStartingAsync() { throw null; }
- protected override System.Threading.Tasks.Task BeforeTestAssemblyFinishedAsync() { throw null; }
- protected override System.Threading.Tasks.Task RunTestCollectionAsync(Xunit.Sdk.IMessageBus messageBus, Xunit.Abstractions.ITestCollection testCollection, System.Collections.Generic.IEnumerable testCases, System.Threading.CancellationTokenSource cancellationTokenSource) { throw null; }
- }
- public partial class AspNetTestCollectionRunner : Xunit.Sdk.XunitTestCollectionRunner
- {
- public AspNetTestCollectionRunner(System.Collections.Generic.Dictionary assemblyFixtureMappings, Xunit.Abstractions.ITestCollection testCollection, System.Collections.Generic.IEnumerable testCases, Xunit.Abstractions.IMessageSink diagnosticMessageSink, Xunit.Sdk.IMessageBus messageBus, Xunit.Sdk.ITestCaseOrderer testCaseOrderer, Xunit.Sdk.ExceptionAggregator aggregator, System.Threading.CancellationTokenSource cancellationTokenSource) : base (default(Xunit.Abstractions.ITestCollection), default(System.Collections.Generic.IEnumerable), default(Xunit.Abstractions.IMessageSink), default(Xunit.Sdk.IMessageBus), default(Xunit.Sdk.ITestCaseOrderer), default(Xunit.Sdk.ExceptionAggregator), default(System.Threading.CancellationTokenSource)) { }
- [System.Diagnostics.DebuggerStepThroughAttribute]
- protected override System.Threading.Tasks.Task AfterTestCollectionStartingAsync() { throw null; }
- protected override System.Threading.Tasks.Task BeforeTestCollectionFinishedAsync() { throw null; }
- protected override System.Threading.Tasks.Task RunTestClassAsync(Xunit.Abstractions.ITestClass testClass, Xunit.Abstractions.IReflectionTypeInfo @class, System.Collections.Generic.IEnumerable testCases) { throw null; }
- }
- public partial class AspNetTestFramework : Xunit.Sdk.XunitTestFramework
- {
- public AspNetTestFramework(Xunit.Abstractions.IMessageSink messageSink) : base (default(Xunit.Abstractions.IMessageSink)) { }
- protected override Xunit.Abstractions.ITestFrameworkExecutor CreateExecutor(System.Reflection.AssemblyName assemblyName) { throw null; }
- }
- public partial class AspNetTestFrameworkExecutor : Xunit.Sdk.XunitTestFrameworkExecutor
- {
- public AspNetTestFrameworkExecutor(System.Reflection.AssemblyName assemblyName, Xunit.Abstractions.ISourceInformationProvider sourceInformationProvider, Xunit.Abstractions.IMessageSink diagnosticMessageSink) : base (default(System.Reflection.AssemblyName), default(Xunit.Abstractions.ISourceInformationProvider), default(Xunit.Abstractions.IMessageSink)) { }
- [System.Diagnostics.DebuggerStepThroughAttribute]
- protected override void RunTestCases(System.Collections.Generic.IEnumerable testCases, Xunit.Abstractions.IMessageSink executionMessageSink, Xunit.Abstractions.ITestFrameworkExecutionOptions executionOptions) { }
- }
- [System.AttributeUsageAttribute(System.AttributeTargets.Assembly, AllowMultiple=true)]
- public partial class AssemblyFixtureAttribute : System.Attribute
- {
- public AssemblyFixtureAttribute(System.Type fixtureType) { }
- public System.Type FixtureType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
- }
- [System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple=false)]
- [Xunit.Sdk.XunitTestCaseDiscovererAttribute("Microsoft.AspNetCore.Testing.ConditionalFactDiscoverer", "Microsoft.AspNetCore.Testing")]
- public partial class ConditionalFactAttribute : Xunit.FactAttribute
- {
- public ConditionalFactAttribute() { }
- }
- [System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple=false)]
- [Xunit.Sdk.XunitTestCaseDiscovererAttribute("Microsoft.AspNetCore.Testing.ConditionalTheoryDiscoverer", "Microsoft.AspNetCore.Testing")]
- public partial class ConditionalTheoryAttribute : Xunit.TheoryAttribute
- {
- public ConditionalTheoryAttribute() { }
- }
- public partial class CultureReplacer : System.IDisposable
- {
- public CultureReplacer(System.Globalization.CultureInfo culture, System.Globalization.CultureInfo uiCulture) { }
- public CultureReplacer(string culture = "en-GB", string uiCulture = "en-US") { }
- public static System.Globalization.CultureInfo DefaultCulture { get { throw null; } }
- public static string DefaultCultureName { get { throw null; } }
- public static string DefaultUICultureName { get { throw null; } }
- public void Dispose() { }
- }
- [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=true, AllowMultiple=false)]
- public sealed partial class DockerOnlyAttribute : System.Attribute, Microsoft.AspNetCore.Testing.ITestCondition
- {
- public DockerOnlyAttribute() { }
- public bool IsMet { get { throw null; } }
- public string SkipReason { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
- }
- [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
- public partial class EnvironmentVariableSkipConditionAttribute : System.Attribute, Microsoft.AspNetCore.Testing.ITestCondition
- {
- public EnvironmentVariableSkipConditionAttribute(string variableName, params string[] values) { }
- public bool IsMet { get { throw null; } }
- public bool RunOnMatch { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
- public string SkipReason { get { throw null; } }
- }
- public static partial class ExceptionAssert
- {
- public static System.ArgumentException ThrowsArgument(System.Action testCode, string paramName, string exceptionMessage) { throw null; }
- public static System.Threading.Tasks.Task ThrowsArgumentAsync(System.Func testCode, string paramName, string exceptionMessage) { throw null; }
- public static System.ArgumentNullException ThrowsArgumentNull(System.Action testCode, string paramName) { throw null; }
- public static System.ArgumentException ThrowsArgumentNullOrEmpty(System.Action testCode, string paramName) { throw null; }
- public static System.Threading.Tasks.Task ThrowsArgumentNullOrEmptyAsync(System.Func testCode, string paramName) { throw null; }
- public static System.ArgumentException ThrowsArgumentNullOrEmptyString(System.Action testCode, string paramName) { throw null; }
- public static System.Threading.Tasks.Task ThrowsArgumentNullOrEmptyStringAsync(System.Func testCode, string paramName) { throw null; }
- public static System.ArgumentOutOfRangeException ThrowsArgumentOutOfRange(System.Action testCode, string paramName, string exceptionMessage, object actualValue = null) { throw null; }
- [System.Diagnostics.DebuggerStepThroughAttribute]
- public static System.Threading.Tasks.Task ThrowsAsync(System.Func testCode, string exceptionMessage) where TException : System.Exception { throw null; }
- public static TException Throws(System.Action testCode) where TException : System.Exception { throw null; }
- public static TException Throws(System.Action testCode, string exceptionMessage) where TException : System.Exception { throw null; }
- public static TException Throws(System.Func