12
12
using System . Collections . Generic ;
13
13
using System . Linq ;
14
14
using System . Net . Http ;
15
+ using System . Threading ;
15
16
using System . Threading . Tasks ;
16
17
17
18
namespace Microsoft . Extensions . Configuration . AzureAppConfiguration
@@ -34,6 +35,10 @@ public class AzureAppConfigurationOptions : IDisposable
34
35
private List < KeyValueSelector > _selectors ;
35
36
private IConfigurationRefresher _refresher = new AzureAppConfigurationRefresher ( ) ;
36
37
private bool _selectCalled = false ;
38
+ private static HttpClientTransport _clientOptionsTransport = new HttpClientTransport ( new HttpClient ( )
39
+ {
40
+ Timeout = NetworkTimeout
41
+ } ) ;
37
42
38
43
// The following set is sorted in descending order.
39
44
// Since multiple prefixes could start with the same characters, we need to trim the longest prefix first.
@@ -150,11 +155,6 @@ internal IEnumerable<IKeyValueAdapter> Adapters
150
155
/// </summary>
151
156
internal StartupOptions Startup { get ; set ; } = new StartupOptions ( ) ;
152
157
153
- /// <summary>
154
- /// Transport used by <see cref="ClientOptions"/>, stored for disposal.
155
- /// </summary>
156
- internal HttpClientTransport ClientOptionsTransport { get ; private set ; } = null ;
157
-
158
158
/// <summary>
159
159
/// Initializes a new instance of the <see cref="AzureAppConfigurationOptions"/> class.
160
160
/// </summary>
@@ -511,18 +511,14 @@ public AzureAppConfigurationOptions ConfigureStartupOptions(Action<StartupOption
511
511
return this ;
512
512
}
513
513
514
- private ConfigurationClientOptions GetDefaultClientOptions ( )
514
+ private static ConfigurationClientOptions GetDefaultClientOptions ( )
515
515
{
516
516
var clientOptions = new ConfigurationClientOptions ( ConfigurationClientOptions . ServiceVersion . V2023_10_01 ) ;
517
517
clientOptions . Retry . MaxRetries = MaxRetries ;
518
518
clientOptions . Retry . MaxDelay = MaxRetryDelay ;
519
519
clientOptions . Retry . Mode = RetryMode . Exponential ;
520
520
clientOptions . AddPolicy ( new UserAgentHeaderPolicy ( ) , HttpPipelinePosition . PerCall ) ;
521
- ClientOptionsTransport = new HttpClientTransport ( new HttpClient ( )
522
- {
523
- Timeout = NetworkTimeout
524
- } ) ;
525
- clientOptions . Transport = ClientOptionsTransport ;
521
+ clientOptions . Transport = _clientOptionsTransport ;
526
522
527
523
return clientOptions ;
528
524
}
@@ -532,9 +528,9 @@ private ConfigurationClientOptions GetDefaultClientOptions()
532
528
/// </summary>
533
529
public void Dispose ( )
534
530
{
535
- if ( ClientOptionsTransport != null )
531
+ if ( _clientOptionsTransport != null )
536
532
{
537
- ClientOptionsTransport . Dispose ( ) ;
533
+ _clientOptionsTransport . Dispose ( ) ;
538
534
}
539
535
}
540
536
}
0 commit comments