Create a command instance from a CommandConfig
Thrown if the command has not been registered yet
The command configuration
Optional getBeta
Get a list of configs for all registered commands
Get a handler associated with a command
the handler for the command class
The command class
Execute the given command with it's registered command handler
result from the command handler
command to execute
Check if a command is supported
true if the command is supported, false otherwise
identifier of the command. Can be either the class or the string the class was registered with
Register a command to be executed by the given handler.
Associates a command class with a handler that will process instances of that command when handle is called.
commandBus.register(SendEmailCommand, {
handle: async (command: SendEmailCommand) => {
// Send email logic
return { success: true };
}
});
The command class to register
The CommandHandler instance that will execute the command
Beta
Register a command to be executed by the given handler
type of command
the handler instance used to execute the command
Optional metadata: Omit<CommandMetadata, "id">metadata for the command
Service for registering and executing commands using the command pattern.
The CommandBus is the central hub for the command pattern implementation. It manages command registration, handler lookup, and command execution. Commands are decoupled from their handlers, allowing for flexible middleware chains and cross-cutting concerns like logging, validation, and authorization.
Key responsibilities:
Example
Example
See