diff --git a/eng/packages/General.props b/eng/packages/General.props index b74a6cd1f0..af9621dc0b 100644 --- a/eng/packages/General.props +++ b/eng/packages/General.props @@ -16,7 +16,6 @@ - diff --git a/src/Libraries/Microsoft.Extensions.AmbientMetadata.Application/Microsoft.Extensions.AmbientMetadata.Application.csproj b/src/Libraries/Microsoft.Extensions.AmbientMetadata.Application/Microsoft.Extensions.AmbientMetadata.Application.csproj index 5cc014f22c..2603f0b42f 100644 --- a/src/Libraries/Microsoft.Extensions.AmbientMetadata.Application/Microsoft.Extensions.AmbientMetadata.Application.csproj +++ b/src/Libraries/Microsoft.Extensions.AmbientMetadata.Application/Microsoft.Extensions.AmbientMetadata.Application.csproj @@ -19,7 +19,6 @@ - diff --git a/src/Libraries/Microsoft.Extensions.Compliance.Redaction/Microsoft.Extensions.Compliance.Redaction.csproj b/src/Libraries/Microsoft.Extensions.Compliance.Redaction/Microsoft.Extensions.Compliance.Redaction.csproj index 286a14ca69..8a6a526acc 100644 --- a/src/Libraries/Microsoft.Extensions.Compliance.Redaction/Microsoft.Extensions.Compliance.Redaction.csproj +++ b/src/Libraries/Microsoft.Extensions.Compliance.Redaction/Microsoft.Extensions.Compliance.Redaction.csproj @@ -26,11 +26,8 @@ - - - diff --git a/src/Libraries/Microsoft.Extensions.Compliance.Testing/Microsoft.Extensions.Compliance.Testing.csproj b/src/Libraries/Microsoft.Extensions.Compliance.Testing/Microsoft.Extensions.Compliance.Testing.csproj index ef2fcd70e7..85ebae934d 100644 --- a/src/Libraries/Microsoft.Extensions.Compliance.Testing/Microsoft.Extensions.Compliance.Testing.csproj +++ b/src/Libraries/Microsoft.Extensions.Compliance.Testing/Microsoft.Extensions.Compliance.Testing.csproj @@ -24,9 +24,7 @@ - - diff --git a/src/Libraries/Microsoft.Extensions.DependencyInjection.AutoActivation/Microsoft.Extensions.DependencyInjection.AutoActivation.csproj b/src/Libraries/Microsoft.Extensions.DependencyInjection.AutoActivation/Microsoft.Extensions.DependencyInjection.AutoActivation.csproj index 9b17c21e82..7d02c3f1e9 100644 --- a/src/Libraries/Microsoft.Extensions.DependencyInjection.AutoActivation/Microsoft.Extensions.DependencyInjection.AutoActivation.csproj +++ b/src/Libraries/Microsoft.Extensions.DependencyInjection.AutoActivation/Microsoft.Extensions.DependencyInjection.AutoActivation.csproj @@ -13,7 +13,6 @@ - diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Microsoft.Extensions.Diagnostics.Testing.csproj b/src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Microsoft.Extensions.Diagnostics.Testing.csproj index 618c6ba38b..01f3b95426 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Microsoft.Extensions.Diagnostics.Testing.csproj +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Microsoft.Extensions.Diagnostics.Testing.csproj @@ -25,11 +25,10 @@ - - + diff --git a/src/Libraries/Microsoft.Extensions.Hosting.Testing/Microsoft.Extensions.Hosting.Testing.csproj b/src/Libraries/Microsoft.Extensions.Hosting.Testing/Microsoft.Extensions.Hosting.Testing.csproj index 942468ef79..1cc91384dc 100644 --- a/src/Libraries/Microsoft.Extensions.Hosting.Testing/Microsoft.Extensions.Hosting.Testing.csproj +++ b/src/Libraries/Microsoft.Extensions.Hosting.Testing/Microsoft.Extensions.Hosting.Testing.csproj @@ -18,7 +18,6 @@ - diff --git a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Microsoft.Extensions.Http.Diagnostics.csproj b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Microsoft.Extensions.Http.Diagnostics.csproj index 052c54939b..f6c98baefc 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Microsoft.Extensions.Http.Diagnostics.csproj +++ b/src/Libraries/Microsoft.Extensions.Http.Diagnostics/Microsoft.Extensions.Http.Diagnostics.csproj @@ -38,12 +38,9 @@ - - - diff --git a/src/Libraries/Microsoft.Extensions.Http.Resilience/Internal/Randomizer.cs b/src/Libraries/Microsoft.Extensions.Http.Resilience/Internal/Randomizer.cs index bf9fba95eb..1192f8d395 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Resilience/Internal/Randomizer.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Resilience/Internal/Randomizer.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Threading; namespace Microsoft.Extensions.Http.Resilience.Internal; @@ -11,9 +10,15 @@ namespace Microsoft.Extensions.Http.Resilience.Internal; internal class Randomizer { - private static readonly ThreadLocal _randomInstance = new(() => new Random()); +#if NET6_0_OR_GREATER + public virtual double NextDouble(double maxValue) => Random.Shared.NextDouble() * maxValue; + + public virtual int NextInt(int maxValue) => Random.Shared.Next(maxValue); +#else + private static readonly System.Threading.ThreadLocal _randomInstance = new(() => new Random()); public virtual double NextDouble(double maxValue) => _randomInstance.Value!.NextDouble() * maxValue; public virtual int NextInt(int maxValue) => _randomInstance.Value!.Next(maxValue); +#endif } diff --git a/src/Libraries/Microsoft.Extensions.Http.Resilience/Polly/HttpClientResiliencePredicates.cs b/src/Libraries/Microsoft.Extensions.Http.Resilience/Polly/HttpClientResiliencePredicates.cs index 3345c75f11..97c5d37d66 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Resilience/Polly/HttpClientResiliencePredicates.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Resilience/Polly/HttpClientResiliencePredicates.cs @@ -52,8 +52,7 @@ public static class HttpClientResiliencePredicates internal static bool IsHttpConnectionTimeout(in Outcome outcome, in CancellationToken cancellationToken) => !cancellationToken.IsCancellationRequested - && outcome.Exception is OperationCanceledException { Source: "System.Private.CoreLib" } - && outcome.Exception.InnerException is TimeoutException; + && outcome.Exception is OperationCanceledException { Source: "System.Private.CoreLib", InnerException: TimeoutException }; /// /// Determines whether a response contains a transient failure. diff --git a/src/Libraries/Microsoft.Extensions.Http.Resilience/Polly/HttpRetryStrategyOptions.cs b/src/Libraries/Microsoft.Extensions.Http.Resilience/Polly/HttpRetryStrategyOptions.cs index afde7d0372..e6b4a7f4fe 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Resilience/Polly/HttpRetryStrategyOptions.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Resilience/Polly/HttpRetryStrategyOptions.cs @@ -55,7 +55,7 @@ public class HttpRetryStrategyOptions : RetryStrategyOptions args.Outcome.Result switch { HttpResponseMessage response when RetryAfterHelper.TryParse(response, TimeProvider.System, out var retryAfter) => new ValueTask(retryAfter), - _ => new ValueTask((TimeSpan?)null) + _ => default }; } else diff --git a/src/Libraries/Microsoft.Extensions.Http.Resilience/Routing/RoutingStrategyBuilderExtensions.cs b/src/Libraries/Microsoft.Extensions.Http.Resilience/Routing/RoutingStrategyBuilderExtensions.cs index 0c861de2df..d276042237 100644 --- a/src/Libraries/Microsoft.Extensions.Http.Resilience/Routing/RoutingStrategyBuilderExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.Http.Resilience/Routing/RoutingStrategyBuilderExtensions.cs @@ -129,7 +129,7 @@ public static class RoutingStrategyBuilderExtensions { var optionsCache = new NamedOptionsCache(builder.Name, serviceProvider.GetRequiredService>()); var factory = new OrderedGroupsRoutingStrategyFactory(serviceProvider.GetRequiredService(), optionsCache); - return () => factory.Get(); + return factory.Get; }); return builder.Services.AddOptionsWithValidateOnStart(builder.Name); @@ -141,7 +141,7 @@ public static class RoutingStrategyBuilderExtensions { var optionsCache = new NamedOptionsCache(builder.Name, serviceProvider.GetRequiredService>()); var factory = new WeightedGroupsRoutingStrategyFactory(serviceProvider.GetRequiredService(), optionsCache); - return () => factory.Get(); + return factory.Get; }); return builder.Services.AddOptionsWithValidateOnStart(builder.Name); diff --git a/src/Libraries/Microsoft.Extensions.Resilience/Microsoft.Extensions.Resilience.csproj b/src/Libraries/Microsoft.Extensions.Resilience/Microsoft.Extensions.Resilience.csproj index f1a2eabe12..ebd6325693 100644 --- a/src/Libraries/Microsoft.Extensions.Resilience/Microsoft.Extensions.Resilience.csproj +++ b/src/Libraries/Microsoft.Extensions.Resilience/Microsoft.Extensions.Resilience.csproj @@ -6,13 +6,8 @@ - true - true - true - true true true - true true @@ -28,12 +23,10 @@ - - diff --git a/src/Libraries/Microsoft.Extensions.Telemetry/Enrichment/ApplicationEnricherServiceCollectionExtensions.cs b/src/Libraries/Microsoft.Extensions.Telemetry/Enrichment/ApplicationEnricherServiceCollectionExtensions.cs index 75bb01c4a8..b42eb79910 100644 --- a/src/Libraries/Microsoft.Extensions.Telemetry/Enrichment/ApplicationEnricherServiceCollectionExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.Telemetry/Enrichment/ApplicationEnricherServiceCollectionExtensions.cs @@ -41,7 +41,7 @@ public static class ApplicationEnricherServiceCollectionExtensions return services .AddStaticLogEnricher() - .AddLogEnricherOptions(configure); + .Configure(configure); } /// @@ -58,21 +58,6 @@ public static class ApplicationEnricherServiceCollectionExtensions return services .AddStaticLogEnricher() - .AddLogEnricherOptions(_ => { }, section); - } - - private static IServiceCollection AddLogEnricherOptions( - this IServiceCollection services, - Action configure, - IConfigurationSection? section = null) - { - _ = services.Configure(configure); - - if (section is not null) - { - _ = services.Configure(section); - } - - return services; + .Configure(section); } } diff --git a/src/Libraries/Microsoft.Extensions.Telemetry/Enrichment/ProcessEnricherServiceCollectionExtensions.cs b/src/Libraries/Microsoft.Extensions.Telemetry/Enrichment/ProcessEnricherServiceCollectionExtensions.cs index bb987eb90b..7a1f1568c8 100644 --- a/src/Libraries/Microsoft.Extensions.Telemetry/Enrichment/ProcessEnricherServiceCollectionExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.Telemetry/Enrichment/ProcessEnricherServiceCollectionExtensions.cs @@ -42,7 +42,7 @@ public static class ProcessEnricherServiceCollectionExtensions return services .AddLogEnricher() .AddStaticLogEnricher() - .AddLogEnricherOptions(configure); + .Configure(configure); } /// @@ -60,21 +60,6 @@ public static class ProcessEnricherServiceCollectionExtensions return services .AddLogEnricher() .AddStaticLogEnricher() - .AddLogEnricherOptions(_ => { }, section); - } - - private static IServiceCollection AddLogEnricherOptions( - this IServiceCollection services, - Action configure, - IConfigurationSection? section = null) - { - _ = services.Configure(configure); - - if (section is not null) - { - _ = services.Configure(section); - } - - return services; + .Configure(section); } } diff --git a/src/Libraries/Microsoft.Extensions.Telemetry/Microsoft.Extensions.Telemetry.csproj b/src/Libraries/Microsoft.Extensions.Telemetry/Microsoft.Extensions.Telemetry.csproj index 9ad04ae889..3d39591e54 100644 --- a/src/Libraries/Microsoft.Extensions.Telemetry/Microsoft.Extensions.Telemetry.csproj +++ b/src/Libraries/Microsoft.Extensions.Telemetry/Microsoft.Extensions.Telemetry.csproj @@ -27,13 +27,10 @@ - - - diff --git a/src/Shared/RentedSpan/RentedSpan.cs b/src/Shared/RentedSpan/RentedSpan.cs index 6e4a837cf7..c7b429b0b6 100644 --- a/src/Shared/RentedSpan/RentedSpan.cs +++ b/src/Shared/RentedSpan/RentedSpan.cs @@ -90,7 +90,7 @@ internal readonly ref struct RentedSpan /// When a buffer isn't rented by this type, it's a cue to you to allocate buffer from the stack instead /// using stackalloc. /// - public Span Span => _rentedBuffer != null ? _rentedBuffer.AsSpan(0, _length) : Array.Empty().AsSpan(); + public Span Span => _rentedBuffer != null ? _rentedBuffer.AsSpan(0, _length) : default; /// /// Gets a value indicating whether a buffer has been rented.