Command (Main Envelope)
Command is the single envelope class for all commands in the system. Created via the static Create factory with a Domain and verb, it inherits Params from Message for carrying typed data. The verb is immutable once created, ensuring the receiver always knows what action was requested. Callers populate command.Params before sending it via BusUtility.Send.
public sealed class Command : Message, ICommand
{
public int Verb { get; }
public static Command Create(Domain targetDomain, int verb)
}ICommand (Contract)
ICommand defines the interface all commands expose: TargetDomain for routing, Verb for action identification, and Params for typed data. Implemented by Command; received and handled by flow controllers and command processors.
IFlowControllable and ICommandProcessor (Handler Contracts)
IFlowControllable marks components that register themselves with a flow controller under a RegistrationKey. ICommandProcessor defines the ProcessCommand method that receives a routed command. Together, they establish the pattern where a flow controller looks up a registered processor by key and delegates command handling to it.
public interface IFlowControllable
{
string RegistrationKey { get; }
void Register();
}
public interface ICommandProcessor
{
void ProcessCommand(ICommand cmd);
}Integration with FlowController
The FlowController base class owns one Domain and registers its HandleCommand method on the CommandBus during initialization. When the bus routes a command to that domain, HandleCommand receives it. The concrete flow controller implementation (e.g., UIFlowController) typically looks up a registered handler using the command's verb or a parameter like RegistrationKey, then delegates to that handler's ProcessCommand method.
Integration with CommandBus
The CommandBus routes commands by their TargetDomain, delivering each to the single handler registered for that domain. If no handler is ready, the command is queued and delivered once the domain's handler registers and signals readiness. This queueing ensures no command is lost during system startup.
Data Flow
- A caller (often in one domain) creates a command via
Command.Create(Domain.UI, verb). - The caller populates
command.Params.Set(key, value)with any data the receiver needs. - The caller sends the command via
BusUtility.Send(command). - The
CommandBusroutes the command to the flow controller registered forDomain.UI. UIFlowController.HandleCommandreceives the command and extracts the verb or registration key.- The flow controller looks up a registered processor (an
ICommandProcessor) by key and callsprocessor.ProcessCommand(command). - The processor executes the action, reading any needed data from
command.Params.Get(key).