/// <summary> /// Asynchronously registers an anonymous command handler for the specified type of command. /// </summary> /// <typeparam name="TCommand">The type of command.</typeparam> /// <param name="commandDispatcher">The command dispatcher.</param> /// <param name="handler">The command handler that shall be registered.</param> /// <returns> /// A <see cref="IHandlerRegistration"/> representing the asynchronous operation. /// The <see cref="IHandlerRegistration"/> cancels the handler registration if completed. /// </returns> /// <exception cref="ArgumentNullException">Thrown if either <paramref name="commandDispatcher"/> or <paramref name="handler"/> is null.</exception> public static Task <IHandlerRegistration <ICommandHandler <TCommand> > > OnCommand <TCommand>(this ICommandDispatcher commandDispatcher, Func <TCommand, Task <ICommandResult> > handler) // TODO: Correct xml-comments { if (commandDispatcher == null) { throw new ArgumentNullException(nameof(commandDispatcher)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } return(commandDispatcher.RegisterAsync(new AnonymousCommandHandler <TCommand>(handler))); }