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
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
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
Methods
CircuitBreaker(Action<CircuitBreakerOptions>)
Adds a circuit breaker strategy configured via configure.
public static Shield CircuitBreaker(Action<CircuitBreakerOptions> configure)
Parameters
configureAction<CircuitBreakerOptions>
Returns
CircuitBreaker(int, TimeSpan)
Breaks the circuit for breakDuration after consecutiveFailures consecutive failures.
public static Shield CircuitBreaker(int consecutiveFailures, TimeSpan breakDuration)
Parameters
Returns
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
shieldsShield[]
Returns
ConcurrencyLimit(Action<ConcurrencyLimitOptions>)
Adds a concurrency limit strategy configured via configure.
public static Shield ConcurrencyLimit(Action<ConcurrencyLimitOptions> configure)
Parameters
configureAction<ConcurrencyLimitOptions>
Returns
ConcurrencyLimit(int, int)
Caps concurrent executions at maxConcurrency with an optional wait queue.
public static Shield ConcurrencyLimit(int maxConcurrency, int queueLimit = 0)
Parameters
Returns
Execute(Action<CancellationToken>, CancellationToken)
Executes the void delegate synchronously through the pipeline.
public void Execute(Action<CancellationToken> action, CancellationToken cancellationToken = default)
Parameters
actionAction<CancellationToken>cancellationTokenCancellationToken
ExecuteAsync(Func<CancellationToken, ValueTask>, CancellationToken)
Executes the void delegate through the pipeline.
public ValueTask ExecuteAsync(Func<CancellationToken, ValueTask> action, CancellationToken cancellationToken = default)
Parameters
actionFunc<CancellationToken, ValueTask>cancellationTokenCancellationToken
Returns
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
actionFunc<CancellationToken, ValueTask<T>>cancellationTokenCancellationToken
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
stateTStateactionFunc<TState, CancellationToken, ValueTask>cancellationTokenCancellationToken
Returns
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
stateTStateactionFunc<TState, CancellationToken, ValueTask<T>>cancellationTokenCancellationToken
Returns
- ValueTask<T>
Type Parameters
TTState
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
actionAction<CancellationToken>cancellationTokenCancellationToken
Returns
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
actionFunc<CancellationToken, ValueTask>cancellationTokenCancellationToken
Returns
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
actionFunc<CancellationToken, ValueTask<T>>cancellationTokenCancellationToken
Returns
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
stateTStateactionFunc<TState, CancellationToken, ValueTask>cancellationTokenCancellationToken
Returns
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
stateTStateactionFunc<TState, CancellationToken, ValueTask<T>>cancellationTokenCancellationToken
Returns
Type Parameters
TTState
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
actionFunc<CancellationToken, T>cancellationTokenCancellationToken
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
stateTStateactionAction<TState, CancellationToken>cancellationTokenCancellationToken
Returns
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
stateTStateactionFunc<TState, CancellationToken, T>cancellationTokenCancellationToken
Returns
- Outcome<T>
Type Parameters
TTState
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
parentContextKevlarContextactionAction<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
actionAction<KevlarContext>cancellationTokenCancellationToken
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
parentContextKevlarContextactionFunc<KevlarContext, ValueTask>
Returns
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
actionFunc<KevlarContext, ValueTask>cancellationTokenCancellationToken
Returns
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
parentContextKevlarContextactionFunc<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
parentContextKevlarContextstateTStateactionFunc<TState, KevlarContext, ValueTask>
Returns
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
actionFunc<KevlarContext, ValueTask<T>>cancellationTokenCancellationToken
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
stateTStateinitializePropertiesAction<TState, KevlarProperties>actionFunc<TState, KevlarContext, ValueTask>onCompletedAction<TState, KevlarProperties>cancellationTokenCancellationToken
Returns
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
stateTStateinitializePropertiesAction<TState, KevlarProperties>actionFunc<TState, KevlarContext, ValueTask>cancellationTokenCancellationToken
Returns
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
parentContextKevlarContextstateTStateactionFunc<TState, KevlarContext, ValueTask<T>>
Returns
- ValueTask<T>
Type Parameters
TTState
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
stateTStateinitializePropertiesAction<TState, KevlarProperties>actionFunc<TState, KevlarContext, ValueTask<T>>onCompletedAction<TState, KevlarProperties>cancellationTokenCancellationToken
Returns
- ValueTask<T>
Type Parameters
TTState
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
stateTStateinitializePropertiesAction<TState, KevlarProperties>actionFunc<TState, KevlarContext, ValueTask<T>>cancellationTokenCancellationToken
Returns
- ValueTask<T>
Type Parameters
TTState
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
parentContextKevlarContextactionFunc<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
parentContextKevlarContextstateTStateactionAction<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
actionFunc<KevlarContext, T>cancellationTokenCancellationToken
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
stateTStateinitializePropertiesAction<TState, KevlarProperties>actionAction<TState, KevlarContext>cancellationTokenCancellationToken
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
parentContextKevlarContextstateTStateactionFunc<TState, KevlarContext, T>
Returns
- T
Type Parameters
TTState
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
stateTStateinitializePropertiesAction<TState, KevlarProperties>actionFunc<TState, KevlarContext, T>cancellationTokenCancellationToken
Returns
- T
Type Parameters
TTState
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
actionFunc<CancellationToken, T>cancellationTokenCancellationToken
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
stateTStateactionAction<TState, CancellationToken>cancellationTokenCancellationToken
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
stateTStateactionFunc<TState, CancellationToken, T>cancellationTokenCancellationToken
Returns
- T
Type Parameters
TTState
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
fallbackFunc<Exception, CancellationToken, ValueTask>
Returns
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
fallbackFunc<Exception, CancellationToken, ValueTask>configureAction<FallbackOptions>
Returns
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
fallbackFunc<CancellationToken, ValueTask>
Returns
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
fallbackFunc<CancellationToken, ValueTask>configureAction<FallbackOptions>
Returns
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
configureAction<HedgeOptions>
Returns
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
maxHedgedAttemptsintMaximum additional attempts after the primary attempt.
delayTimeSpanThe delay between attempts. Zero launches attempts in parallel; any negative value launches another attempt only after a handled failure.
Returns
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
configureAction<RateLimitOptions>
Returns
RateLimit(int, TimeSpan)
Limits throughput to permits executions per perWindow (token bucket).
public static Shield RateLimit(int permits, TimeSpan perWindow)
Parameters
Returns
Retry(Action<RetryOptions>)
Adds a retry strategy configured via configure.
public static Shield Retry(Action<RetryOptions> configure)
Parameters
configureAction<RetryOptions>
Returns
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
maxRetriesintThe number of retries, not the number of attempts:
Retry(3)makes up to 4 total attempts — the initial call plus 3 retries.
Returns
Retry(int, Backoff)
Retries failed executions up to maxRetries times with the given backoff.
public static Shield Retry(int maxRetries, Backoff backoff)
Parameters
maxRetriesintThe number of retries, not the number of attempts:
Retry(3)makes up to 4 total attempts — the initial call plus 3 retries.backoffBackoffThe delay computation applied between attempts.
Returns
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
RetryForever(Backoff)
Retries failed executions indefinitely with the given backoff.
public static Shield RetryForever(Backoff backoff)
Parameters
backoffBackoffThe delay computation applied between attempts.
Returns
Timeout(Action<TimeoutOptions>)
Adds a timeout strategy configured via configure.
public static Shield Timeout(Action<TimeoutOptions> configure)
Parameters
configureAction<TimeoutOptions>
Returns
Timeout(TimeSpan)
Cancels executions that exceed timeout, surfacing TimeoutExceededException.
public static Shield Timeout(TimeSpan timeout)
Parameters
timeoutTimeSpan
Returns
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
Use(Strategy)
Starts a pipeline with a custom Strategy implementation.
public static Shield Use(Strategy strategy)
Parameters
strategyStrategy
Returns
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
factoryFunc<HandlingClause, Strategy>
Returns
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
Returns
WhenContext(Func<HandlingEvent, bool>)
Starts a handling clause using the active execution and strategy context.
public static ShieldBuilder WhenContext(Func<HandlingEvent, bool> predicate)
Parameters
predicateFunc<HandlingEvent, bool>
Returns
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
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
Returns
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
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
Returns
Type Parameters
TException