Dawning.Resilience
1.0.1
dotnet add package Dawning.Resilience --version 1.0.1
NuGet\Install-Package Dawning.Resilience -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Dawning.Resilience" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dawning.Resilience" Version="1.0.1" />
<PackageReference Include="Dawning.Resilience" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Dawning.Resilience --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Dawning.Resilience, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Dawning.Resilience@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Dawning.Resilience&version=1.0.1
#tool nuget:?package=Dawning.Resilience&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Dawning.Resilience
弹性策略库(基于 Polly 8)。
安装
dotnet add package Dawning.Resilience
功能
- 重试策略 - 指数退避、抖动
- 熔断器 - 失败率触发、自动恢复
- 超时处理 - 请求超时控制
- HttpClient 集成 - 弹性 HTTP 客户端
使用
方式 1: 注册弹性服务
builder.Services.AddDawningResilience(options =>
{
// 重试配置
options.Retry.MaxRetryAttempts = 3;
options.Retry.BaseDelayMs = 200;
options.Retry.UseExponentialBackoff = true;
// 熔断器配置
options.CircuitBreaker.FailureRatioThreshold = 0.5;
options.CircuitBreaker.BreakDurationSeconds = 30;
// 超时配置
options.Timeout.TimeoutSeconds = 30;
});
方式 2: 弹性 HttpClient
builder.Services.AddResilientHttpClient<IMyApiClient>(
client => client.BaseAddress = new Uri("https://api.example.com"),
options => options.Retry.MaxRetryAttempts = 5
);
方式 3: 手动使用
public class MyService
{
private readonly ResiliencePolicyBuilder _policyBuilder;
public async Task<string> CallApiAsync()
{
var pipeline = _policyBuilder.Build<string>();
return await pipeline.ExecuteAsync(async () =>
{
return await _httpClient.GetStringAsync("/api/data");
});
}
}
配置选项
重试 (RetryOptions)
| 选项 | 说明 | 默认值 |
|---|---|---|
Enabled |
是否启用 | true |
MaxRetryAttempts |
最大重试次数 | 3 |
BaseDelayMs |
基础延迟(ms) | 200 |
UseExponentialBackoff |
指数退避 | true |
MaxDelayMs |
最大延迟(ms) | 30000 |
熔断器 (CircuitBreakerOptions)
| 选项 | 说明 | 默认值 |
|---|---|---|
Enabled |
是否启用 | true |
FailureRatioThreshold |
失败率阈值 | 0.5 |
SamplingDurationSeconds |
采样时长(s) | 30 |
MinimumThroughput |
最小吞吐量 | 10 |
BreakDurationSeconds |
熔断时长(s) | 30 |
超时 (TimeoutOptions)
| 选项 | 说明 | 默认值 |
|---|---|---|
Enabled |
是否启用 | true |
TimeoutSeconds |
超时时间(s) | 30 |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http.Resilience (>= 8.0.0)
- Polly (>= 8.5.2)
- Polly.Extensions (>= 8.5.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1 | 241 | 1/2/2026 |