Skip to content

CommandR: Diagrams

Diagrams for the CommandR concepts introduced in Part 4.

Command Handler Pipeline

HandlerPriorityTypePurpose
PreparedCommandHandler1,000,000,000FilterCalls IPreparedCommand.Prepare() if implemented
CommandTracer998,000,000FilterCreates Activity for tracing, logs errors
LocalCommandRunner900,000,000FilterRuns ILocalCommand.Run() if implemented
RpcCommandHandler800,000,000FilterRoutes to RPC if command should be handled remotely
OperationReprocessor100,000FilterOperations Framework
NestedOperationLogger11,000FilterOperations Framework
OperationScopeProvider10,000FilterOperations Framework
DbOperationScopeProvider1,000FilterOperations Framework
Your Handler0FinalYour business logic

CommandContext Hierarchy for Nested Commands

PropertyBehavior
ServiceScopeShared across all nested contexts (same ICommander)
ItemsEach context has its own dictionary
OutermostContextAlways points to the root context
Data sharingUse context.OutermostContext.Items to share across contexts

IOutermostCommand Behavior

IDelegatingCommand Behavior

Code in CommandContext.New():

csharp
if (!isOutermost && (command is IOutermostCommand ||
                     Current?.UntypedCommand is IDelegatingCommand))
    isOutermost = true;

IEventCommand Parallel Execution

ScenarioBehavior
ChainId is emptyRunEvent() builds chains, clones command for each, runs in parallel
ChainId is setGoes through RunCommand(), executes only that specific handler chain

ChainId format: {ServiceType.GetName()}.{Method.Name}

ISessionCommand Processing (RpcDefaultSessionReplacer)

RpcDefaultSessionReplacer Logic

StepAction
1Check if first param is ISessionCommand
2Get SessionBoundRpcConnection from peer
3If session.IsDefault(): command.SetSession(connection.Session)
4Else: session.RequireValid()

Session Resolution Flow

Handler Registration and Resolution

Registration (at startup)

Resolution (at runtime)

IndexHandlerPriorityType
[0]PreparedCommandHandler1,000,000,000Filter
[1]CommandTracer998,000,000Filter
[2]LocalCommandRunner900,000,000Filter
[3]RpcCommandHandler800,000,000Filter
[4]OperationReprocessor100,000Filter
[5]NestedOperationLogger11,000Filter
[6]InMemoryOperationScope10,000Filter
[7]DbOperationScopeProvider1,000Filter
[8]YourHandler0Final

Command Service Proxy (AOP)

Call StyleResult
commander.Call(new CreateOrderCommand(...), ct)Full pipeline
orderService.CreateOrder(new CreateOrderCommand(...), ct)Full pipeline (via proxy)

Both paths go through: PreparedCommandHandlerCommandTracer → ... → Handler