Class Shield

Namespace
Kevlar
Assembly
Kevlar.dll

An immutable, thread-safe resilience pipeline. Build one once — with the static factories and fluent chaining — and reuse it for every execution. The first strategy in a chain is the outermost, exactly like ASP.NET middleware: Shield.Timeout(t).Retry(3) applies a total timeout around all retries.

public sealed class Shield
Inheritance
Shield
Inherited Members
Extension Methods

Remarks

Stateful strategies (circuit breakers, rate limiters, bulkheads) live with the shield instance they were created in. Composing that shield into others (via Wrap or Compose) intentionally shares the state; creating a new shield creates fresh state.

Properties

Empty

A shield with no strategies: executions pass straight through.

public static Shield Empty { get; }

Property Value

Shield

InvokesContinuationAtMostOnce

Gets whether every strategy guarantees invoking the execution continuation at most once. Custom strategies may opt in through InvokesContinuationAtMostOnce.

public bool InvokesContinuationAtMostOnce { get; }

Property Value

bool

Remarks

A live-forwarding shield reports false because a later publication may introduce retry, hedging, or another multi-attempt strategy.

Name

The shield's diagnostic name, if assigned via WithName.

public string? Name { get; }

Property Value

string

Methods

CircuitBreaker(Action<CircuitBreakerOptions>)

Adds a circuit breaker strategy configured via configure.

public static Shield CircuitBreaker(Action<CircuitBreakerOptions> configure)

Parameters

configure Action<CircuitBreakerOptions>

Returns

Shield

CircuitBreaker(int, TimeSpan)

Breaks the circuit for breakDuration after consecutiveFailures consecutive failures.

public static Shield CircuitBreaker(int consecutiveFailures, TimeSpan breakDuration)

Parameters

consecutiveFailures int
breakDuration TimeSpan

Returns

Shield

Compose(params Shield[])

Merges shields into one pipeline. The first shield is the outermost. Stateful strategies keep their identity, so a shared circuit breaker shield shares its circuit here. The result keeps the first non-null Name and TimeProvider among the inputs. Composition seals handling clauses, so reactive strategies appended afterwards use default handling unless a new clause is declared.

public static Shield Compose(params Shield[] shields)

Parameters

shields Shield[]

Returns

Shield

ConcurrencyLimit(Action<ConcurrencyLimitOptions>)

Adds a concurrency limit strategy configured via configure.

public static Shield ConcurrencyLimit(Action<ConcurrencyLimitOptions> configure)

Parameters

configure Action<ConcurrencyLimitOptions>

Returns

Shield

ConcurrencyLimit(int, int)

Caps concurrent executions at maxConcurrency with an optional wait queue.

public static Shield ConcurrencyLimit(int maxConcurrency, int queueLimit = 0)

Parameters

maxConcurrency int
queueLimit int

Returns

Shield

Execute(Action<CancellationToken>, CancellationToken)

Executes the void delegate synchronously through the pipeline.

public void Execute(Action<CancellationToken> action, CancellationToken cancellationToken = default)

Parameters

action Action<CancellationToken>
cancellationToken CancellationToken

ExecuteAsync(Func<CancellationToken, ValueTask>, CancellationToken)

Executes the void delegate through the pipeline.

public ValueTask ExecuteAsync(Func<CancellationToken, ValueTask> action, CancellationToken cancellationToken = default)

Parameters

action Func<CancellationToken, ValueTask>
cancellationToken CancellationToken

Returns

ValueTask

ExecuteAsync<T>(Func<CancellationToken, ValueTask<T>>, CancellationToken)

Executes the delegate through the pipeline. The delegate must use the cancellation token it is handed.

public ValueTask<T> ExecuteAsync<T>(Func<CancellationToken, ValueTask<T>> action, CancellationToken cancellationToken = default)

Parameters

action Func<CancellationToken, ValueTask<T>>
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExecuteAsync<TState>(TState, Func<TState, CancellationToken, ValueTask>, CancellationToken)

Executes the void delegate through the pipeline, threading state to avoid closure allocations.

public ValueTask ExecuteAsync<TState>(TState state, Func<TState, CancellationToken, ValueTask> action, CancellationToken cancellationToken = default)

Parameters

state TState
action Func<TState, CancellationToken, ValueTask>
cancellationToken CancellationToken

Returns

ValueTask

Type Parameters

TState

ExecuteAsync<T, TState>(TState, Func<TState, CancellationToken, ValueTask<T>>, CancellationToken)

Executes the delegate through the pipeline, threading state to avoid closure allocations.

public ValueTask<T> ExecuteAsync<T, TState>(TState state, Func<TState, CancellationToken, ValueTask<T>> action, CancellationToken cancellationToken = default)

Parameters

state TState
action Func<TState, CancellationToken, ValueTask<T>>
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T
TState

ExecuteOutcome(Action<CancellationToken>, CancellationToken)

Executes a void delegate synchronously and returns success or the captured exception.

public Outcome ExecuteOutcome(Action<CancellationToken> action, CancellationToken cancellationToken = default)

Parameters

action Action<CancellationToken>
cancellationToken CancellationToken

Returns

Outcome

ExecuteOutcomeAsync(Func<CancellationToken, ValueTask>, CancellationToken)

Executes a void delegate and returns success or the captured exception.

public ValueTask<Outcome> ExecuteOutcomeAsync(Func<CancellationToken, ValueTask> action, CancellationToken cancellationToken = default)

Parameters

action Func<CancellationToken, ValueTask>
cancellationToken CancellationToken

Returns

ValueTask<Outcome>

ExecuteOutcomeAsync<T>(Func<CancellationToken, ValueTask<T>>, CancellationToken)

Executes the delegate through the pipeline and returns the outcome instead of throwing.

public ValueTask<Outcome<T>> ExecuteOutcomeAsync<T>(Func<CancellationToken, ValueTask<T>> action, CancellationToken cancellationToken = default)

Parameters

action Func<CancellationToken, ValueTask<T>>
cancellationToken CancellationToken

Returns

ValueTask<Outcome<T>>

Type Parameters

T

ExecuteOutcomeAsync<TState>(TState, Func<TState, CancellationToken, ValueTask>, CancellationToken)

Executes a void delegate, threading state to avoid closure allocations, and returns success or the captured exception.

public ValueTask<Outcome> ExecuteOutcomeAsync<TState>(TState state, Func<TState, CancellationToken, ValueTask> action, CancellationToken cancellationToken = default)

Parameters

state TState
action Func<TState, CancellationToken, ValueTask>
cancellationToken CancellationToken

Returns

ValueTask<Outcome>

Type Parameters

TState

ExecuteOutcomeAsync<T, TState>(TState, Func<TState, CancellationToken, ValueTask<T>>, CancellationToken)

Executes the delegate through the pipeline, threading state to avoid closure allocations, and returns the outcome instead of throwing.

public ValueTask<Outcome<T>> ExecuteOutcomeAsync<T, TState>(TState state, Func<TState, CancellationToken, ValueTask<T>> action, CancellationToken cancellationToken = default)

Parameters

state TState
action Func<TState, CancellationToken, ValueTask<T>>
cancellationToken CancellationToken

Returns

ValueTask<Outcome<T>>

Type Parameters

T
TState

ExecuteOutcome<T>(Func<CancellationToken, T>, CancellationToken)

Executes a result-returning delegate synchronously and returns its outcome.

public Outcome<T> ExecuteOutcome<T>(Func<CancellationToken, T> action, CancellationToken cancellationToken = default)

Parameters

action Func<CancellationToken, T>
cancellationToken CancellationToken

Returns

Outcome<T>

Type Parameters

T

ExecuteOutcome<TState>(TState, Action<TState, CancellationToken>, CancellationToken)

Executes a void delegate synchronously, threading state to avoid closure allocations, and returns success or the captured exception.

public Outcome ExecuteOutcome<TState>(TState state, Action<TState, CancellationToken> action, CancellationToken cancellationToken = default)

Parameters

state TState
action Action<TState, CancellationToken>
cancellationToken CancellationToken

Returns

Outcome

Type Parameters

TState

ExecuteOutcome<T, TState>(TState, Func<TState, CancellationToken, T>, CancellationToken)

Executes a result-returning delegate synchronously, threading state to avoid closure allocations, and returns its outcome.

public Outcome<T> ExecuteOutcome<T, TState>(TState state, Func<TState, CancellationToken, T> action, CancellationToken cancellationToken = default)

Parameters

state TState
action Func<TState, CancellationToken, T>
cancellationToken CancellationToken

Returns

Outcome<T>

Type Parameters

T
TState

ExecuteWithContext(KevlarContext, Action<KevlarContext>)

Executes a context-aware void delegate synchronously through the pipeline using the properties, cancellation token, and time provider from parentContext.

public void ExecuteWithContext(KevlarContext parentContext, Action<KevlarContext> action)

Parameters

parentContext KevlarContext
action Action<KevlarContext>

ExecuteWithContext(Action<KevlarContext>, CancellationToken)

Executes a context-aware void delegate synchronously through the pipeline without seeding execution properties. The context is pooled and is valid only for the duration of the delegate invocation; never retain it.

public void ExecuteWithContext(Action<KevlarContext> action, CancellationToken cancellationToken = default)

Parameters

action Action<KevlarContext>
cancellationToken CancellationToken

ExecuteWithContextAsync(KevlarContext, Func<KevlarContext, ValueTask>)

Executes a context-aware void delegate through the pipeline using the properties, cancellation token, and time provider from parentContext.

public ValueTask ExecuteWithContextAsync(KevlarContext parentContext, Func<KevlarContext, ValueTask> action)

Parameters

parentContext KevlarContext
action Func<KevlarContext, ValueTask>

Returns

ValueTask

ExecuteWithContextAsync(Func<KevlarContext, ValueTask>, CancellationToken)

Executes a context-aware void delegate through the pipeline without seeding execution properties. The context is pooled and is valid only for the duration of the delegate invocation; never retain it.

public ValueTask ExecuteWithContextAsync(Func<KevlarContext, ValueTask> action, CancellationToken cancellationToken = default)

Parameters

action Func<KevlarContext, ValueTask>
cancellationToken CancellationToken

Returns

ValueTask

ExecuteWithContextAsync<T>(KevlarContext, Func<KevlarContext, ValueTask<T>>)

Executes a context-aware delegate through the pipeline using the properties, cancellation token, and time provider from parentContext.

public ValueTask<T> ExecuteWithContextAsync<T>(KevlarContext parentContext, Func<KevlarContext, ValueTask<T>> action)

Parameters

parentContext KevlarContext
action Func<KevlarContext, ValueTask<T>>

Returns

ValueTask<T>

Type Parameters

T

ExecuteWithContextAsync<TState>(KevlarContext, TState, Func<TState, KevlarContext, ValueTask>)

Executes a context-aware void delegate through the pipeline using the properties, cancellation token, and time provider from parentContext, threading state to avoid closure allocations.

public ValueTask ExecuteWithContextAsync<TState>(KevlarContext parentContext, TState state, Func<TState, KevlarContext, ValueTask> action)

Parameters

parentContext KevlarContext
state TState
action Func<TState, KevlarContext, ValueTask>

Returns

ValueTask

Type Parameters

TState

ExecuteWithContextAsync<T>(Func<KevlarContext, ValueTask<T>>, CancellationToken)

Executes a context-aware delegate through the pipeline without seeding execution properties. The context is pooled and is valid only for the duration of the delegate invocation; never retain it.

public ValueTask<T> ExecuteWithContextAsync<T>(Func<KevlarContext, ValueTask<T>> action, CancellationToken cancellationToken = default)

Parameters

action Func<KevlarContext, ValueTask<T>>
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExecuteWithContextAsync<TState>(TState, Action<TState, KevlarProperties>, Func<TState, KevlarContext, ValueTask>, Action<TState, KevlarProperties>, CancellationToken)

Initializes execution properties, executes a context-aware void delegate, then exposes the final properties to onCompleted before the pooled context is returned.

public ValueTask ExecuteWithContextAsync<TState>(TState state, Action<TState, KevlarProperties> initializeProperties, Func<TState, KevlarContext, ValueTask> action, Action<TState, KevlarProperties> onCompleted, CancellationToken cancellationToken = default)

Parameters

state TState
initializeProperties Action<TState, KevlarProperties>
action Func<TState, KevlarContext, ValueTask>
onCompleted Action<TState, KevlarProperties>
cancellationToken CancellationToken

Returns

ValueTask

Type Parameters

TState

ExecuteWithContextAsync<TState>(TState, Action<TState, KevlarProperties>, Func<TState, KevlarContext, ValueTask>, CancellationToken)

Initializes execution properties, then executes a context-aware void delegate through the pipeline. The context is pooled and is valid only for the duration of the delegate invocation; never retain it.

public ValueTask ExecuteWithContextAsync<TState>(TState state, Action<TState, KevlarProperties> initializeProperties, Func<TState, KevlarContext, ValueTask> action, CancellationToken cancellationToken = default)

Parameters

state TState
initializeProperties Action<TState, KevlarProperties>
action Func<TState, KevlarContext, ValueTask>
cancellationToken CancellationToken

Returns

ValueTask

Type Parameters

TState

ExecuteWithContextAsync<T, TState>(KevlarContext, TState, Func<TState, KevlarContext, ValueTask<T>>)

Executes a context-aware delegate through the pipeline using the properties, cancellation token, and time provider from parentContext, threading state to avoid closure allocations.

public ValueTask<T> ExecuteWithContextAsync<T, TState>(KevlarContext parentContext, TState state, Func<TState, KevlarContext, ValueTask<T>> action)

Parameters

parentContext KevlarContext
state TState
action Func<TState, KevlarContext, ValueTask<T>>

Returns

ValueTask<T>

Type Parameters

T
TState

ExecuteWithContextAsync<T, TState>(TState, Action<TState, KevlarProperties>, Func<TState, KevlarContext, ValueTask<T>>, Action<TState, KevlarProperties>, CancellationToken)

Initializes execution properties, executes a context-aware delegate, then exposes the final properties to onCompleted before the pooled context is returned.

public ValueTask<T> ExecuteWithContextAsync<T, TState>(TState state, Action<TState, KevlarProperties> initializeProperties, Func<TState, KevlarContext, ValueTask<T>> action, Action<TState, KevlarProperties> onCompleted, CancellationToken cancellationToken = default)

Parameters

state TState
initializeProperties Action<TState, KevlarProperties>
action Func<TState, KevlarContext, ValueTask<T>>
onCompleted Action<TState, KevlarProperties>
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T
TState

ExecuteWithContextAsync<T, TState>(TState, Action<TState, KevlarProperties>, Func<TState, KevlarContext, ValueTask<T>>, CancellationToken)

Initializes execution properties, then executes a context-aware delegate through the pipeline. The context is pooled and is valid only for the duration of the delegate invocation; never retain it.

public ValueTask<T> ExecuteWithContextAsync<T, TState>(TState state, Action<TState, KevlarProperties> initializeProperties, Func<TState, KevlarContext, ValueTask<T>> action, CancellationToken cancellationToken = default)

Parameters

state TState
initializeProperties Action<TState, KevlarProperties>
action Func<TState, KevlarContext, ValueTask<T>>
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T
TState

ExecuteWithContext<T>(KevlarContext, Func<KevlarContext, T>)

Executes a context-aware delegate synchronously through the pipeline using the properties, cancellation token, and time provider from parentContext.

public T ExecuteWithContext<T>(KevlarContext parentContext, Func<KevlarContext, T> action)

Parameters

parentContext KevlarContext
action Func<KevlarContext, T>

Returns

T

Type Parameters

T

ExecuteWithContext<TState>(KevlarContext, TState, Action<TState, KevlarContext>)

Executes a context-aware void delegate synchronously through the pipeline using the properties, cancellation token, and time provider from parentContext, threading state to avoid closure allocations.

public void ExecuteWithContext<TState>(KevlarContext parentContext, TState state, Action<TState, KevlarContext> action)

Parameters

parentContext KevlarContext
state TState
action Action<TState, KevlarContext>

Type Parameters

TState

ExecuteWithContext<T>(Func<KevlarContext, T>, CancellationToken)

Executes a context-aware delegate synchronously through the pipeline without seeding execution properties. The context is pooled and is valid only for the duration of the delegate invocation; never retain it.

public T ExecuteWithContext<T>(Func<KevlarContext, T> action, CancellationToken cancellationToken = default)

Parameters

action Func<KevlarContext, T>
cancellationToken CancellationToken

Returns

T

Type Parameters

T

ExecuteWithContext<TState>(TState, Action<TState, KevlarProperties>, Action<TState, KevlarContext>, CancellationToken)

Initializes execution properties, then executes a context-aware void delegate synchronously through the pipeline. The context is pooled and is valid only for the duration of the delegate invocation; never retain it.

public void ExecuteWithContext<TState>(TState state, Action<TState, KevlarProperties> initializeProperties, Action<TState, KevlarContext> action, CancellationToken cancellationToken = default)

Parameters

state TState
initializeProperties Action<TState, KevlarProperties>
action Action<TState, KevlarContext>
cancellationToken CancellationToken

Type Parameters

TState

ExecuteWithContext<T, TState>(KevlarContext, TState, Func<TState, KevlarContext, T>)

Executes a context-aware delegate synchronously through the pipeline using the properties, cancellation token, and time provider from parentContext, threading state to avoid closure allocations.

public T ExecuteWithContext<T, TState>(KevlarContext parentContext, TState state, Func<TState, KevlarContext, T> action)

Parameters

parentContext KevlarContext
state TState
action Func<TState, KevlarContext, T>

Returns

T

Type Parameters

T
TState

ExecuteWithContext<T, TState>(TState, Action<TState, KevlarProperties>, Func<TState, KevlarContext, T>, CancellationToken)

Initializes execution properties, then executes a context-aware delegate synchronously through the pipeline. The context is pooled and is valid only for the duration of the delegate invocation; never retain it.

public T ExecuteWithContext<T, TState>(TState state, Action<TState, KevlarProperties> initializeProperties, Func<TState, KevlarContext, T> action, CancellationToken cancellationToken = default)

Parameters

state TState
initializeProperties Action<TState, KevlarProperties>
action Func<TState, KevlarContext, T>
cancellationToken CancellationToken

Returns

T

Type Parameters

T
TState

Execute<T>(Func<CancellationToken, T>, CancellationToken)

Executes the delegate synchronously through the pipeline. Delays (retry backoff, rate limit waits) block the calling thread. Hedging is not supported synchronously.

public T Execute<T>(Func<CancellationToken, T> action, CancellationToken cancellationToken = default)

Parameters

action Func<CancellationToken, T>
cancellationToken CancellationToken

Returns

T

Type Parameters

T

Execute<TState>(TState, Action<TState, CancellationToken>, CancellationToken)

Executes the void delegate synchronously, threading state to avoid closure allocations.

public void Execute<TState>(TState state, Action<TState, CancellationToken> action, CancellationToken cancellationToken = default)

Parameters

state TState
action Action<TState, CancellationToken>
cancellationToken CancellationToken

Type Parameters

TState

Execute<T, TState>(TState, Func<TState, CancellationToken, T>, CancellationToken)

Executes the delegate synchronously, threading state to avoid closure allocations.

public T Execute<T, TState>(TState state, Func<TState, CancellationToken, T> action, CancellationToken cancellationToken = default)

Parameters

state TState
action Func<TState, CancellationToken, T>
cancellationToken CancellationToken

Returns

T

Type Parameters

T
TState

Fallback(Func<Exception, CancellationToken, ValueTask>)

Starts a pipeline with a fallback that runs fallback in place of handled failures, receiving the handled exception. Applies to void executions only; result-returning executions fail with a descriptive InvalidOperationException — use Shield.For<T>().FallbackTo(…) for constant values or its typed Fallback(…) overloads for factories.

public static Shield Fallback(Func<Exception, CancellationToken, ValueTask> fallback)

Parameters

fallback Func<Exception, CancellationToken, ValueTask>

Returns

Shield

Remarks

A fallback is legitimately the outermost strategy: it recovers what everything chained inside it could not.

Fallback(Func<Exception, CancellationToken, ValueTask>, Action<FallbackOptions>)

Starts a pipeline with a fallback that runs fallback in place of handled failures and configures notifications. Applies to void executions only.

public static Shield Fallback(Func<Exception, CancellationToken, ValueTask> fallback, Action<FallbackOptions> configure)

Parameters

fallback Func<Exception, CancellationToken, ValueTask>
configure Action<FallbackOptions>

Returns

Shield

Remarks

Runs and awaits OnFallback before recovery. Notification failures are reported and recovery continues.

Fallback(Func<CancellationToken, ValueTask>)

Starts a pipeline with a fallback that runs fallback in place of handled failures. Applies to void executions only; result-returning executions fail with a descriptive InvalidOperationException. Use Shield.For<T>().FallbackTo(…) for constant values or its typed Fallback(…) overloads for factories.

public static Shield Fallback(Func<CancellationToken, ValueTask> fallback)

Parameters

fallback Func<CancellationToken, ValueTask>

Returns

Shield

Fallback(Func<CancellationToken, ValueTask>, Action<FallbackOptions>)

Starts a pipeline with a fallback that runs fallback in place of handled failures and configures notifications. Applies to void executions only.

public static Shield Fallback(Func<CancellationToken, ValueTask> fallback, Action<FallbackOptions> configure)

Parameters

fallback Func<CancellationToken, ValueTask>
configure Action<FallbackOptions>

Returns

Shield

Remarks

Runs and awaits OnFallback before recovery. Notification failures are reported and recovery continues.

For<TResult>()

Starts a result-aware shield for executions returning TResult.

public static Shield<TResult> For<TResult>()

Returns

Shield<TResult>

Type Parameters

TResult

Hedge(Action<HedgeOptions>)

Adds a hedging strategy configured via configure.

public static Shield Hedge(Action<HedgeOptions> configure)

Parameters

configure Action<HedgeOptions>

Returns

Shield

Remarks

Hedging on an untyped Shield runs the execution delegate more than once, concurrently, so the delegate must be idempotent. Prefer For<TResult>(), or confirm the action is safe to repeat.

Hedge(int, TimeSpan)

Races the primary with up to maxHedgedAttempts additional attempts staggered by delay; first acceptable outcome wins.

public static Shield Hedge(int maxHedgedAttempts, TimeSpan delay)

Parameters

maxHedgedAttempts int

Maximum additional attempts after the primary attempt.

delay TimeSpan

The delay between attempts. Zero launches attempts in parallel; any negative value launches another attempt only after a handled failure.

Returns

Shield

Remarks

Hedging on an untyped Shield runs the execution delegate more than once, concurrently, and only its exceptions can select a winner. The delegate must therefore be idempotent: duplicate writes, charges, or sends are otherwise observable side effects of a hedge that later loses. Prefer For<TResult>(), where result clauses decide which attempt is acceptable, or confirm the action is safe to repeat.

RateLimit(Action<RateLimitOptions>)

Adds a rate limit strategy configured via configure.

public static Shield RateLimit(Action<RateLimitOptions> configure)

Parameters

configure Action<RateLimitOptions>

Returns

Shield

RateLimit(int, TimeSpan)

Limits throughput to permits executions per perWindow (token bucket).

public static Shield RateLimit(int permits, TimeSpan perWindow)

Parameters

permits int
perWindow TimeSpan

Returns

Shield

Retry(Action<RetryOptions>)

Adds a retry strategy configured via configure.

public static Shield Retry(Action<RetryOptions> configure)

Parameters

configure Action<RetryOptions>

Returns

Shield

Remarks

MaxRetries counts retries, not attempts: MaxRetries = 3 makes up to 4 total attempts — the initial call plus 3 retries.

Retry(int)

Retries failed executions up to maxRetries times with Default: exponential from 250 milliseconds with factor 2, equal jitter, and a 30-second cap.

public static Shield Retry(int maxRetries = 3)

Parameters

maxRetries int

The number of retries, not the number of attempts: Retry(3) makes up to 4 total attempts — the initial call plus 3 retries.

Returns

Shield

Retry(int, Backoff)

Retries failed executions up to maxRetries times with the given backoff.

public static Shield Retry(int maxRetries, Backoff backoff)

Parameters

maxRetries int

The number of retries, not the number of attempts: Retry(3) makes up to 4 total attempts — the initial call plus 3 retries.

backoff Backoff

The delay computation applied between attempts.

Returns

Shield

RetryForever()

Retries failed executions indefinitely with Default: exponential from 250 milliseconds with factor 2, equal jitter, and a 30-second cap.

public static Shield RetryForever()

Returns

Shield

RetryForever(Backoff)

Retries failed executions indefinitely with the given backoff.

public static Shield RetryForever(Backoff backoff)

Parameters

backoff Backoff

The delay computation applied between attempts.

Returns

Shield

Timeout(Action<TimeoutOptions>)

Adds a timeout strategy configured via configure.

public static Shield Timeout(Action<TimeoutOptions> configure)

Parameters

configure Action<TimeoutOptions>

Returns

Shield

Timeout(TimeSpan)

Cancels executions that exceed timeout, surfacing TimeoutExceededException.

public static Shield Timeout(TimeSpan timeout)

Parameters

timeout TimeSpan

Returns

Shield

ToString()

Describes the pipeline, outermost strategy first, e.g. Timeout(30s) → Retry(3, exponential 250ms ×2, equal jitter, cap 30s) → CircuitBreaker(5 consecutive, break 30s).

public override string ToString()

Returns

string

Use(Strategy)

Starts a pipeline with a custom Strategy implementation.

public static Shield Use(Strategy strategy)

Parameters

strategy Strategy

Returns

Shield

Use(Func<HandlingClause, Strategy>)

Starts a pipeline with a custom strategy created from the default handling clause. The factory runs once when the strategy is appended.

public static Shield Use(Func<HandlingClause, Strategy> factory)

Parameters

factory Func<HandlingClause, Strategy>

Returns

Shield

When(Func<Exception, bool>)

Starts a handling clause for exceptions matching predicate. Use WithDefaultHandling(Shield) to return to default handling.

public static ShieldBuilder When(Func<Exception, bool> predicate)

Parameters

predicate Func<Exception, bool>

Returns

ShieldBuilder

WhenContext(Func<HandlingEvent, bool>)

Starts a handling clause using the active execution and strategy context.

public static ShieldBuilder WhenContext(Func<HandlingEvent, bool> predicate)

Parameters

predicate Func<HandlingEvent, bool>

Returns

ShieldBuilder

WhenInner<TException>()

Starts a handling clause for exceptions containing an exception of type TException. Use WithDefaultHandling(Shield) to return to default handling.

public static ShieldBuilder WhenInner<TException>() where TException : Exception

Returns

ShieldBuilder

Type Parameters

TException

Remarks

The outer exception, ordinary inner-exception chains, and every branch of an AggregateException are searched.

WhenInner<TException>(Func<TException, bool>)

Starts a handling clause for exceptions containing an exception of type TException matching predicate. Use WithDefaultHandling(Shield) to return to default handling.

public static ShieldBuilder WhenInner<TException>(Func<TException, bool> predicate) where TException : Exception

Parameters

predicate Func<TException, bool>

Returns

ShieldBuilder

Type Parameters

TException

Remarks

The outer exception, ordinary inner-exception chains, and every branch of an AggregateException are searched.

When<TException>()

Starts a handling clause: subsequent reactive strategies act on exceptions of type TException. Use WithDefaultHandling(Shield) to return to default handling.

public static ShieldBuilder When<TException>() where TException : Exception

Returns

ShieldBuilder

Type Parameters

TException

When<TException>(Func<TException, bool>)

Starts a handling clause for exceptions of type TException matching predicate. Use WithDefaultHandling(Shield) to return to default handling.

public static ShieldBuilder When<TException>(Func<TException, bool> predicate) where TException : Exception

Parameters

predicate Func<TException, bool>

Returns

ShieldBuilder

Type Parameters

TException