Class RetryStrategyExtensions
- Namespace
- Kampute.HttpClient.RetryManagement
- Assembly
- Kampute.HttpClient.dll
Provides extension methods for IRetryStrategy to enhance retry strategies with additional behavior.
public static class RetryStrategyExtensions
- Inheritance
-
RetryStrategyExtensions
- Inherited Members
Methods
ToBackoffStrategy(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
sourceIRetryStrategyThe retry strategy to use for creating a scheduler factory.
Returns
- BackoffStrategy
A new instance of BackoffStrategy.
Exceptions
- ArgumentNullException
Thrown if
sourceis null.
ToScheduler(IRetryStrategy)
Converts an IRetryStrategy into a RetryScheduler, creating a scheduler instance based on the provided strategy.
public static RetryScheduler ToScheduler(this IRetryStrategy source)
Parameters
sourceIRetryStrategyThe retry strategy to convert into a scheduler.
Returns
- RetryScheduler
A new instance of RetryScheduler.
Exceptions
- ArgumentNullException
Thrown if
sourceis null.
WithJitter(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
sourceIRetryStrategyThe original retry strategy to be enhanced.
jitterFactordoubleThe 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
sourceis null.- ArgumentOutOfRangeException
Thrown if
jitterFactoris not between 0 and 1.
WithMaxAttempts(IRetryStrategy, uint)
Enhances a retry strategy with a maximum number of retry attempts.
public static LimitedAttemptsStrategyModifier WithMaxAttempts(this IRetryStrategy source, uint maxAttempts)
Parameters
sourceIRetryStrategyThe original retry strategy to be enhanced.
maxAttemptsuintThe 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
sourceis null.
WithTimeout(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
sourceIRetryStrategyThe original retry strategy to be enhanced.
timeoutTimeSpanThe 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
sourceis null.