MCPcopy Index your code
hub / github.com/angular/angular / resolveProvider

Function resolveProvider

packages/core/src/render3/di_setup.ts:70–244  ·  view source on GitHub ↗

* Resolves a provider and publishes it to the DI system.

(
  provider: Provider,
  tInjectables: TData,
  lInjectablesBlueprint: NodeInjectorFactory[],
  isComponent: boolean,
  isViewProvider: boolean,
)

Source from the content-addressed store, hash-verified

68 * Resolves a provider and publishes it to the DI system.
69 */
70function resolveProvider(
71 provider: Provider,
72 tInjectables: TData,
73 lInjectablesBlueprint: NodeInjectorFactory[],
74 isComponent: boolean,
75 isViewProvider: boolean,
76): void {
77 provider = resolveForwardRef(provider);
78 if (Array.isArray(provider)) {
79 // Recursively call `resolveProvider`
80 // Recursion is OK in this case because this code will not be in hot-path once we implement
81 // cloning of the initial state.
82 for (let i = 0; i < provider.length; i++) {
83 resolveProvider(
84 provider[i],
85 tInjectables,
86 lInjectablesBlueprint,
87 isComponent,
88 isViewProvider,
89 );
90 }
91 } else {
92 const tView = getTView();
93 const lView = getLView();
94 const tNode = getCurrentTNode()!;
95 let token: any = isTypeProvider(provider) ? provider : resolveForwardRef(provider.provide);
96
97 const providerFactory = providerToFactory(provider);
98 if (ngDevMode) {
99 const injector = new NodeInjector(
100 tNode as TElementNode | TContainerNode | TElementContainerNode,
101 lView,
102 );
103 runInInjectorProfilerContext(injector, token, () => {
104 emitProviderConfiguredEvent(provider as SingleProvider, isViewProvider);
105 });
106 }
107
108 const beginIndex = tNode.providerIndexes & TNodeProviderIndexes.ProvidersStartIndexMask;
109 const endIndex = tNode.directiveStart;
110 const cptViewProvidersCount =
111 tNode.providerIndexes >> TNodeProviderIndexes.CptViewProvidersCountShift;
112
113 if (isTypeProvider(provider) || !provider.multi) {
114 const factory = new NodeInjectorFactory(
115 providerFactory,
116 isViewProvider,
117 ɵɵdirectiveInject,
118 ngDevMode ? providerName(provider) : null,
119 );
120 const existingFactoryIndex = indexOf(
121 token,
122 tInjectables,
123 isViewProvider ? beginIndex : beginIndex + cptViewProvidersCount,
124 endIndex,
125 );
126 if (existingFactoryIndex === -1) {
127 diPublicInInjector(

Callers 1

providersResolverFunction · 0.85

Calls 15

resolveForwardRefFunction · 0.90
getTViewFunction · 0.90
getLViewFunction · 0.90
getCurrentTNodeFunction · 0.90
isTypeProviderFunction · 0.90
providerToFactoryFunction · 0.90
diPublicInInjectorFunction · 0.90
providerNameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…