Path: redb-route/redb.Route/Abstractions/ScopeNesting.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/Abstractions/ScopeNesting.cs
----
namespace redb.Route.Abstractions;
/// Severity of an verdict.
public enum NestingPolicy
{
/// The nesting is fine.
Allowed,
/// Allowed but semantically risky — emit a build warning.
Warn,
/// Structurally ill-formed — fail the build.
Forbid
}
/// Result of evaluating an against one enclosing scope.
/// What to do about the nesting.
/// Human-readable reason (required for Warn/Forbid).
public readonly record struct NestingVerdict(NestingPolicy Policy, string? Message)
{
/// No constraint.
public static NestingVerdict Allowed => new(NestingPolicy.Allowed, null);
/// Allowed but risky — warn with the given message.
public static NestingVerdict Warn(string message) => new(NestingPolicy.Warn, message);
/// Ill-formed — fail the build with the given message.
public static NestingVerdict Forbid(string message) => new(NestingPolicy.Forbid, message);
}
///
/// Marker: a branching scope whose body is a bounded sub-region — the exchange is
/// conditionally executed (Filter), branched (Choice), or fanned out (Split/Multicast). A node with
/// linear "tail" semantics (e.g. a replay checkpoint) generally cannot span such a boundary.
///
public interface ICompositeScope { }
///
/// Marker: a durable/transactional scope (e.g. Transaction). Nesting is structurally fine,
/// but a re-invocation (replay) runs OUTSIDE the original transaction — usually a warn, not a forbid.
///
public interface IDurableScope { }
///
/// Declarative nesting constraint on a definition — reusable, generic validation instead of ad-hoc
/// per-type checks in the validator. While walking the definition tree the validator calls
/// for each enclosing scope (a node implementing );
/// a fails the build, a logs a
/// warning. Any future definition that must constrain where it nests just implements this interface —
/// the validator never changes.
///
/// Scopes advertise their category with marker interfaces (,
/// ), so a rule reacts to a category rather than to concrete types.
///
///
public interface IScopeNestingRule
{
/// Evaluates this node's policy against one enclosing scope ancestor.
/// An enclosing scope definition (nearest and outer scopes are both offered).
NestingVerdict CheckAncestor(IProcessorDefinition ancestor);
}
///
/// Implemented by definitions whose logical children live outside
/// — e.g. a Choice keeps its When/Otherwise
/// branches in dedicated lists. A generic tree-walk (validation, analysis) recurses into
/// so it reaches those children without any per-type knowledge.
///
public interface IBranchingDefinition
{
/// Child definitions not present in .
IEnumerable Branches { get; }
}