Skip to content

feat(stages): add IRequestStage and stage pipeline - #2

Merged
illia1f merged 1 commit into
mainfrom
feat/stage-contract-and-executor
Aug 1, 2026
Merged

feat(stages): add IRequestStage and stage pipeline#2
illia1f merged 1 commit into
mainfrom
feat/stage-contract-and-executor

Conversation

@illia1f

@illia1f illia1f commented Aug 1, 2026

Copy link
Copy Markdown
Owner

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 void IRequestStage<TRequest> in Abstractions, with StageDelegate<TResponse> and StageDelegate as the continuation. Both forms share one chain, in registration order.
  • AddStage(typeof(LoggingStage<,>)) and AddStage<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 next short-circuits the handler and every inner stage. Calling next again after its task completes reruns the rest of the chain (the retry shape); overlapping calls throw InvalidOperationException.

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 InvalidOperationException naming the culprit instead of surfacing as a NullReferenceException at the await.

Docs

docs/stages.md is new. README, ROADMAP, docs/exceptions.md, and docs/registration.md no 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 test green: 174 tests per target framework, run on net8.0, net10.0, and net462.

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.
@illia1f
illia1f merged commit c794ad9 into main Aug 1, 2026
1 check passed
@illia1f
illia1f deleted the feat/stage-contract-and-executor branch August 1, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant