Use when nestJS dependency injection with providers, modules, and decorators. Use when building modular NestJS applications.
View on GitHubTheBushidoCollective/han
jutsu-nestjs
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-nestjs/skills/nestjs-dependency-injection/SKILL.md -a claude-code --skill nestjs-dependency-injectionInstallation paths:
.claude/skills/nestjs-dependency-injection/# NestJS Dependency Injection
Master NestJS dependency injection for building modular, testable
Node.js applications with proper service architecture, provider
patterns, and module organization.
## Table of Contents
- [Provider Patterns](#provider-patterns)
- [Module System](#module-system)
- [Injection Scopes](#injection-scopes)
- [Advanced Patterns](#advanced-patterns)
- [Best Practices](#best-practices)
- [Common Pitfalls](#common-pitfalls)
- [Resources](#resources)
## Provider Patterns
### Class Providers (Standard Pattern)
```typescript
import { Injectable } from '@nestjs/common';
@Injectable()
export class UserService {
private users: User[] = [];
findAll(): User[] {
return this.users;
}
findById(id: string): User | undefined {
return this.users.find(user => user.id === id);
}
create(user: User): User {
this.users.push(user);
return user;
}
}
// Module registration
@Module({
providers: [UserService],
exports: [UserService],
})
export class UserModule {}
```
### Value Providers
```typescript
import { Module } from '@nestjs/common';
// Simple value provider
const DATABASE_CONNECTION = {
provide: 'DATABASE_CONNECTION',
useValue: {
host: 'localhost',
port: 5432,
database: 'mydb',
},
};
// Configuration value provider
const APP_CONFIG = {
provide: 'APP_CONFIG',
useValue: {
apiUrl: process.env.API_URL,
timeout: 5000,
retries: 3,
},
};
@Module({
providers: [DATABASE_CONNECTION, APP_CONFIG],
exports: [DATABASE_CONNECTION, APP_CONFIG],
})
export class ConfigModule {}
// Usage in service
@Injectable()
export class ApiService {
constructor(
@Inject('APP_CONFIG') private config: AppConfig,
) {}
async fetchData(): Promise<any> {
const response = await fetch(this.config.apiUrl, {
timeout: this.config.timeout,
});
return response.json();
}
}
```
### Factory Providers
```typescript
import { Injectable, Module } from '@nestjs/common';
// Simple factory p