Skip to content

Commit

Permalink
Fix samples
Browse files Browse the repository at this point in the history
React to breaking changes.
  • Loading branch information
martincostello committed Aug 8, 2023
1 parent 184c8e8 commit 18e9438
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions samples/Extensibility/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// ------------------------------------------------------------------------
// Usage of custom strategy
// ------------------------------------------------------------------------
var strategy = new ResilienceStrategyBuilder()
var strategy = new CompositeStrategyBuilder()
// This is custom extension defined in this sample
.AddMyResilienceStrategy(new MyResilienceStrategyOptions
{
Expand All @@ -23,7 +23,7 @@
// SIMPLE EXTENSIBILITY MODEL (INLINE STRATEGY)
// ------------------------------------------------------------------------

strategy = new ResilienceStrategyBuilder()
strategy = new CompositeStrategyBuilder()
// Just add the strategy instance directly
.AddStrategy(new MySimpleStrategy())
.Build();
Expand Down Expand Up @@ -125,7 +125,7 @@ protected override async ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState
public static class MyResilienceStrategyExtensions
{
// Add new extension that works for both "ResilienceStrategyBuilder" and "ResilienceStrategyBuilder<T>"
public static TBuilder AddMyResilienceStrategy<TBuilder>(this TBuilder builder, MyResilienceStrategyOptions options) where TBuilder : ResilienceStrategyBuilderBase
public static TBuilder AddMyResilienceStrategy<TBuilder>(this TBuilder builder, MyResilienceStrategyOptions options) where TBuilder : CompositeStrategyBuilderBase
=> builder.AddStrategy(
// Provide a factory that creates the strategy
context => new MyResilienceStrategy(context.Telemetry, options),
Expand Down
2 changes: 1 addition & 1 deletion samples/GenericStrategies/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// The generic ResilienceStrategyBuilder<T> creates a ResilienceStrategy<T>
// that can execute synchronous and asynchronous callbacks that return T.

ResilienceStrategy<HttpResponseMessage> strategy = new ResilienceStrategyBuilder<HttpResponseMessage>()
ResilienceStrategy<HttpResponseMessage> strategy = new CompositeStrategyBuilder<HttpResponseMessage>()
.AddFallback(new FallbackStrategyOptions<HttpResponseMessage>
{
FallbackAction = _ =>
Expand Down
6 changes: 3 additions & 3 deletions samples/Intro/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// The ResilienceStrategyBuilder creates a ResilienceStrategy
// that can be executed synchronously or asynchronously
// and for both void and result-returning user-callbacks.
ResilienceStrategy strategy = new ResilienceStrategyBuilder()
ResilienceStrategy strategy = new CompositeStrategyBuilder()
// Use convenience extension that accepts TimeSpan
.AddTimeout(TimeSpan.FromSeconds(5))
.Build();
Expand Down Expand Up @@ -37,7 +37,7 @@
// 3. Create and execute a pipeline of strategies
// ------------------------------------------------------------------------

strategy = new ResilienceStrategyBuilder()
strategy = new CompositeStrategyBuilder()
// Add retries using the options
.AddRetry(new RetryStrategyOptions
{
Expand All @@ -51,7 +51,7 @@
_ => PredicateResult.False
},
// Register user callback called whenever retry occurs
OnRetry = args => { Console.WriteLine($"Retrying...{args.Arguments.Attempt} attempt"); return default; },
OnRetry = args => { Console.WriteLine($"Retrying...{args.Arguments.AttemptNumber} attempt"); return default; },
BaseDelay = TimeSpan.FromMilliseconds(400),
BackoffType = RetryBackoffType.Constant,
RetryCount = 3
Expand Down
13 changes: 7 additions & 6 deletions samples/Retries/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// 1. Create a retry strategy that handles all exceptions
// ------------------------------------------------------------------------

ResilienceStrategy strategy = new ResilienceStrategyBuilder()
ResilienceStrategy strategy = new CompositeStrategyBuilder()
// Default retry options handle all exceptions
.AddRetry(new RetryStrategyOptions())
.Build();
Expand All @@ -21,7 +21,7 @@
// 2. Customize the retry behavior
// ------------------------------------------------------------------------

strategy = new ResilienceStrategyBuilder()
strategy = new CompositeStrategyBuilder()
.AddRetry(new RetryStrategyOptions
{
// Specify what exceptions should be retried using PredicateBuilder
Expand All @@ -31,7 +31,8 @@

// The recommended backoff type for HTTP scenarios
// See here for more information: https://github.com/App-vNext/Polly/wiki/Retry-with-jitter#more-complex-jitter
BackoffType = RetryBackoffType.ExponentialWithJitter
BackoffType = RetryBackoffType.Exponential,
UseJitter = true
})
.Build();

Expand All @@ -42,7 +43,7 @@
// 3. Register the callbacks
// ------------------------------------------------------------------------

strategy = new ResilienceStrategyBuilder()
strategy = new CompositeStrategyBuilder()
.AddRetry(new RetryStrategyOptions
{
// Specify what exceptions should be retried using switch expressions
Expand All @@ -53,7 +54,7 @@
},
OnRetry = outcome =>
{
Console.WriteLine($"Retrying attempt {outcome.Arguments.Attempt}...");
Console.WriteLine($"Retrying attempt {outcome.Arguments.AttemptNumber}...");
return default;
}
})
Expand All @@ -66,7 +67,7 @@
// 4. Create an HTTP retry strategy that handles both exceptions and results
// ------------------------------------------------------------------------

ResilienceStrategy<HttpResponseMessage> httpStrategy = new ResilienceStrategyBuilder<HttpResponseMessage>()
ResilienceStrategy<HttpResponseMessage> httpStrategy = new CompositeStrategyBuilder<HttpResponseMessage>()
.AddRetry(new RetryStrategyOptions<HttpResponseMessage>
{
// Specify what exceptions or results should be retried
Expand Down

0 comments on commit 18e9438

Please sign in to comment.