Path: redb-route/redb.Route/Definitions/NodePipeline.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Definitions/NodePipeline.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Processors;
namespace redb.Route.Definitions;
///
/// The single place where a scope definition's child steps are compiled into a body processor.
///
/// Previously every scope definition (Choice, Filter, CircuitBreaker, TryCatch, Loop, Metered,
/// Replayable, Aggregate, IdempotentConsumer, Resequence, Threads, Traced, Transaction, Throttle,
/// Debounce, …) carried its own identical copy of the "0 → no-op / 1 → the single child / N → a
/// pipeline" logic. Routing them all through removes that duplication and — because
/// every child now compiles through — gives one seam to decorate each node (e.g.
/// Message History) at compile time.
///
///
/// Behaviour is identical to the old per-definition builders: the empty body is a no-op
/// ; a single child is returned unwrapped; multiple children form a
/// . This does not touch the DSL — the Outputs/scope tree
/// the builders walk is built entirely by the fluent API and its End* closers.
///
///
public static class NodePipeline
{
///
/// Compiles one child definition into its runtime processor — the per-node seam. Routes through
/// when the context is a (so a
/// node can be decorated), falling back to a plain compile otherwise (e.g. a test double).
///
public static IProcessor Node(IRouteContext context, IProcessorDefinition definition)
=> context is RouteContext rc
? rc.CompileNode(definition)
: definition.CreateProcessor(context);
/// Compiles a list of child definitions into a body processor (0 → no-op, 1 → the child, N → pipeline).
public static IProcessor Body(IRouteContext context, IList outputs) =>
outputs.Count switch
{
0 => new DelegateProcessor(_ => { }),
1 => Node(context, outputs[0]),
_ => BuildMulti(context, outputs),
};
private static PipelineProcessor BuildMulti(IRouteContext context, IList outputs)
{
var pipeline = new PipelineProcessor();
foreach (var output in outputs)
pipeline.Add(Node(context, output));
return pipeline;
}
}