Recall & Review
beginner
What is the default provider scope in NestJS?
The default provider scope is Singleton. This means one instance of the provider is created and shared across the entire application.
Click to reveal answer
intermediate
Explain the
Request provider scope in NestJS.The
Request scope creates a new instance of the provider for each incoming HTTP request. This helps isolate data per request.Click to reveal answer
intermediate
What does the
Transient provider scope do in NestJS?The
Transient scope creates a new instance of the provider every time it is injected, regardless of the request or module.Click to reveal answer
advanced
How does the
Request scope differ from the Transient scope?The
Request scope creates one instance per HTTP request, shared within that request. The Transient scope creates a new instance every time it is injected, even multiple times in the same request.Click to reveal answer
intermediate
Why would you use
Transient scope for a provider?Use
Transient when you want a fresh instance every time to avoid shared state or side effects, like for stateless helpers or utilities.Click to reveal answer
What scope does NestJS use by default for providers?
✗ Incorrect
By default, NestJS providers are singletons, meaning one instance is shared across the app.
Which provider scope creates a new instance for each HTTP request?
✗ Incorrect
The Request scope creates a new provider instance per HTTP request.
If you want a new provider instance every time it is injected, which scope should you use?
✗ Incorrect
Transient scope creates a new instance every time the provider is injected.
Which scope shares the same instance within a single HTTP request but creates new instances for different requests?
✗ Incorrect
Request scope shares one instance per HTTP request.
Why might you avoid using Singleton scope for stateful providers?
✗ Incorrect
Singleton scope shares one instance app-wide, which can cause unwanted shared state for stateful providers.
Describe the differences between default, request, and transient provider scopes in NestJS.
Think about how many instances are created and when.
You got /3 concepts.
When would you choose to use the transient scope over the request or default scopes in NestJS?
Consider cases where sharing instances could cause problems.
You got /3 concepts.