angular-dependency-injection
/angular-dependency-injection
Configure DI, inject() usage, and providers in Angular. Use when configuring Angular dependency injection, using inject(), or defining providers.
- Author
- HoangNguyen0403 ↗
- Repository
- agent-skills-standard ↗
- Licence
- MIT
- Last repository change
- 22.10.2026
Assessment and security
- Files in this package
- 3
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 1
No signals detected. Repository changed on 22.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Configure DI, inject() usage, and providers in Angular. Use when configuring Angular dependency injection, using inject(), or defining providers.
Original author description
Configure DI, inject() usage, and providers in Angular. Use when configuring Angular dependency injection, using inject(), or defining providers.
How it works
- Priority: P0 (CRITICAL)
- Principles
- Guidelines
- Anti-Patterns
- References
- Canonical response anchors
SKILL.md preview
---
name: angular-dependency-injection
description: Configure DI, inject() usage, and providers in Angular. Use when configuring Angular dependency injection, using inject(), or defining providers.
metadata:
triggers:
files:
- '**/*.service.ts'
keywords:
- angular inject
- providedIn
- injection token
- provideAppInitializer
---
# Dependency Injection
## **Priority: P0 (CRITICAL)**
## Principles
- **`inject()` over Constructor**: Use **inject(MyService)** function in **class fields or constructor-equivalent** class positions for cleaner injection. It works in any **injection context** (class fields, factory functions, guards).
- **Tree Shaking**: Always use **@Injectable({ providedIn: 'root' })** for app-wide singletons unless specific scoping required.
- **Tokens**: Use **new InjectionToken<T>('description')** for configuration, primitives, or interface abstraction. Provide via: **{ provide: API_URL, useValue: 'https://api.example.com' }** in `app.config.ts`. Inject with: **inject(API_URL)**.
## Guidelines
- **Providers**: Prefer **provide\*()** functions (e.g., **provideHttpClient()**) in `app.config.ts` providers array over importing NgModules.
- **Factories**: Use `useFactory` strictly when dependencies need runtime configuration.
- **App Initializer**: Use **provideAppInitializer(() => inject(ConfigService).load())** (Angular 19+) to run async code **before app bootstrap** — replaces old `APP_INITIALIZER` token pattern.
- **Route Providers**: Scope services to route tree using **providers: [MyService]** in **route config** ( routes array) instead of `providedIn: 'root'`. This creates instance destroyed when leaving route.
- **Multi Providers**: Use **{ provide: TOKEN, useClass: Impl, multi: true }** to **collects all multi providers** into array (e.g., **HTTP_INTERCEPTORS**, validators).
## Anti-Patterns
- **No `providedIn: 'platform'`**: Use `'root'` scoping; reserve platform only for Micro Frontend sharing.
- **No `forwardRef`**: Refactor architecture to eliminate circular dependencies instead.
## References
- [DI Patterns](references/di-patterns.md)
## Canonical response anchors
When this skill applies, preserve the following domain terminology or equivalent concrete examples in the answer when relevant:
- HTTP_INTERCEPTORS
- before app bootstrap
- class fields or constructor-equivalent
- collects all multi providers
- inject(MyService)
- provideHttpClient()
- providers: [MyService]
- route config
- Additional task-grounded exact anchors: inject(API_URL)
Files in this package (3)
- SKILL.md 2 KB
- evals/evals.json 4 KB
- references/di-patterns.md 1 KB
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · HoangNguyen0403/agent-skills-standard | 100 | MIT |
| TheBushidoCollective/han | 95 | Apache-2.0 |
Database snapshot: 13.11.2026 · package version 270cdf4bd69b (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100angular-standalone-components
Use this skill when developing Angular applications using standalone components, signals reactivity, inject() dependency injection, and modern routing. - 80Angular v20 Injector InjectFlags Cleanup
Clean up Angular 20 dependency injection code that still relies on InjectFlags, TestBed.get, or untyped Injector.get usage after an Angular 20 upgrade. Use when strict ProviderToken typing or injection options must be made explicit. - 100angular
Expert Angular assistance covering Signals, Standalone Components, dependency injection, RxJS, and SSR. Use when building enterprise Single Page Applications with modern Angular. - 100angular
Angular 17+ with standalone components and signals. Covers components, services, dependency injection, and reactive patterns. USE WHEN: user mentions "Angular", "standalone components", "signals", "dependency injection", "RxJS", "NgModules", asks about "Angular 17 patterns",… - 100angular-expert
Expert knowledge in Angular framework, RxJS reactive programming, TypeScript, dependency injection, and enterprise application development. Use when the user mentions RxJS, TypeScript, dependency injection, reactive, frontend, or enterprise, or when the task involves Angular… - 100angular-conventions
Angular 18-21 project structure, standalone components vs NgModule, control flow (@if/@for/@switch + *ngIf/*ngFor legacy), decorators, dependency injection (inject() function), lifecycle hooks, pipes, Angular Universal SSR pointer. Use this skill to: - Detect project style…