NestJS · Junior · Question 24 of 75

How does a controller get a service instance?

@Controller("users")
export class UsersController {
  constructor(private readonly usersService: UsersService) {}
}

Explanation

The service must be a provider in this module (or exported by an imported module). Nest resolves the whole dependency graph.

Further reading

Problem with a question

NestJS · Junior · question 24

Test yourself

Take the NestJS · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz