RetryStrategyOptions<TResult>
Represents the options used to configure a retry strategy.
using Polly.Utils;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace Polly.Retry
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Addressed with DynamicDependency on ValidationHelper.Validate method")]
public class RetryStrategyOptions<[System.Runtime.CompilerServices.Nullable(2)] TResult> : ResilienceStrategyOptions
{
[Range(1, int.MaxValue)]
public int MaxRetryAttempts { get; set; } = 3;
public DelayBackoffType BackoffType { get; set; }
public bool UseJitter { get; set; }
[Range(typeof(TimeSpan), "00:00:00", "1.00:00:00")]
public TimeSpan Delay { get; set; } = RetryConstants.DefaultBaseDelay;
[Range(typeof(TimeSpan), "00:00:00", "1.00:00:00")]
public TimeSpan? MaxDelay { get; set; }
[System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
0
})]
[Required]
[field: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
0
})]
public Func<RetryPredicateArguments<TResult>, ValueTask<bool>> ShouldHandle {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
0
})]
get;
[param: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
0
})]
set;
} = DefaultPredicates<RetryPredicateArguments<TResult>, TResult>.HandleOutcome;
[System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1,
0
})]
[field: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1,
0
})]
public Func<RetryDelayGeneratorArguments<TResult>, ValueTask<TimeSpan?>> DelayGenerator {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1,
0
})]
get;
[param: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1,
0
})]
set;
}
[System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1
})]
[field: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1
})]
public Func<OnRetryArguments<TResult>, ValueTask> OnRetry {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1
})]
get;
[param: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
0,
1
})]
set;
}
[EditorBrowsable(EditorBrowsableState.Never)]
[Required]
public Func<double> Randomizer { get; set; } = RandomUtil.Instance.NextDouble;
public RetryStrategyOptions()
{
base.Name = "Retry";
}
}
}