Any class decorated with @Injectable() that can be injected via the DI container is a provider. Services, repositories, factories, helpers, and guards are all providers. They are registered in a module's providers array and instantiated by the NestJS IoC container.
The main idea of a provider is that it can be injected as a dependency. NestJS manages the lifecycle and instantiation of providers through its IoC (Inversion of Control) container.
Services — contain business logic.
Repositories — handle data access.
Guards — handle authorization.
Interceptors — transform requests/responses.
Pipes — validate and transform input data.
Factories — create and configure instances.
How would you register a simple service as a provider in a NestJS module?
If you forget to add a provider to the module's providers array, what runtime error do you see when trying to inject it?
Show me how you would inject a provider into a controller using constructor injection.
You need to replace a third‑party library with a mock for testing; how would you configure a custom provider to achieve that?
During a feature rollout, injecting a provider throws 'Nest can't resolve dependencies' – what steps would you take to debug?
Explain why you might use useFactory instead of useClass when defining a provider, and give an example where useFactory is preferable.
Our microservice must share a single database connection across many modules without creating multiple connections; how would you design a provider to handle this efficiently?
When scaling to thousands of requests, what are the performance implications of using request‑scoped providers versus singleton providers?
If you need to conditionally provide different implementations based on environment variables, how would you structure the provider registration to keep the code maintainable?
We are migrating a legacy NestJS monolith to a modular architecture; how would you refactor existing providers to avoid circular dependencies and support independent deployment?
Across multiple teams, you need a shared logging provider that can be overridden per service; what design patterns and NestJS features would you employ to ensure extensibility and versioning?
Discuss the trade‑offs of using dynamic modules with custom providers for feature toggles versus a centralized configuration service.