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; }} Copy
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; }}
The type of command this handler processes
The result type returned by the handler
Handles the command and returns a result.
The command to handle
The result of handling the command
Handler for processing commands.
Command handlers contain the business logic for executing commands. Each command should have exactly one handler.
Example