What problem does it solve?
Angular dependency injection can become inconsistent and hard to scale when services, scopes, and tokens are not designed up front, leading to duplicated instances, tangled dependencies, and brittle configuration.
Core Features & Use Cases
- Modern injection with inject(): Prefer
inject() over constructor injection to keep components/services lean and more flexible.
- Correct provider scoping: Use
providedIn: 'root', component-level providers, and route-level providers to control instance lifetimes.
- Injection tokens for configurable dependencies: Create typed tokens (including factory-based and value-based tokens) to decouple implementation from configuration.
- Provider configuration patterns: Choose between
useClass, useValue, useFactory, and useExisting, including multi providers for arrays and interceptors.
- Advanced DI controls: Apply optional injection,
self/skipSelf/host resolution, and run code inside an injection context using runInInjectionContext.
- App initialization & environment injectors: Load async configuration before the app starts with
provideAppInitializer, and create injectors programmatically with createEnvironmentInjector.
Quick Start
Configure your Angular app to use inject() with properly scoped providers and typed InjectionTokens for API and feature configuration.