RetryStrategyExtensions Class
- Namespace
- Kampute.HttpClient.RetryManagement
- Assembly
- Kampute.HttpClient.dll
Definition
Provides extension methods for IRetryStrategy to enhance retry strategies with additional behavior.
public static class RetryStrategyExtensions- Inheritance
- object
- RetryStrategyExtensions
Methods
ToBackoffStrategy(this IRetryStrategy)
Converts an IRetryStrategy into a BackoffStrategy, creating a factory capable of producing schedulers based on the provided strategy.
public static BackoffStrategy ToBackoffStrategy(this IRetryStrategy source)Parameters
sourceIRetryStrategy- The retry strategy to use for creating a scheduler factory.
Returns
- BackoffStrategy
- A new instance of BackoffStrategy.
Exceptions
- ArgumentNullException
- Thrown if
sourceisnull.
ToScheduler(this IRetryStrategy)
Converts an IRetryStrategy into a RetryScheduler, creating a scheduler instance based on the provided strategy.
public static RetryScheduler ToScheduler(this IRetryStrategy source)Parameters
sourceIRetryStrategy- The retry strategy to convert into a scheduler.
Returns
- RetryScheduler
- A new instance of RetryScheduler.
Exceptions
- ArgumentNullException
- Thrown if
sourceisnull.
WithJitter(this IRetryStrategy, double)
Enhances a retry strategy with jitter to add randomness to the retry delay.
public static JitterStrategyModifier WithJitter(this IRetryStrategy source, double jitterFactor = 0.5)Parameters
sourceIRetryStrategy- The original retry strategy to be enhanced.
jitterFactordouble optional- The factor by which to adjust the delay randomly, with a default of 0.5.
Returns
- JitterStrategyModifier
- A JitterStrategyModifier instance wrapping the original retry strategy with added jitter.
Exceptions
- ArgumentNullException
- Thrown if
sourceisnull. - ArgumentOutOfRangeException
- Thrown if
jitterFactoris not between 0 and 1.
WithMaxAttempts(this IRetryStrategy, uint)
Enhances a retry strategy with a maximum number of retry attempts.
public static LimitedAttemptsStrategyModifier WithMaxAttempts(this IRetryStrategy source, uint maxAttempts)Parameters
sourceIRetryStrategy- The original retry strategy to be enhanced.
maxAttemptsuint- The maximum number of attempts allowed before giving up.
Returns
- LimitedAttemptsStrategyModifier
- A LimitedAttemptsStrategyModifier instance wrapping the original retry strategy with a limit on the number of attempts.
Exceptions
- ArgumentNullException
- Thrown if
sourceisnull.
WithTimeout(this IRetryStrategy, TimeSpan)
Enhances a retry strategy with a timeout, limiting the total duration allowed for retry attempts.
public static LimitedDurationStrategyModifier WithTimeout(this IRetryStrategy source, TimeSpan timeout)Parameters
sourceIRetryStrategy- The original retry strategy to be enhanced.
timeoutTimeSpan- The maximum duration to attempt retries before giving up.
Returns
- LimitedDurationStrategyModifier
- A LimitedDurationStrategyModifier instance wrapping the original retry strategy with a timeout limit.
Exceptions
- ArgumentNullException
- Thrown if
sourceisnull.
