Skip to content

Commit a8dd367

Browse files
authored
Merge pull request #7 from kolan72/dev
Update main before release.
2 parents b4e0fa1 + 562f14d commit a8dd367

14 files changed

+274
-79
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The library provides an outgoing request resiliency pipeline for `HttpClient`, u
88

99
## ⚡ Key Features
1010

11-
- Provides the ability to create a pipeline to handle typical transient HTTP failures (including the `HttpRequestException` exception).
11+
- Provides the ability to create a resiliency pipeline to handle typical transient HTTP failures (including the `HttpRequestException` exception).
1212
- Flexible transient failure filter for the final `DelegatingHandler` in the pipeline for the response.
1313
- Additionally, custom failure status codes or categories can be added to the final handler filter.
1414
- Other exception types (besides `HttpRequestException`) can also be included in the final handler filter.

samples/FromOptions/RetryFromOptions/RetryFromOptions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<LangVersion>latest</LangVersion>

samples/Intro/Fallback/Fallback.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
99
</PropertyGroup>
1010

11-
<ItemGroup>
12-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.8" />
13-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.8" />
14-
</ItemGroup>
15-
1611
<ItemGroup>
1712
<ProjectReference Include="..\..\Shared\Shared.csproj" />
1813
</ItemGroup>

samples/Intro/Retries/Retries.csproj

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<LangVersion>latest</LangVersion>
77
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
88
</PropertyGroup>
99

10-
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.8" />
12-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.8" />
13-
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.8" />
14-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.8" />
15-
<PackageReference Include="PoliNorError.Extensions.Http" Version="0.3.0" />
16-
<PackageReference Include="System.Text.Json" Version="9.0.8" />
17-
</ItemGroup>
18-
1910
<ItemGroup>
2011
<ProjectReference Include="..\..\Shared\Shared.csproj" />
2112
</ItemGroup>

samples/Shared/Shared.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
66
</PropertyGroup>
77

@@ -11,9 +11,9 @@
1111
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.8" />
1212
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.8" />
1313
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.8" />
14-
<PackageReference Include="PoliNorError" Version="2.24.0" />
15-
<PackageReference Include="PoliNorError.Extensions.Http" Version="0.3.0" />
16-
<PackageReference Include="Spectre.Console" Version="0.50.0" />
14+
<PackageReference Include="PoliNorError" Version="2.24.12" />
15+
<PackageReference Include="PoliNorError.Extensions.Http" Version="0.5.0" />
16+
<PackageReference Include="Spectre.Console" Version="0.51.1" />
1717
<PackageReference Include="System.Text.Json" Version="9.0.8" />
1818
<PackageReference Include="vertical-spectreconsolelogger" Version="0.10.1-dev.20240326.31" />
1919
</ItemGroup>

src/HttpPolicyResultHandler.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
using System.Net.Http;
33
using System.Threading.Tasks;
44
using System.Threading;
5+
using PoliNorError.Extensions.PolicyResultHandling;
56

67
namespace PoliNorError.Extensions.Http
78
{
89
internal interface IHttpPolicyResultHandler
910
{
10-
void AttachTo(RetryPolicy retryPolicy);
11+
void AttachTo(Policy policy);
1112
}
1213

1314
internal class SyncHttpPolicyResultHandler : IHttpPolicyResultHandler
@@ -19,9 +20,9 @@ public SyncHttpPolicyResultHandler(Action<PolicyResult<HttpResponseMessage>, Can
1920
_syncHandler = syncHandler;
2021
}
2122

22-
public void AttachTo(RetryPolicy retryPolicy)
23+
public void AttachTo(Policy policy)
2324
{
24-
retryPolicy.AddPolicyResultHandler(_syncHandler);
25+
policy.AddHandlerForPolicyResult(_syncHandler);
2526
}
2627
}
2728

@@ -34,9 +35,9 @@ public NotCancelableSyncHttpPolicyResultHandler(Action<PolicyResult<HttpResponse
3435
_syncHandler = syncHandler;
3536
}
3637

37-
public void AttachTo(RetryPolicy retryPolicy)
38+
public void AttachTo(Policy policy)
3839
{
39-
retryPolicy.AddPolicyResultHandler(_syncHandler);
40+
policy.AddHandlerForPolicyResult(_syncHandler);
4041
}
4142
}
4243

@@ -49,9 +50,9 @@ public AsyncHttpPolicyResultHandler(Func<PolicyResult<HttpResponseMessage>, Canc
4950
_asyncHandler = asyncHandler;
5051
}
5152

52-
public void AttachTo(RetryPolicy retryPolicy)
53+
public void AttachTo(Policy policy)
5354
{
54-
retryPolicy.AddPolicyResultHandler(_asyncHandler);
55+
policy.AddHandlerForPolicyResult(_asyncHandler);
5556
}
5657
}
5758

@@ -64,9 +65,9 @@ public NotCancelableAsyncHttpPolicyResultHandler(Func<PolicyResult<HttpResponseM
6465
_asyncHandler = asyncHandler;
6566
}
6667

67-
public void AttachTo(RetryPolicy retryPolicy)
68+
public void AttachTo(Policy policy)
6869
{
69-
retryPolicy.AddPolicyResultHandler(_asyncHandler);
70+
policy.AddHandlerForPolicyResult(_asyncHandler);
7071
}
7172
}
7273
}

src/IHttpPolicyResultHandlers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ public IHttpPolicyResultHandlers AddHandler(Func<PolicyResult<HttpResponseMessag
9595
return this;
9696
}
9797

98-
internal void AttachTo(RetryPolicy retryPolicy)
98+
internal void AttachTo(Policy policy)
9999
{
100100
foreach (var handler in _hanlders)
101101
{
102-
handler.AttachTo(retryPolicy);
102+
handler.AttachTo(policy);
103103
}
104104
}
105105
}

src/PoliNorError.Extensions.Http.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
</PropertyGroup>
2727

2828
<ItemGroup>
29-
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.8" />
30-
<PackageReference Include="PoliNorError" Version="2.24.0" />
29+
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.10" />
30+
<PackageReference Include="PoliNorError" Version="2.24.12" />
3131
</ItemGroup>
3232

3333
<ItemGroup>

src/PolicyHandlerStorageExtensions.Retry.FromOptions.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,38 @@ public static partial class PolicyHandlerStorageExtensions
66
{
77
private static readonly Func<int, RetryPolicyOptions, IBulkErrorProcessor, RetryPolicy> _retryPolicyCreator = (rc, rpo, bep) => new RetryPolicy(rc, bep, retryDelay: rpo.RetryDelay);
88

9+
private static readonly Func<RetryPolicyOptions, IBulkErrorProcessor, RetryPolicy> _infiniteRetryPolicyCreator = (rpo, bep) => RetryPolicy.InfiniteRetries(bep, retryDelay: rpo.RetryDelay);
10+
11+
/// <summary>
12+
/// Adds a handler based on a <see cref="RetryPolicy"/> to a pipeline builder
13+
/// that implements the <see cref="IPolicyHandlerStorage{TStorage}"/> interface,
14+
/// configured for **infinite retries**.
15+
/// </summary>
16+
/// <typeparam name="TStorage">Storage type for <see cref="System.Net.Http.DelegatingHandler"/>.</typeparam>
17+
/// <param name="storage">Storage for <see cref="System.Net.Http.DelegatingHandler"/>.</param>
18+
/// <param name="options"><see cref="RetryPolicyOptions"/>.</param>
19+
public static TStorage AddInfiniteRetryHandler<TStorage>(this IPolicyHandlerStorage<TStorage> storage, RetryPolicyOptions options) where TStorage : IPolicyHandlerStorage<TStorage>
20+
{
21+
return storage.AddRetryHandler(_infiniteRetryPolicyCreator, options);
22+
}
23+
24+
/// <summary>
25+
/// Adds a handler based on a <see cref="RetryPolicy"/> to a pipeline builder
26+
/// that implements the <see cref="IPolicyHandlerStorage{TStorage}"/> interface,
27+
/// configured for **infinite retries**.
28+
/// </summary>
29+
/// <typeparam name="TStorage">Storage type for <see cref="System.Net.Http.DelegatingHandler"/>.</typeparam>
30+
/// <param name="storage">Storage for <see cref="System.Net.Http.DelegatingHandler"/>.</param>
31+
/// <param name="configure">Delegate for configuring <see cref="RetryPolicyOptions"/>.</param>
32+
/// <returns></returns>
33+
public static TStorage AddInfiniteRetryHandler<TStorage>(this IPolicyHandlerStorage<TStorage> storage, Action<RetryPolicyOptions> configure = null) where TStorage : IPolicyHandlerStorage<TStorage>
34+
{
35+
var options = new RetryPolicyOptions();
36+
configure?.Invoke(options);
37+
38+
return storage.AddInfiniteRetryHandler(options);
39+
}
40+
941
/// <summary>
1042
/// Adds a handler based on a RetryPolicy to a pipeline builder
1143
/// that implements the <see cref="IPolicyHandlerStorage{TStorage}"/> interface.

src/PolicyOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class PolicyOptions
2020
/// <summary>
2121
/// Gets or sets the action that configures error processing by adding an <see cref=“IErrorProcessor”/> to a policy.
2222
/// </summary>
23-
public Action<IBulkErrorProcessor> ConfigureErrorProcessing { get; set; }
23+
public Action<BulkErrorProcessor> ConfigureErrorProcessing { get; set; }
2424

2525
/// <summary>
2626
/// Gets or sets the function that configures the error filter for a policy.

0 commit comments

Comments
 (0)