registerCommand<TCommand extends ICommand<TResult>, TResult> method

void registerCommand<TCommand extends ICommand<TResult>, TResult>(
  1. ICommandHandler<TCommand, TResult> handler
)

Registers an ICommandHandler for a custom ICommand type.

Only a single handler can be registered for a specific ICommand type, if you try to register multiple handlers then a StateError will be thrown.

Implementation

void registerCommand<TCommand extends ICommand<TResult>, TResult>(
  ICommandHandler<TCommand, TResult> handler,
) {
  dynamic existing = _commandHandlers[TCommand];
  if (existing != null) {
    throw StateError(
      "A command handler has already been registered for the $TCommand type.",
    );
  }

  _commandHandlers[TCommand] = handler;
}