@@ -19,16 +19,13 @@ public class EnvironmentDetail
1919 {
2020 private static EnvironmentDetail _CachedCopy = null ;
2121
22- public static EnvironmentDetail Get ( bool refresh )
22+ public static EnvironmentDetail Get ( )
2323 {
24- if ( refresh || _CachedCopy == null )
25- {
26- _CachedCopy = new EnvironmentDetail ( true ) ;
27- }
28-
29- return _CachedCopy ;
24+ return _CachedCopy ?? ( _CachedCopy = new EnvironmentDetail ( ) ) ;
3025 }
31-
26+ #if NETSTANDARD
27+ private static System . Net . Http . HttpClient Client => new System . Net . Http . HttpClient ( ) ;
28+ #endif
3229 private static bool registryAccessFailure = false ;
3330
3431 /// <summary>
@@ -209,43 +206,17 @@ public static async Task<string> GetEC2InstanceId()
209206 {
210207 string r = null ;
211208
212- // SF-6804: Frequent Calls to GetEC2InstanceId
213- bool skipEc2InstanceIdUpdate = false ;
214-
215- if ( Config . Ec2InstanceMetadataUpdateThresholdMinutes > 0 )
216- {
217- var threshold = TimeSpan . FromMinutes ( Config . Ec2InstanceMetadataUpdateThresholdMinutes ) ;
218- lock ( ec2InstanceLock )
219- {
220- skipEc2InstanceIdUpdate = ec2InstanceIdLastUpdate != null && ec2InstanceIdLastUpdate < DateTimeOffset . UtcNow . Subtract ( threshold ) ;
221- r = string . IsNullOrWhiteSpace ( ec2InstanceId ) ? null : ec2InstanceId ;
222- }
223- }
224- else
225- {
226- skipEc2InstanceIdUpdate = true ;
227- }
228-
229- if ( skipEc2InstanceIdUpdate )
230- {
231- return r ;
232- }
233-
234209 try
235210 {
211+ Client . Timeout = TimeSpan . FromSeconds ( 5 ) ;
212+ var content = await Client . GetAsync ( EC2InstanceIdUrl ) ;
236213
237- using ( var client = new System . Net . Http . HttpClient ( ) )
238- {
239- client . Timeout = TimeSpan . FromSeconds ( 5 ) ;
240- var content = await client . GetAsync ( EC2InstanceIdUrl ) ;
241-
242- int statusCode = ( int ) content . StatusCode ;
214+ int statusCode = ( int ) content . StatusCode ;
243215
244- if ( statusCode >= 200 && statusCode < 300 )
245- {
246- string id = await content . Content . ReadAsStringAsync ( ) ;
247- r = string . IsNullOrWhiteSpace ( id ) ? null : id ;
248- }
216+ if ( statusCode >= 200 && statusCode < 300 )
217+ {
218+ string id = await content . Content . ReadAsStringAsync ( ) ;
219+ r = string . IsNullOrWhiteSpace ( id ) ? null : id ;
249220 }
250221
251222 }
@@ -317,10 +288,8 @@ private void IsWindowService()
317288#endif
318289 }
319290
320- public EnvironmentDetail ( bool loadDetails )
291+ public EnvironmentDetail ( )
321292 {
322- if ( ! loadDetails )
323- return ;
324293
325294 bool isWebRequest = false ;
326295#if NETFULL
0 commit comments