Composable per-item middleware / interceptor (#93) - #334
Merged
Conversation
Add IItemMiddleware<T> + MiddlewareResult<T> (Continue/Drop) and WithMiddleware(...) extensions that attach cross-cutting per-item behaviour (logging, validation, metrics, throttling, dedup) to any IAsyncEnumerable<T> stream — extractor/transformer output or loader input — without changing the component, and compose inside an EtlPipeline via Through(s => s.WithMiddleware(...)). Single and ordered-chain overloads; a dropped item short-circuits the rest of the chain. Dependency-free. - 15 MiddlewareTests (transform, drop, chain order, stop-at-drop, empty chain, token flow, pipeline composition, null guards) + MiddlewareResult value semantics. 441 unit tests pass; Stryker 100.00% (0 survivors). - PublicAPI.Unshipped updated (RS0016 completeness + RS0017 correctness validated). - CHANGELOG [Unreleased] Added entry. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jul 28, 2026
This was referenced Jul 30, 2026
This was referenced Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #93. Stacked on #333 (#94) — base is
feat/94-retry-seam.Summary
Adds a dependency-free middleware / interceptor mechanism for cross-cutting per-item concerns:
IItemMiddleware<T>—ValueTask<MiddlewareResult<T>> OnItemAsync(T item, CancellationToken).MiddlewareResult<T>— value type withItem+Skip, built viaMiddlewareResult.Continue(item)(keep/replace) orMiddlewareResult.Drop<T>()(remove).WithMiddleware(...)extensions onIAsyncEnumerable<T>— a single middleware or an ordered chain (each sees the previous one's output; a drop short-circuits the rest of the chain).Because it decorates a stream, it composes anywhere — extractor/transformer output, loader input, and inside an
EtlPipeline:Design notes
MiddlewareResult<T>has full value equality (satisfies CA1815); the factory methods live on a non-genericMiddlewareResultcompanion (CA1000-clean).OnItemErrorstill wraps its own worker — they compose without overlap.Verification
MiddlewareTests+MiddlewareResultvalue-semantics: transform, drop, chain order, stop-at-drop, empty chain, token flow,EtlPipelinecomposition, all null guards).ConfigureAwait(false), theGetHashCodeformula, and the diagnostic message string — marked with justified// Stryker disable oncecomments per repo convention).Notes for release-prep (not in this PR)
Targets the 0.20.0 line (
vNext-plus-one). Version bump 0.19.0 → 0.20.0 and baseline → 0.19.0 are deferred to 0.20.0 release-prep, gated on 0.19.0 publishing.