Class AsyncActionDecorator<TIn>
- Namespace
- PatternKit.Structural.Decorator
- Assembly
- PatternKit.Core.dll
Fluent, allocation-light async action decorator that wraps a component and applies layered enhancements for async side effects (void-returning async operations). Build once, then call ExecuteAsync(TIn, CancellationToken) to run the component through the decorator pipeline.
public sealed class AsyncActionDecorator<TIn>
Type Parameters
TInInput type passed to the component.
- Inheritance
-
AsyncActionDecorator<TIn>
- Inherited Members
Examples
var decorator = AsyncActionDecorator<string>.Create(
async (msg, ct) => await SaveToDbAsync(msg, ct))
.Before(async (msg, ct) => $"[{DateTime.UtcNow}] {msg}")
.After(async (msg, ct) => await LogAsync("Saved", ct))
.Build();
await decorator.ExecuteAsync("Hello");
Remarks
Mental model: A base async action is wrapped by zero or more async decorators.
Immutability: After Build(), the decorator chain is immutable and safe for concurrent reuse.
Methods
Create(Component)
Creates a new builder for constructing an async decorated action.
public static AsyncActionDecorator<TIn>.Builder Create(AsyncActionDecorator<TIn>.Component component)
Parameters
componentAsyncActionDecorator<TIn>.Component
Returns
ExecuteAsync(TIn, CancellationToken)
Executes the decorated action asynchronously.
public ValueTask ExecuteAsync(TIn input, CancellationToken ct = default)
Parameters
inputTInctCancellationToken