44using System ;
55using System . Diagnostics . CodeAnalysis ;
66using System . Linq ;
7+ using System . Threading ;
78using Microsoft . Extensions . Compliance . Redaction ;
89using Microsoft . Extensions . Compliance . Testing ;
910using Microsoft . Extensions . DependencyInjection ;
11+ using Microsoft . Extensions . DependencyInjection . Extensions ;
12+ using Microsoft . Extensions . Logging ;
13+ using Microsoft . Extensions . Logging . Abstractions ;
1014using Microsoft . Extensions . Telemetry . Metering ;
1115
1216#pragma warning disable R9A033 // Replace uses of 'Enum.GetName' and 'Enum.ToString' with the '[EnumStrings]' code generator for improved performance
@@ -24,6 +28,10 @@ public enum HedgingClientType
2428
2529internal static class HttpClientFactory
2630{
31+ internal const string EmptyClient = "Empty" ;
32+
33+ internal const string StandardClient = "Standard" ;
34+
2735 private const string HedgingEndpoint1 = "http://localhost1" ;
2836 private const string HedgingEndpoint2 = "http://localhost2" ;
2937
@@ -34,14 +42,25 @@ public static ServiceProvider InitializeServiceProvider(HedgingClientType client
3442 . RegisterMetering ( )
3543 . AddSingleton < IRedactorProvider > ( NullRedactorProvider . Instance )
3644 . AddTransient < NoRemoteCallHandler > ( )
37- . AddHedging ( clientType ) ;
45+ . AddHedging ( clientType )
46+ . AddHttpClient ( StandardClient , client => client . Timeout = Timeout . InfiniteTimeSpan )
47+ . AddStandardResilienceHandler ( )
48+ . Services
49+ . AddHttpClient ( StandardClient )
50+ . AddHttpMessageHandler < NoRemoteCallHandler > ( )
51+ . Services
52+ . AddHttpClient ( EmptyClient , client => client . Timeout = Timeout . InfiniteTimeSpan )
53+ . AddHttpMessageHandler < NoRemoteCallHandler > ( ) ;
54+
55+ services . RemoveAll < ILoggerFactory > ( ) ;
56+ services . AddSingleton < ILoggerFactory > ( NullLoggerFactory . Instance ) ;
3857
3958 return services . BuildServiceProvider ( ) ;
4059 }
4160
4261 private static IServiceCollection AddHedging ( this IServiceCollection services , HedgingClientType clientType )
4362 {
44- var clientBuilder = services . AddHttpClient ( clientType . ToString ( ) ) ;
63+ var clientBuilder = services . AddHttpClient ( clientType . ToString ( ) , client => client . Timeout = Timeout . InfiniteTimeSpan ) ;
4564 var hedgingBuilder = clientBuilder . AddStandardHedgingHandler ( ) . SelectPipelineByAuthority ( SimpleClassifications . PublicData ) ;
4665 _ = clientBuilder . AddHttpMessageHandler < NoRemoteCallHandler > ( ) ;
4766
0 commit comments