Overview - Injectable decorator
What is it?
The Injectable decorator in NestJS marks a class as a provider that can be managed by Nest's dependency injection system. It tells Nest that this class can be created and shared automatically wherever needed. This helps organize code by letting Nest handle creating and linking objects behind the scenes. Without it, you would have to manually create and connect every class instance.
Why it matters
Without the Injectable decorator, developers would need to manually create and manage dependencies, leading to more complex, error-prone code. The decorator enables automatic and consistent object creation and sharing, making applications easier to build, test, and maintain. It solves the problem of tightly coupled code by promoting loose coupling and clear dependency management.
Where it fits
Before learning Injectable, you should understand basic TypeScript classes and decorators. After this, you can learn about NestJS modules, providers, and dependency injection patterns. Later topics include scopes, lifecycle hooks, and custom providers that build on Injectable.