Recall & Review
beginner
What is Dependency Injection (DI) in NestJS?
Dependency Injection is a design pattern where NestJS automatically provides instances of classes (dependencies) to other classes that need them, instead of creating them manually.
Click to reveal answer
beginner
How does NestJS know which dependencies to inject?
NestJS uses decorators like @Injectable() to mark classes as providers and uses the constructor parameters to identify which dependencies to inject.
Click to reveal answer
beginner
What role does the @Injectable() decorator play in NestJS DI?
The @Injectable() decorator marks a class as a provider so NestJS can manage its lifecycle and inject it where needed.Click to reveal answer
beginner
What is a provider in NestJS?
A provider is a class that can be injected as a dependency. It usually contains business logic or services that other parts of the app need.Click to reveal answer
beginner
How do you inject a service into a controller in NestJS?
You add the service as a parameter in the controller's constructor. NestJS then injects the service instance automatically.
Click to reveal answer
Which decorator marks a class as injectable in NestJS?
✗ Incorrect
The @Injectable() decorator tells NestJS that the class can be injected as a dependency.
How does NestJS inject dependencies into a class?
✗ Incorrect
NestJS uses constructor parameters to inject dependencies automatically.
What is a provider in NestJS?
✗ Incorrect
Providers are classes that NestJS can inject into other classes as dependencies.
Which of these is NOT a typical use of dependency injection?
✗ Incorrect
Dependency injection helps reduce tight coupling, not create it.
Where do you declare providers so NestJS can inject them?
✗ Incorrect
Providers must be declared in the module's providers array for NestJS to manage and inject them.
Explain how dependency injection works in NestJS and why it is useful.
Think about how NestJS provides classes to others without manual creation.
You got /4 concepts.
Describe the steps to inject a service into a controller in NestJS.
Focus on decorators, module setup, and constructor usage.
You got /4 concepts.