Recall & Review
beginner
What is the purpose of the
@Injectable() decorator in NestJS?The <code>@Injectable()</code> decorator marks a class as a provider that can be managed by NestJS's dependency injection system. It allows the class to be injected into other classes as a dependency.Click to reveal answer
beginner
Can a class without <code>@Injectable()</code> be injected as a provider in NestJS?No. Without the <code>@Injectable()</code> decorator, NestJS does not recognize the class as a provider and will not inject it into other classes.Click to reveal answer
beginner
How does
@Injectable() help with managing dependencies in NestJS?It tells NestJS to create and manage an instance of the class automatically. This way, you don't have to manually create instances or manage dependencies yourself.Click to reveal answer
intermediate
Is it possible to add metadata or options inside the
@Injectable() decorator?Yes. You can pass options to
@Injectable() to control the provider's scope, like making it singleton or request-scoped.Click to reveal answer
beginner
What happens if you forget to add
@Injectable() on a service you want to inject?NestJS will throw a runtime error saying it cannot resolve the dependency because the class is not registered as a provider.Click to reveal answer
What does the
@Injectable() decorator do in NestJS?✗ Incorrect
@Injectable() marks a class as a provider so NestJS can inject it where needed.
Can you inject a class without
@Injectable() in NestJS?✗ Incorrect
Classes must have @Injectable() to be injected as providers.
Which of these is a valid use of
@Injectable() options?✗ Incorrect
You can set provider scope like singleton or request-scoped using options in @Injectable().
What error occurs if you inject a class without
@Injectable()?✗ Incorrect
NestJS throws a 'Cannot resolve dependency' error at runtime.
Where should you place the
@Injectable() decorator?✗ Incorrect
@Injectable() goes on classes to make them injectable providers.
Explain in your own words what the
@Injectable() decorator does in NestJS and why it is important.Think about how NestJS knows which classes to create and share automatically.
You got /4 concepts.
Describe what happens if you try to inject a class without the
@Injectable() decorator in NestJS.Consider what NestJS needs to know to inject a class.
You got /4 concepts.