Interface CommandHandler<TCommand, TResult>

Handler for processing commands.

Command handlers contain the business logic for executing commands. Each command should have exactly one handler.

class CreateUserCommandHandler implements CommandHandler<CreateUserCommand, User> {
async handle(command: CreateUserCommand): Promise<User> {
const user = new User(command.email, command.name);
await this.repository.save(user);
return user;
}
}
interface CommandHandler<TCommand extends Command, TResult = void> {
    handle(command: TCommand): Promise<TResult>;
}

Type Parameters

  • TCommand extends Command

    The type of command this handler processes

  • TResult = void

    The result type returned by the handler

Implemented by

Methods

Methods