Resources
1Install
npx skillscat add hoangnguyen0403/agent-skills-standard/dependency-injection Install via the SkillsCat registry.
SKILL.md
Dependency Injection
Priority: P0 (CRITICAL)
Principles
inject()over Constructor: Use theinject()function for cleaner injection updates and type inference.- Tree Shaking: Always use
providedIn: 'root'for services unless specific scoping is required. - Tokens: Use
InjectionToken<T>for configuration, primitives, or interface abstraction.
Guidelines
- Providers: Prefer
provide*functions (e.g.,provideHttpClient()) inapp.config.tsover importing modules. - Factories: Use
useFactorystrictly when dependencies need runtime configuration.
Anti-Patterns
- Global State: Avoid
providedIn: 'platform'unless absolutely necessary (share between Micro Frontends). - Circular Deps: Use
forwardRefonly as a last resort; refactor architecture instead.