# Dependency Injection — NestJS

Source: https://www.geekswithgeeks.com/en/nestjs/nestjs-dependency-injection

> NestJS's powerful IoC container manages dependencies for you.

## Inject via constructor

NestJS automatically instantiates and injects services via the constructor. No manual `new` needed.

```typescript
@Injectable()
export class UsersService {
  // service logic
}

@Controller('users')
export class UsersController {
  constructor(private usersService: UsersService) {}

  @Get()
  findAll() {
    return this.usersService.findAll();
  }
}
```

## Lazy loading & scopes

By default, services are singletons (one instance for the app). You can also use `REQUEST` or `TRANSIENT` scopes for per-request or per-use instances.
