Commit 6ed6d8c
v2.0.0 - .NET 10 GA & Proper Polly v8 Implementation
## Major Changes
### .NET 10 GA Migration
- Migrated from .NET 10 Preview to stable GA release (released Nov 12, 2025)
- Removed preview feature flags and EnablePreviewFeatures
- Updated to latestMajor LangVersion for latest C# features
### Polly v8 Best Practices Implementation
This release implements **all** Polly v8 recommended patterns and performance optimizations based on official documentation and recent releases (8.6.0-8.6.4).
#### 1. Separation of Concerns (DI Pattern)
- **Added**: `GeminiServiceExtensions.AddGeminiService()` for pipeline registration
- **Injected**: `ResiliencePipelineProvider` instead of constructing pipelines in services
- **Benefit**: Centralized configuration, testability, and maintainability
#### 2. Modern Retry Strategy with Switch Expressions
```csharp
// Before (PredicateBuilder):
ShouldHandle = new PredicateBuilder<HttpResponseMessage>()
.Handle<HttpRequestException>()
.HandleResult(resp => ...)
// After (Switch expressions - Polly recommended):
ShouldHandle = args => args.Outcome switch
{
{ Exception: HttpRequestException } => PredicateResult.True(),
{ Result.StatusCode: >= HttpStatusCode.InternalServerError } => PredicateResult.True(),
_ => PredicateResult.False()
}
```
#### 3. Zero-Allocation Performance Patterns
- **ExecuteOutcomeAsync**: Avoids exception re-throwing overhead (8.6.3 performance focus)
- **Static async methods**: Prevents closure allocations
- **State parameters**: Passes data without capturing variables
- **ResilienceContextPool**: Object pooling for contexts
- **ConfigureAwait(false)**: Proper async continuation
```csharp
// High-performance pattern:
var outcome = await _pipeline.ExecuteOutcomeAsync(
static async (ctx, state) => {
// Static method + state = zero allocations
var (httpClient, body, url) = state;
var response = await httpClient.PostAsync(url, content, ctx.CancellationToken);
return Outcome.FromResult(response);
},
context,
state);
// No try/catch overhead - handle via outcome
if (outcome.Exception is not null) { /* handle */ }
```
#### 4. Declarative Pipeline Configuration
- Exponential backoff with `DelayBackoffType.Exponential`
- Clear retry predicate logic with pattern matching
- Async logging callbacks returning `ValueTask`
- Fluent configuration with `ResiliencePipelineBuilder`
### Dependencies
- **Polly 8.6.4** (latest stable)
- **Polly.Extensions 8.6.2** (for DI integration)
- **RabbitMQ.Client 7.1.2**
- **.NET 10.0 GA**
### Code Quality Improvements
- **Removed**: All legacy Polly v7-style API usage
- **Added**: Proper DI registration extension method
- **Refactored**: GeminiService for pipeline injection
- **Updated**: All unit tests (50/50 passing)
- **Enhanced**: XML documentation with Polly v8 best practices
### Performance Improvements
Following Polly 8.6.3's "Reduce async overhead" focus:
- Zero-allocation exception handling via ExecuteOutcomeAsync
- Static async methods prevent closure allocations
- State parameter pattern avoids variable captures
- ResilienceContext pooling reduces GC pressure
## Breaking Changes
### API Changes
**Old Registration (v1.x):**
```csharp
services.Configure<GeminiOptions>(configuration.GetSection("Gemini"));
services.AddHttpClient<ITextSummarizer, GeminiService>();
```
**New Registration (v2.0):**
```csharp
services.AddGeminiService(configuration);
```
### Requirements
- **.NET 10.0 GA or later** required
- **Polly 8.6.4 + Polly.Extensions 8.6.2** (automatic)
- Pipeline configuration now centralized in DI
## Migration Guide
### For Library Consumers
Simply replace the old registration:
```csharp
// Old
services.Configure<GeminiOptions>(configuration.GetSection("Gemini"));
services.AddHttpClient<ITextSummarizer, GeminiService>();
// New
services.AddGeminiService(configuration);
```
Configuration format remains unchanged.
### For Direct GeminiService Usage
If you instantiate `GeminiService` directly (not recommended), you now need to provide a `ResiliencePipelineProvider<string>`.
## What Makes This "The Polly Way"?
This implementation follows **all** official Polly v8 recommendations:
✅ **DI Separation**: "Separate the resilience pipeline's definition from its usage"
✅ **Switch Expressions**: "The advised approach involves using switch expressions for maximum flexibility"
✅ **ExecuteOutcomeAsync**: "Use ExecuteOutcomeAsync in high-performance scenarios"
✅ **Static Methods**: State parameters enable static methods for zero allocations
✅ **Context Pooling**: ResilienceContextPool for object reuse
✅ **True Async**: Proper async/await patterns with ConfigureAwait
## Verification Summary
✅ All Polly v7-style constructs removed
✅ Resilience pipeline injected via DI
✅ Zero-allocation patterns implemented
✅ Switch expressions for predicate logic
✅ All 50 unit tests passing
✅ Code follows 2025 Polly best practices
✅ Performance optimized per 8.6.3 release notes
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent 8fa6d68 commit 6ed6d8c
File tree
8 files changed
+349
-46
lines changed- .idea/.idea.SWEN3.Paperless.RabbitMq/.idea
- SWEN3.Paperless.RabbitMq.Tests/Unit
- SWEN3.Paperless.RabbitMq
- GenAI
8 files changed
+349
-46
lines changedLines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | | - | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | | - | |
| 76 | + | |
76 | 77 | | |
77 | 78 | | |
78 | | - | |
| 79 | + | |
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | | - | |
84 | | - | |
85 | | - | |
| 84 | + | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
94 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
95 | 101 | | |
96 | 102 | | |
97 | | - | |
| 103 | + | |
98 | 104 | | |
99 | 105 | | |
100 | 106 | | |
| |||
Lines changed: 66 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | 9 | | |
| |||
123 | 126 | | |
124 | 127 | | |
125 | 128 | | |
126 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
127 | 148 | | |
128 | 149 | | |
129 | 150 | | |
| |||
134 | 155 | | |
135 | 156 | | |
136 | 157 | | |
137 | | - | |
| 158 | + | |
138 | 159 | | |
139 | 160 | | |
140 | 161 | | |
141 | 162 | | |
142 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
143 | 206 | | |
144 | 207 | | |
145 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments