Cleanup Http.Resilience dependencies (#5217)

This commit is contained in:
Pent Ploompuu 2024-06-14 02:39:05 +03:00 коммит произвёл GitHub
Родитель 3947b2e528
Коммит c13c8efa97
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
17 изменённых файлов: 17 добавлений и 66 удалений

Просмотреть файл

@ -16,7 +16,6 @@
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="$(MicrosoftExtensionsConfigurationVersion)" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsDependencyInjectionAbstractionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionVersion)" />
<PackageVersion Include="Microsoft.Extensions.DiagnosticAdapter" Version="3.1.32" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics" Version="$(MicrosoftExtensionsDiagnosticsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="$(MicrosoftExtensionsDiagnosticsHealthChecksVersion)" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(MicrosoftExtensionsHostingAbstractionsVersion)" />

Просмотреть файл

@ -19,7 +19,6 @@
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -26,11 +26,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))" />
<PackageReference Include="System.Collections.Immutable" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
<PackageReference Include="System.IO.Hashing" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -24,9 +24,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Bcl.HashCode" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -13,7 +13,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Options" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -25,11 +25,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Bcl.TimeProvider" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -18,7 +18,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.Extensions.Telemetry.Abstractions\Microsoft.Extensions.Telemetry.Abstractions.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.Diagnostics.Testing\Microsoft.Extensions.Diagnostics.Testing.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.Compliance.Testing\Microsoft.Extensions.Compliance.Testing.csproj" />
</ItemGroup>

Просмотреть файл

@ -38,12 +38,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Extensions.Http" />
<PackageReference Include="System.Collections.Immutable" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -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<Random> _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<Random> _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
}

Просмотреть файл

@ -52,8 +52,7 @@ public static class HttpClientResiliencePredicates
internal static bool IsHttpConnectionTimeout(in Outcome<HttpResponseMessage> 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 };
/// <summary>
/// Determines whether a response contains a transient failure.

Просмотреть файл

@ -55,7 +55,7 @@ public class HttpRetryStrategyOptions : RetryStrategyOptions<HttpResponseMessage
DelayGenerator = args => args.Outcome.Result switch
{
HttpResponseMessage response when RetryAfterHelper.TryParse(response, TimeProvider.System, out var retryAfter) => new ValueTask<TimeSpan?>(retryAfter),
_ => new ValueTask<TimeSpan?>((TimeSpan?)null)
_ => default
};
}
else

Просмотреть файл

@ -129,7 +129,7 @@ public static class RoutingStrategyBuilderExtensions
{
var optionsCache = new NamedOptionsCache<OrderedGroupsRoutingOptions>(builder.Name, serviceProvider.GetRequiredService<IOptionsMonitor<OrderedGroupsRoutingOptions>>());
var factory = new OrderedGroupsRoutingStrategyFactory(serviceProvider.GetRequiredService<Randomizer>(), optionsCache);
return () => factory.Get();
return factory.Get;
});
return builder.Services.AddOptionsWithValidateOnStart<OrderedGroupsRoutingOptions, OrderedGroupsRoutingOptionsValidator>(builder.Name);
@ -141,7 +141,7 @@ public static class RoutingStrategyBuilderExtensions
{
var optionsCache = new NamedOptionsCache<WeightedGroupsRoutingOptions>(builder.Name, serviceProvider.GetRequiredService<IOptionsMonitor<WeightedGroupsRoutingOptions>>());
var factory = new WeightedGroupsRoutingStrategyFactory(serviceProvider.GetRequiredService<Randomizer>(), optionsCache);
return () => factory.Get();
return factory.Get;
});
return builder.Services.AddOptionsWithValidateOnStart<WeightedGroupsRoutingOptions, WeightedGroupsRoutingOptionsValidator>(builder.Name);

Просмотреть файл

@ -6,13 +6,8 @@
</PropertyGroup>
<PropertyGroup>
<UseLoggingGenerator>true</UseLoggingGenerator>
<UseMetricsGenerator>true</UseMetricsGenerator>
<UseOptionsValidationGenerator>true</UseOptionsValidationGenerator>
<InjectTrimAttributesOnLegacy>true</InjectTrimAttributesOnLegacy>
<InjectGetOrAddOnLegacy>true</InjectGetOrAddOnLegacy>
<InjectTrimAttributesOnLegacy>true</InjectTrimAttributesOnLegacy>
<InjectSharedDataValidation>true</InjectSharedDataValidation>
<InjectSharedDiagnosticIds>true</InjectSharedDiagnosticIds>
</PropertyGroup>
@ -28,12 +23,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Polly.Core" />
<PackageReference Include="Polly.Extensions" />
<PackageReference Include="Polly.RateLimiting" />
<PackageReference Include="Microsoft.Extensions.Diagnostics" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -41,7 +41,7 @@ public static class ApplicationEnricherServiceCollectionExtensions
return services
.AddStaticLogEnricher<ApplicationLogEnricher>()
.AddLogEnricherOptions(configure);
.Configure(configure);
}
/// <summary>
@ -58,21 +58,6 @@ public static class ApplicationEnricherServiceCollectionExtensions
return services
.AddStaticLogEnricher<ApplicationLogEnricher>()
.AddLogEnricherOptions(_ => { }, section);
}
private static IServiceCollection AddLogEnricherOptions(
this IServiceCollection services,
Action<ApplicationLogEnricherOptions> configure,
IConfigurationSection? section = null)
{
_ = services.Configure(configure);
if (section is not null)
{
_ = services.Configure<ApplicationLogEnricherOptions>(section);
}
return services;
.Configure<ApplicationLogEnricherOptions>(section);
}
}

Просмотреть файл

@ -42,7 +42,7 @@ public static class ProcessEnricherServiceCollectionExtensions
return services
.AddLogEnricher<ProcessLogEnricher>()
.AddStaticLogEnricher<StaticProcessLogEnricher>()
.AddLogEnricherOptions(configure);
.Configure(configure);
}
/// <summary>
@ -60,21 +60,6 @@ public static class ProcessEnricherServiceCollectionExtensions
return services
.AddLogEnricher<ProcessLogEnricher>()
.AddStaticLogEnricher<StaticProcessLogEnricher>()
.AddLogEnricherOptions(_ => { }, section);
}
private static IServiceCollection AddLogEnricherOptions(
this IServiceCollection services,
Action<ProcessLogEnricherOptions> configure,
IConfigurationSection? section = null)
{
_ = services.Configure(configure);
if (section is not null)
{
_ = services.Configure<ProcessLogEnricherOptions>(section);
}
return services;
.Configure<ProcessLogEnricherOptions>(section);
}
}

Просмотреть файл

@ -27,13 +27,10 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.Extensions.DependencyInjection.AutoActivation\Microsoft.Extensions.DependencyInjection.AutoActivation.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.AmbientMetadata.Application\Microsoft.Extensions.AmbientMetadata.Application.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.Compliance.Abstractions\Microsoft.Extensions.Compliance.Abstractions.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.Telemetry.Abstractions\Microsoft.Extensions.Telemetry.Abstractions.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="Microsoft.Bcl.TimeProvider" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" />
<PackageReference Include="System.Collections.Immutable" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />

Просмотреть файл

@ -90,7 +90,7 @@ internal readonly ref struct RentedSpan<T>
/// When a buffer isn't rented by this type, it's a cue to you to allocate buffer from the stack instead
/// using stackalloc.
/// </remarks>
public Span<T> Span => _rentedBuffer != null ? _rentedBuffer.AsSpan(0, _length) : Array.Empty<T>().AsSpan();
public Span<T> Span => _rentedBuffer != null ? _rentedBuffer.AsSpan(0, _length) : default;
/// <summary>
/// Gets a value indicating whether a buffer has been rented.