Skip to content

Commit d102b7a

Browse files
authored
Update README.md
1 parent 080149a commit d102b7a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ The resilience system is built around the [`IResiliencePolicy` interface](https:
312312
4. **Exponential Backoff**: Gradually increase delays between retries with optional jitter
313313
5. **Exception Filtering**: Configure which exceptions should trigger retries
314314

315-
You can customize resilience behavior throughout Foundatio by implementing [`IResiliencePolicyProvider`](https://github.com/FoundatioFx/Foundatio/blob/master/src/Foundatio/Utility/ResiliencePolicy.cs) and registering it with dependency injection. This allows you to replace the default retry behavior in caching, queues, storage, and other Foundatio components.
315+
You can customize resilience behavior throughout Foundatio by implementing [`IResiliencePolicyProvider`](https://github.com/FoundatioFx/Foundatio/blob/master/src/Foundatio/Utility/ResiliencePolicy.cs) and passing it via options. This allows you to replace the default retry behavior in caching, queues, storage, and other Foundatio components.
316316
317317
#### Resilience Policy Sample
318318

@@ -368,16 +368,23 @@ var resilienceProvider = new ResiliencePolicyProvider()
368368
.WithPolicy("external-api", builder => builder
369369
.WithMaxAttempts(5)
370370
.WithCircuitBreaker()
371+
.WithTimeout(TimeSpan.FromSeconds(30)))
372+
.WithPolicy<MyService>(builder => builder
373+
.WithMaxAttempts(3)
374+
.WithLinearDelay()
371375
.WithTimeout(TimeSpan.FromSeconds(30)));
372376

373-
// Register with dependency injection
374-
services.AddSingleton<IResiliencePolicyProvider>(resilienceProvider);
375-
376377
// Use named policies
377378
var apiPolicy = resilienceProvider.GetPolicy("external-api");
378379
await apiPolicy.ExecuteAsync(async ct => {
379380
await CallExternalApiAsync(ct);
380381
});
382+
383+
// Use class based policies
384+
var apiPolicy = resilienceProvider.GetPolicy<MyService>();
385+
await apiPolicy.ExecuteAsync(async ct => {
386+
await CallMyServiceAsync(ct);
387+
});
381388
```
382389

383390
## Sample Application

0 commit comments

Comments
 (0)