angular-di

Configure Angular v20+ dependency injection with inject() and InjectionTokens.

Updated Mar 5, 2026
One-click install
npx skills add https://github.com/alexander-kastil/advanced-angular-agentic-swe --skill angular-di-alexander-kastil
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: angular-di
Source: https://github.com/alexander-kastil/advanced-angular-agentic-swe/tree/main/.github/skills/angular-di
Command: npx skills add https://github.com/alexander-kastil/advanced-angular-agentic-swe --skill angular-di-alexander-kastil

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Implement dependency injection in Angular v20+ using inject(), injection tokens, and provider configuration to simplify service wiring and configuration.

Core Features & Use Cases

  • Inject-based access: Use inject() to access dependencies directly in services and components, reducing constructor boilerplate.
  • Token-based configuration: Define InjectionTokens for API URLs and config objects and provide values via useValue or useFactory.
  • Provider scoping & patterns: Demonstrate root, component, and route-scoped providers, multi providers, and hierarchical injection for flexible architectures.
  • Use case: Build a feature module where core services are singleton at root while feature-specific services get isolated instances.

Quick Start

Create a sample service that uses inject() to access a dependency and configure a token-based provider to observe scope behavior.

Frequently Asked Questions about angular-di

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use inject() for Angular dependency injection instead of constructor parameters?

Use the inject() function to access Angular dependencies directly within services and components, reducing constructor boilerplate. It replaces constructor parameter injection by allowing you to retrieve dependencies inline during property initialization or method execution.

How do I configure Angular InjectionTokens with useFactory and useValue providers?

Configure Angular InjectionTokens by defining the token and providing values or logic via useValue or useFactory. This token-based configuration approach decouples configuration data, like API URLs, from concrete service implementations for flexible wiring.

What is hierarchical injection and how do I scope providers at the root, component, or route level?

Hierarchical injection in Angular determines provider visibility and instance creation. Scope providers at the root level for singletons, or configure component and route-level providers to provide isolated instances specific to those structural boundaries.

Can I use multi providers in Angular to register multiple dependencies for a single InjectionToken?

Yes, multi providers in Angular allow registering multiple dependencies for a single InjectionToken. This advanced dependency injection pattern enables plugin-like architectures where multiple services contribute to a single collection retrieved via inject().

Does this Angular dependency injection approach work for building feature modules with isolated service instances?

Yes, this approach supports building feature modules where core services are singleton at root while feature-specific services get isolated instances. It applies to scenarios involving root, component, and route-level providers for flexible feature architectures.