Skip to content

Commit 98d262f

Browse files
AleksanderBodurrialxhub
authored andcommitted
feat(core): create injector debugging APIs (#48639)
This commit introduces 3 new APIs. getDependenciesFromInstantiation: - Given an injector and a token that was instantiated by that injector, discover all of the things were injected in the instance of that token - This API is meant to enable recursive inspection of dependencies. Dependencies returned by this API include which injector they were providedIn, which enables the continous use of getDependenciesFromInstantiation to determine the dependencies of dependencies getInjectorProviders: - Given an injector, discover all of the providers that were configured in that injector. - This API returns information on the configured providers of an injector, including the import path that leads to the container that the provider originated from (NgModule or standalone directive). This enables fine grained inspection to determine where a specific provider comes from. getInjectorParent: - Given an injector, discover the parent of that injector. - This function is meant to be used recursively to discover the entire resolution path from a starting injector to the NullInjector. These APIs were designed to be used together. For example, getInjectorParent can be used to discover the structure of an injector hierarchy. Once that's done, getInjectorProviders can be used to determine the providers of each injector in that hierarchy. Another example: getDependenciesFromInstantiation can be used to discover the dependencies of a specific injector constructed instance. From there, we can use getInjectorParent to discover the injector resolution path and map each dependency to a path from the starting injector to the injector that it was provided in. PR Close #48639
1 parent 4d92080 commit 98d262f

File tree

2 files changed

+541
-0
lines changed

2 files changed

+541
-0
lines changed

packages/core/src/render3/util/global_utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
*/
88
import {assertDefined} from '../../util/assert';
99
import {global} from '../../util/global';
10+
import {setupFrameworkInjectorProfiler} from '../debug/framework_injector_profiler';
1011
import {setProfiler} from '../profiler';
12+
1113
import {applyChanges} from './change_detection_utils';
1214
import {getComponent, getContext, getDirectiveMetadata, getDirectives, getHostElement, getInjector, getListeners, getOwningComponent, getRootComponents} from './discovery_utils';
15+
import {getDependenciesFromInjectable, getInjectorProviders, getInjectorResolutionPath} from './injector_discovery_utils';
1316

1417

1518

@@ -41,6 +44,10 @@ export function publishDefaultGlobalUtils() {
4144
if (!_published) {
4245
_published = true;
4346

47+
setupFrameworkInjectorProfiler();
48+
publishGlobalUtil('ɵgetDependenciesFromInjectable', getDependenciesFromInjectable);
49+
publishGlobalUtil('ɵgetInjectorProviders', getInjectorProviders);
50+
publishGlobalUtil('ɵgetInjectorResolutionPath', getInjectorResolutionPath);
4451
/**
4552
* Warning: this function is *INTERNAL* and should not be relied upon in application's code.
4653
* The contract of the function might be changed in any release and/or the function can be

0 commit comments

Comments
 (0)