feat(stages): add IRequestStage and stage pipeline - #2
Merged
Conversation
Last v1 piece missing from the dispatcher. A stage wraps the handler of every request it applies to, and the stage class's own generic constraints decide which requests those are, so no list of types sits next to the registration. - IRequestStage<TRequest, TResponse> and the void IRequestStage<TRequest> in Abstractions, with StageDelegate as the continuation. - AddStage, WhereHandlerImplements, and DisallowUnusedStages on the same options object as scanning. - Startup validation for the new failure modes: non-concrete or partially closed stage types, an open generic that does not use its own parameters as the request, duplicate registrations, two declarations reaching one request as the same stage class, and unused stages when opted in. - Chains close once while the dispatch map is built. Dispatch walks a prebuilt array, still with no reflection, LINQ, or locking. - A null task from a handler or a stage throws InvalidOperationException naming the culprit instead of a NullReferenceException at the await. - docs/stages.md, plus the README and roadmap entries that assumed stages were still unbuilt.
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.
Last v1 checkbox before the benchmark suite. Stages are RequestFlow's answer to
IPipelineBehavior<,>.A stage wraps the handler of every request it applies to. Which requests those are comes from the stage class's own generic constraints, so no list of request types sits next to the registration.
Surface
IRequestStage<TRequest, TResponse>and the voidIRequestStage<TRequest>in Abstractions, withStageDelegate<TResponse>andStageDelegateas the continuation. Both forms share one chain, in registration order.AddStage(typeof(LoggingStage<,>))andAddStage<TStage>()chain on the same configure delegate as scanning. Registration order is execution order, outermost first.WhereHandlerImplements<T>()narrows a stage to requests whose handler implements a contract.DisallowUnusedStages()turns a stage that reaches nothing into a validation problem instead of a silent no-op.Dispatch
Chains close once, while the dispatch map is built. Dispatch walks a prebuilt array of resolved stages, still without reflection, LINQ, or locking.
Skipping
nextshort-circuits the handler and every inner stage. Callingnextagain after its task completes reruns the rest of the chain (the retry shape); overlapping calls throwInvalidOperationException.Validation
Stage problems join the single
RequestFlowValidationException: interfaces and abstract classes, partially closed generics, an open generic whose contract does not use its own type parameters as the request, duplicate stage types, two declarations reaching one request as the same stage class, and unused stages when opted in.A null task from a handler or a stage throws
InvalidOperationExceptionnaming the culprit instead of surfacing as aNullReferenceExceptionat the await.Docs
docs/stages.mdis new. README, ROADMAP,docs/exceptions.md, anddocs/registration.mdno longer describe stages as unbuilt. README also picks up NuGet badges and a MediatR mapping table.Tests
Six stage test files covering closing, executor semantics, pipeline order, lifetimes, and registration.
dotnet testgreen: 174 tests per target framework, run on net8.0, net10.0, and net462.