The InMemoryCommandBus is a Spring-managed implementation of the CommandBus interface designed for local execution. It facilitates the decoupling of command dispatching from command handling by using an internal registry (CommandHandlersInformation) to locate the appropriate CommandHandler within the Spring ApplicationContext.
To use it, call the dispatch method with a Command instance. The bus will automatically resolve the correct handler and execute its handle method. If the handler execution fails, the bus wraps the underlying error in a CommandHandlerExecutionError.
// Assuming command and commandBus are already instantiated
try {
commandBus.dispatch(command);
} catch (CommandHandlerExecutionError error) {
// Handle execution failure
}