Implement dependency injection in Angular v20+ using inject(), injection tokens, and provider configuration. Use for service architecture, providing…
Dependency injection configuration and service management for Angular v20+ using inject() and providers.
Use inject() for cleaner dependency declaration in components and services; configure providers at root, component, or route level to control singleton vs instance-per-component behavior
Create and inject custom tokens for configuration objects, third-party values, and multi-provider collections; supports useValue, useClass, useFactory, and useExisting provider strategies
Manage injection scope with optional injection, self/skipSelf/host modifiers, and multi-providers for collecting multiple implementations of the same token
Run async initialization code before app startup using provideAppInitializer; create custom injectors programmatically with createEnvironmentInjector and runInInjectionContext
Angular Dependency Injection
Configure and use dependency injection in Angular v20+ with inject() and providers.
Basic Injection
Using inject()
Prefer inject() over constructor injection:
import { Component, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { User } from './user.service';don't have the plugin yet? install it then click "run inline in claude" again.