Handler for processing queries.
Query handlers retrieve data without changing state. Each query should have exactly one handler.
class GetUserQueryHandler implements QueryHandler<GetUserQuery, User | null> { async handle(query: GetUserQuery): Promise<User | null> { return await this.repository.findById(query.userId); }} Copy
class GetUserQueryHandler implements QueryHandler<GetUserQuery, User | null> { async handle(query: GetUserQuery): Promise<User | null> { return await this.repository.findById(query.userId); }}
The type of query this handler processes
The result type returned by the handler
Handles the query and returns the result.
The query to handle
The query result
Handler for processing queries.
Query handlers retrieve data without changing state. Each query should have exactly one handler.
Example