runCommand<TCommand extends ICommand<TResult> , TResult> method
Executes the given command if a handler for it could be found,
otherwise throws the StateError.
Implementation
Future<TResult> runCommand<TCommand extends ICommand<TResult>, TResult>(
TCommand command,
) async {
Object? handler = _commandHandlers[TCommand];
if (handler == null) {
throw StateError(
"No query handler has been registered for the $TCommand type.",
);
}
ICommandHandler<TCommand, TResult> typedhandler =
handler as ICommandHandler<TCommand, TResult>;
return await typedhandler.handle(command);
}