liveBook · Manning

Application injection context

As explained in Modern Angular

An application injection context is the Angular dependency-injection scope associated with application-level configuration and bootstrapping.

An application injection context is the application-level dependency-injection scope used by standalone Angular configuration and bootstrapping. Providers belong here when configured through bootstrapApplication or application configuration. section 2.3.2

Standalone APIs such as provideRouter and provideHttpClient configure dependencies directly. When a library still exposes an NgModule, importProvidersFrom extracts its providers for use in this context, preserving interoperability. section 2.3.2

Application-level providers

In app.config.ts, define an ApplicationConfig with providers such as provideRouter(routes) and provideHttpClient(). Use importProvidersFrom(HttpClientModule) when a dependency has no suitable standalone API. section 2.3.2

Table 2.1 Different scenarios of providing dependencies
Question
Answer without standalone APIs
Answer with standalone APIs
Do I need to provide every dependency in every component?
Either this or mark the service as providedIn: 'root'.
We can use a standalone API if one is provided.
How do I import services that are provided in other modules (without special standalone APIs)?
Import the module directly into the component.
Use the importProvidersFrom function in the application main.ts file.
How do I import built-in Angular dependencies?
Import the whole module.
Use existing standalone APIs.

Compare dependency provision before and after standalone APIs, including when to use importProvidersFrom or existing standalone provider functions. section 2.3.2

How Modern Angular covers it

How deep it goes
Explains valid provider locations and demonstrates provider configuration, but stops short of describing injector internals.
Examples
Uses app.config.ts examples with provideRouter, provideHttpClient, importProvidersFrom, and a dependency-provision comparison table.
What it assumes
Assumes familiarity with Angular dependency injection, standalone components, and NgModules.
What you can do after
Operate/configure application providers with standalone APIs while retaining compatibility with NgModule-based dependencies.
How it connects
Connects dependency injection with standalone APIs, NgModules, bootstrapApplication, route providers, and HttpClient.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern Angular. The section links point to the parts of the book it draws on.