@codefast/di 0.3.16-canary.1 → 0.3.16-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +4 -4
- package/dist/binding-select.d.mts +1 -1
- package/dist/binding-select.mjs +5 -5
- package/dist/binding.d.mts +6 -6
- package/dist/binding.mjs +8 -8
- package/dist/constraints.mjs +2 -2
- package/dist/container.mjs +70 -70
- package/dist/decorators/inject.d.mts +1 -1
- package/dist/decorators/inject.mjs +8 -8
- package/dist/dependency-graph.mjs +13 -13
- package/dist/environment.d.mts +15 -15
- package/dist/environment.mjs +21 -21
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/inspector.mjs +13 -13
- package/dist/module.d.mts +1 -1
- package/dist/module.mjs +2 -2
- package/dist/registry.d.mts +4 -4
- package/dist/registry.mjs +27 -27
- package/dist/resolve-options.d.mts +5 -5
- package/dist/resolve-options.mjs +8 -8
- package/dist/resolver.d.mts +10 -10
- package/dist/resolver.mjs +152 -152
- package/dist/token.d.mts +1 -1
- package/dist/token.mjs +4 -4
- package/dist/types.d.mts +5 -5
- package/package.json +9 -8
package/dist/resolver.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AsyncResolutionError, CircularDependencyError, InternalError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, TokenNotBoundError } from "./errors.mjs";
|
|
2
2
|
import { selectAllBindings, selectBinding } from "./binding-select.mjs";
|
|
3
3
|
import { tokenName } from "./token.mjs";
|
|
4
|
-
import { DefaultResolutionContext,
|
|
5
|
-
import {
|
|
4
|
+
import { DefaultResolutionContext, buildResolutionFrame, runWithContainer } from "./environment.mjs";
|
|
5
|
+
import { injectionSlotToResolveOptions } from "./resolve-options.mjs";
|
|
6
6
|
//#region src/resolver.ts
|
|
7
7
|
const RESOLUTION_SET_KEY = Symbol("di:resolution-set");
|
|
8
8
|
const RESOLUTION_SET_THRESHOLD = 32;
|
|
@@ -10,7 +10,7 @@ const EMPTY_STRING_LIST = [];
|
|
|
10
10
|
const EMPTY_FRAME_LIST = [];
|
|
11
11
|
const ROOT_CONSTRAINT_CONTEXT = {
|
|
12
12
|
resolutionPath: EMPTY_STRING_LIST,
|
|
13
|
-
|
|
13
|
+
resolutionStack: EMPTY_FRAME_LIST,
|
|
14
14
|
parent: void 0,
|
|
15
15
|
ancestors: EMPTY_FRAME_LIST,
|
|
16
16
|
currentResolveHint: void 0
|
|
@@ -48,7 +48,7 @@ var DependencyResolver = class {
|
|
|
48
48
|
this._container = _container;
|
|
49
49
|
this._parent = _parent;
|
|
50
50
|
}
|
|
51
|
-
_findBinding(token, hint, resolutionPath,
|
|
51
|
+
_findBinding(token, hint, resolutionPath, resolutionStack) {
|
|
52
52
|
if (hint === void 0) {
|
|
53
53
|
const fastDefaultBinding = this._registry.getFastDefault(token);
|
|
54
54
|
if (fastDefaultBinding !== void 0) return {
|
|
@@ -58,7 +58,7 @@ var DependencyResolver = class {
|
|
|
58
58
|
}
|
|
59
59
|
if (hint?.name !== void 0 && hint.tag === void 0 && (hint.tags?.length ?? 0) === 0) {
|
|
60
60
|
const namedBinding = this._registry.getSimpleNamed(token, hint.name);
|
|
61
|
-
if (namedBinding !== void 0 && this._matchesBindingFast(namedBinding, hint, resolutionPath,
|
|
61
|
+
if (namedBinding !== void 0 && this._matchesBindingFast(namedBinding, hint, resolutionPath, resolutionStack)) return {
|
|
62
62
|
binding: namedBinding,
|
|
63
63
|
owner: this
|
|
64
64
|
};
|
|
@@ -80,18 +80,18 @@ var DependencyResolver = class {
|
|
|
80
80
|
binding: onlyBinding,
|
|
81
81
|
owner: this
|
|
82
82
|
};
|
|
83
|
-
if (this._matchesBindingFast(onlyBinding, hint, resolutionPath,
|
|
83
|
+
if (this._matchesBindingFast(onlyBinding, hint, resolutionPath, resolutionStack)) return {
|
|
84
84
|
binding: onlyBinding,
|
|
85
85
|
owner: this
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
const binding = selectBinding(bindings, hint, this._makeConstraintContext(resolutionPath,
|
|
88
|
+
const binding = selectBinding(bindings, hint, this._makeConstraintContext(resolutionPath, resolutionStack, hint), this._getTokenName(token));
|
|
89
89
|
if (binding !== void 0) return {
|
|
90
90
|
binding,
|
|
91
91
|
owner: this
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
if (this._parent !== void 0) return this._parent._findBinding(token, hint, resolutionPath,
|
|
94
|
+
if (this._parent !== void 0) return this._parent._findBinding(token, hint, resolutionPath, resolutionStack);
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
97
|
* Binding lookup aligned with `resolve` — used by `Container.validate` without instantiating.
|
|
@@ -108,33 +108,33 @@ var DependencyResolver = class {
|
|
|
108
108
|
if (allBindings.length === 0) return [];
|
|
109
109
|
return selectAllBindings(allBindings, hint, this._makeConstraintContext([], [], hint));
|
|
110
110
|
}
|
|
111
|
-
resolveFromContext(token, resolutionPath,
|
|
111
|
+
resolveFromContext(token, resolutionPath, resolutionStack) {
|
|
112
112
|
const fastBinding = this._registry.getFastDefault(token);
|
|
113
113
|
if (fastBinding !== void 0) {
|
|
114
|
-
if (fastBinding.kind === "alias") return this.resolveFromContext(fastBinding.target, resolutionPath,
|
|
114
|
+
if (fastBinding.kind === "alias") return this.resolveFromContext(fastBinding.target, resolutionPath, resolutionStack);
|
|
115
115
|
const scope = fastBinding.scope ?? "transient";
|
|
116
|
-
if (scope === "transient" && fastBinding.kind === "dynamic" && fastBinding.onActivation === void 0 && (this._lifecycle.activationVersion === 0 || !this._lifecycle.hasActivationHandlers(fastBinding.token))) return this._resolveTransientDynamicSyncFromContext(fastBinding, resolutionPath,
|
|
116
|
+
if (scope === "transient" && fastBinding.kind === "dynamic" && fastBinding.onActivation === void 0 && (this._lifecycle.activationVersion === 0 || !this._lifecycle.hasActivationHandlers(fastBinding.token))) return this._resolveTransientDynamicSyncFromContext(fastBinding, resolutionPath, resolutionStack);
|
|
117
117
|
if (scope === "singleton" && this._scope.hasSingleton(fastBinding.id)) return this._scope.getSingleton(fastBinding.id);
|
|
118
118
|
if (scope === "scoped") {
|
|
119
119
|
if (!this._scope.isChild) throw new MissingScopeContextError(this._getTokenName(fastBinding.token));
|
|
120
120
|
if (this._scope.hasScoped(fastBinding.id)) return this._scope.getScoped(fastBinding.id);
|
|
121
121
|
}
|
|
122
|
-
return this._resolveBinding(fastBinding, void 0, resolutionPath,
|
|
122
|
+
return this._resolveBinding(fastBinding, void 0, resolutionPath, resolutionStack);
|
|
123
123
|
}
|
|
124
|
-
return this.resolve(token, void 0, resolutionPath,
|
|
124
|
+
return this.resolve(token, void 0, resolutionPath, resolutionStack);
|
|
125
125
|
}
|
|
126
|
-
resolve(token, hint, resolutionPath,
|
|
127
|
-
const found = this._findBinding(token, hint, resolutionPath,
|
|
126
|
+
resolve(token, hint, resolutionPath, resolutionStack) {
|
|
127
|
+
const found = this._findBinding(token, hint, resolutionPath, resolutionStack);
|
|
128
128
|
if (found === void 0) {
|
|
129
129
|
if (this._registry.getAll(token).length > 0) throw new NoMatchingBindingError(this._getTokenName(token), hint ?? {}, this._getAvailableSlots(token));
|
|
130
130
|
throw new TokenNotBoundError(this._getTokenName(token));
|
|
131
131
|
}
|
|
132
132
|
const { binding, owner } = found;
|
|
133
|
-
if (binding.kind === "alias") return this.resolve(binding.target, hint, resolutionPath,
|
|
134
|
-
if ((binding.scope ?? "transient") === "singleton" && owner !== this) return owner._resolveBinding(binding, hint, resolutionPath,
|
|
135
|
-
return this._resolveBinding(binding, hint, resolutionPath,
|
|
133
|
+
if (binding.kind === "alias") return this.resolve(binding.target, hint, resolutionPath, resolutionStack);
|
|
134
|
+
if ((binding.scope ?? "transient") === "singleton" && owner !== this) return owner._resolveBinding(binding, hint, resolutionPath, resolutionStack);
|
|
135
|
+
return this._resolveBinding(binding, hint, resolutionPath, resolutionStack);
|
|
136
136
|
}
|
|
137
|
-
_resolveBinding(binding, hint, resolutionPath,
|
|
137
|
+
_resolveBinding(binding, hint, resolutionPath, resolutionStack) {
|
|
138
138
|
if (binding.kind === "constant" && binding.onActivation === void 0 && !this._lifecycle.hasActivationHandlers(binding.token)) return binding.value;
|
|
139
139
|
const scope = binding.scope ?? "transient";
|
|
140
140
|
if (scope === "singleton") {
|
|
@@ -144,7 +144,7 @@ var DependencyResolver = class {
|
|
|
144
144
|
if (!this._scope.isChild) throw new MissingScopeContextError(this._getTokenName(binding.token));
|
|
145
145
|
if (this._scope.hasScoped(binding.id)) return this._scope.getScoped(binding.id);
|
|
146
146
|
}
|
|
147
|
-
const frame = this.
|
|
147
|
+
const frame = this._getResolutionFrame(binding);
|
|
148
148
|
const tokenDisplayName = frame.tokenName;
|
|
149
149
|
const pathWithSet = resolutionPath;
|
|
150
150
|
let resolutionSet = pathWithSet[RESOLUTION_SET_KEY];
|
|
@@ -155,27 +155,27 @@ var DependencyResolver = class {
|
|
|
155
155
|
if (resolutionSet !== void 0 ? resolutionSet.has(tokenDisplayName) : resolutionPath.includes(tokenDisplayName)) throw new CircularDependencyError([...resolutionPath, tokenDisplayName]);
|
|
156
156
|
resolutionPath.push(tokenDisplayName);
|
|
157
157
|
resolutionSet?.add(tokenDisplayName);
|
|
158
|
-
|
|
158
|
+
resolutionStack.push(frame);
|
|
159
159
|
const needsActivation = this._needsActivation(binding);
|
|
160
160
|
if (!needsActivation && scope === "transient" && binding.kind === "dynamic") {
|
|
161
|
-
const resolutionCtx = this._acquireSyncResolutionContext(resolutionPath,
|
|
161
|
+
const resolutionCtx = this._acquireSyncResolutionContext(resolutionPath, resolutionStack, hint);
|
|
162
162
|
try {
|
|
163
163
|
const dynamicResult = binding.factory(resolutionCtx);
|
|
164
164
|
if (dynamicResult instanceof Promise) throw new AsyncResolutionError(tokenName(binding.token), tokenName(binding.token));
|
|
165
|
-
|
|
165
|
+
resolutionStack.pop();
|
|
166
166
|
resolutionPath.pop();
|
|
167
167
|
resolutionSet?.delete(tokenDisplayName);
|
|
168
168
|
return dynamicResult;
|
|
169
169
|
} catch (error) {
|
|
170
|
-
|
|
170
|
+
resolutionStack.pop();
|
|
171
171
|
resolutionPath.pop();
|
|
172
172
|
resolutionSet?.delete(tokenDisplayName);
|
|
173
173
|
throw error;
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
try {
|
|
177
|
-
const resolutionCtx = needsActivation || this._requiresResolutionContext(binding) ? this._acquireSyncResolutionContext(resolutionPath,
|
|
178
|
-
const instance = this._instantiateSync(binding, resolutionCtx, resolutionPath,
|
|
177
|
+
const resolutionCtx = needsActivation || this._requiresResolutionContext(binding) ? this._acquireSyncResolutionContext(resolutionPath, resolutionStack, hint) : void 0;
|
|
178
|
+
const instance = this._instantiateSync(binding, resolutionCtx, resolutionPath, resolutionStack);
|
|
179
179
|
let shouldActivate = needsActivation;
|
|
180
180
|
if (binding.kind === "class" && this._classHasPostConstruct.get(binding.target) === void 0) {
|
|
181
181
|
this._refreshClassPostConstructCache(binding.target);
|
|
@@ -187,12 +187,12 @@ var DependencyResolver = class {
|
|
|
187
187
|
else if (scope === "scoped") this._scope.setScoped(binding.id, activated);
|
|
188
188
|
return activated;
|
|
189
189
|
} finally {
|
|
190
|
-
|
|
190
|
+
resolutionStack.pop();
|
|
191
191
|
resolutionPath.pop();
|
|
192
192
|
resolutionSet?.delete(tokenDisplayName);
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
-
_instantiateSync(binding, ctx, resolutionPath,
|
|
195
|
+
_instantiateSync(binding, ctx, resolutionPath, resolutionStack) {
|
|
196
196
|
switch (binding.kind) {
|
|
197
197
|
case "constant": return binding.value;
|
|
198
198
|
case "dynamic": {
|
|
@@ -203,20 +203,20 @@ var DependencyResolver = class {
|
|
|
203
203
|
}
|
|
204
204
|
case "dynamic-async": throw new AsyncResolutionError(tokenName(binding.token), tokenName(binding.token));
|
|
205
205
|
case "class": {
|
|
206
|
-
const deps = this._resolveClassDeps(binding.target, resolutionPath,
|
|
206
|
+
const deps = this._resolveClassDeps(binding.target, resolutionPath, resolutionStack);
|
|
207
207
|
return this._instantiateClass(binding.target, deps);
|
|
208
208
|
}
|
|
209
209
|
case "resolved": {
|
|
210
|
-
const deps = this._resolveDescriptorDeps(binding.deps, resolutionPath,
|
|
211
|
-
const
|
|
212
|
-
if (
|
|
213
|
-
return
|
|
210
|
+
const deps = this._resolveDescriptorDeps(binding.deps, resolutionPath, resolutionStack);
|
|
211
|
+
const factoryResult = binding.factory(...deps);
|
|
212
|
+
if (factoryResult instanceof Promise) throw new AsyncResolutionError(tokenName(binding.token), tokenName(binding.token));
|
|
213
|
+
return factoryResult;
|
|
214
214
|
}
|
|
215
215
|
case "resolved-async": throw new AsyncResolutionError(tokenName(binding.token), tokenName(binding.token));
|
|
216
216
|
case "alias": throw new InternalError("alias should have been followed before instantiation");
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
_resolveClassDeps(target, resolutionPath,
|
|
219
|
+
_resolveClassDeps(target, resolutionPath, resolutionStack) {
|
|
220
220
|
const meta = this._getConstructorMetadata(target);
|
|
221
221
|
if (meta === void 0) {
|
|
222
222
|
if (target.length === 0) return [];
|
|
@@ -225,91 +225,91 @@ var DependencyResolver = class {
|
|
|
225
225
|
if (meta.params.length === 0) return [];
|
|
226
226
|
if (meta.params.length === 1) {
|
|
227
227
|
const param = meta.params[0];
|
|
228
|
-
const paramHint =
|
|
229
|
-
if (param.multi) return [this.resolveAll(param.token, paramHint, resolutionPath,
|
|
230
|
-
if (param.optional) return [this.resolveOptional(param.token, paramHint, resolutionPath,
|
|
231
|
-
if (paramHint === void 0) return [this.resolveFromContext(param.token, resolutionPath,
|
|
232
|
-
return [this.resolve(param.token, paramHint, resolutionPath,
|
|
228
|
+
const paramHint = injectionSlotToResolveOptions(param);
|
|
229
|
+
if (param.multi) return [this.resolveAll(param.token, paramHint, resolutionPath, resolutionStack)];
|
|
230
|
+
if (param.optional) return [this.resolveOptional(param.token, paramHint, resolutionPath, resolutionStack)];
|
|
231
|
+
if (paramHint === void 0) return [this.resolveFromContext(param.token, resolutionPath, resolutionStack)];
|
|
232
|
+
return [this.resolve(param.token, paramHint, resolutionPath, resolutionStack)];
|
|
233
233
|
}
|
|
234
234
|
const deps = new Array(meta.params.length);
|
|
235
235
|
for (let index = 0; index < meta.params.length; index += 1) {
|
|
236
236
|
const param = meta.params[index];
|
|
237
|
-
const paramHint =
|
|
237
|
+
const paramHint = injectionSlotToResolveOptions(param);
|
|
238
238
|
if (param.multi) {
|
|
239
|
-
deps[index] = this.resolveAll(param.token, paramHint, resolutionPath,
|
|
239
|
+
deps[index] = this.resolveAll(param.token, paramHint, resolutionPath, resolutionStack);
|
|
240
240
|
continue;
|
|
241
241
|
}
|
|
242
242
|
if (param.optional) {
|
|
243
|
-
deps[index] = this.resolveOptional(param.token, paramHint, resolutionPath,
|
|
243
|
+
deps[index] = this.resolveOptional(param.token, paramHint, resolutionPath, resolutionStack);
|
|
244
244
|
continue;
|
|
245
245
|
}
|
|
246
|
-
deps[index] = paramHint === void 0 ? this.resolveFromContext(param.token, resolutionPath,
|
|
246
|
+
deps[index] = paramHint === void 0 ? this.resolveFromContext(param.token, resolutionPath, resolutionStack) : this.resolve(param.token, paramHint, resolutionPath, resolutionStack);
|
|
247
247
|
}
|
|
248
248
|
return deps;
|
|
249
249
|
}
|
|
250
|
-
_resolveDescriptorDeps(deps, resolutionPath,
|
|
250
|
+
_resolveDescriptorDeps(deps, resolutionPath, resolutionStack) {
|
|
251
251
|
const resolved = new Array(deps.length);
|
|
252
252
|
for (let index = 0; index < deps.length; index += 1) {
|
|
253
253
|
const dep = deps[index];
|
|
254
|
-
const depHint =
|
|
254
|
+
const depHint = injectionSlotToResolveOptions(dep);
|
|
255
255
|
if (dep.multi) {
|
|
256
|
-
resolved[index] = this.resolveAll(dep.token, depHint, resolutionPath,
|
|
256
|
+
resolved[index] = this.resolveAll(dep.token, depHint, resolutionPath, resolutionStack);
|
|
257
257
|
continue;
|
|
258
258
|
}
|
|
259
259
|
if (dep.optional) {
|
|
260
|
-
resolved[index] = this.resolveOptional(dep.token, depHint, resolutionPath,
|
|
260
|
+
resolved[index] = this.resolveOptional(dep.token, depHint, resolutionPath, resolutionStack);
|
|
261
261
|
continue;
|
|
262
262
|
}
|
|
263
|
-
resolved[index] = depHint === void 0 ? this.resolveFromContext(dep.token, resolutionPath,
|
|
263
|
+
resolved[index] = depHint === void 0 ? this.resolveFromContext(dep.token, resolutionPath, resolutionStack) : this.resolve(dep.token, depHint, resolutionPath, resolutionStack);
|
|
264
264
|
}
|
|
265
265
|
return resolved;
|
|
266
266
|
}
|
|
267
|
-
resolveOptional(token, hint, resolutionPath,
|
|
268
|
-
if (this._findBinding(token, hint, resolutionPath,
|
|
269
|
-
return this.resolve(token, hint, resolutionPath,
|
|
267
|
+
resolveOptional(token, hint, resolutionPath, resolutionStack) {
|
|
268
|
+
if (this._findBinding(token, hint, resolutionPath, resolutionStack) === void 0) return;
|
|
269
|
+
return this.resolve(token, hint, resolutionPath, resolutionStack);
|
|
270
270
|
}
|
|
271
|
-
resolveAll(token, hint, resolutionPath,
|
|
271
|
+
resolveAll(token, hint, resolutionPath, resolutionStack) {
|
|
272
272
|
if (hint?.name !== void 0 && hint.tag === void 0 && (hint.tags?.length ?? 0) === 0) {
|
|
273
273
|
const namedCandidates = this._getSimpleNamedBindingsFromChain(token, hint.name);
|
|
274
274
|
if (namedCandidates.length === 0) return [];
|
|
275
275
|
const resolved = new Array(namedCandidates.length);
|
|
276
|
-
for (let index = 0; index < namedCandidates.length; index += 1) resolved[index] = this._resolveCandidateSync(namedCandidates[index], hint, resolutionPath,
|
|
276
|
+
for (let index = 0; index < namedCandidates.length; index += 1) resolved[index] = this._resolveCandidateSync(namedCandidates[index], hint, resolutionPath, resolutionStack);
|
|
277
277
|
return resolved;
|
|
278
278
|
}
|
|
279
279
|
const allBindings = this._getAllBindingsFromChain(token);
|
|
280
280
|
if (allBindings.length === 0) return [];
|
|
281
|
-
const candidates = selectAllBindings(allBindings, hint, this._makeConstraintContext(resolutionPath,
|
|
281
|
+
const candidates = selectAllBindings(allBindings, hint, this._makeConstraintContext(resolutionPath, resolutionStack, hint));
|
|
282
282
|
const resolved = new Array(candidates.length);
|
|
283
|
-
for (let index = 0; index < candidates.length; index += 1) resolved[index] = this._resolveCandidateSync(candidates[index], hint, resolutionPath,
|
|
283
|
+
for (let index = 0; index < candidates.length; index += 1) resolved[index] = this._resolveCandidateSync(candidates[index], hint, resolutionPath, resolutionStack);
|
|
284
284
|
return resolved;
|
|
285
285
|
}
|
|
286
|
-
resolveAsyncFromContext(token, resolutionPath,
|
|
286
|
+
resolveAsyncFromContext(token, resolutionPath, resolutionStack) {
|
|
287
287
|
const fastBinding = this._registry.getFastDefault(token);
|
|
288
288
|
if (fastBinding !== void 0) {
|
|
289
|
-
if (fastBinding.kind === "alias") return this.resolveAsyncFromContext(fastBinding.target, resolutionPath,
|
|
289
|
+
if (fastBinding.kind === "alias") return this.resolveAsyncFromContext(fastBinding.target, resolutionPath, resolutionStack);
|
|
290
290
|
const scope = fastBinding.scope ?? "transient";
|
|
291
|
-
if (scope === "transient" && (fastBinding.kind === "dynamic" || fastBinding.kind === "dynamic-async") && fastBinding.onActivation === void 0 && (this._lifecycle.activationVersion === 0 || !this._lifecycle.hasActivationHandlers(fastBinding.token))) return this._resolveTransientDynamicAsyncFromContext(fastBinding, resolutionPath,
|
|
291
|
+
if (scope === "transient" && (fastBinding.kind === "dynamic" || fastBinding.kind === "dynamic-async") && fastBinding.onActivation === void 0 && (this._lifecycle.activationVersion === 0 || !this._lifecycle.hasActivationHandlers(fastBinding.token))) return this._resolveTransientDynamicAsyncFromContext(fastBinding, resolutionPath, resolutionStack);
|
|
292
292
|
if (scope === "singleton" && this._scope.hasSingleton(fastBinding.id)) return Promise.resolve(this._scope.getSingleton(fastBinding.id));
|
|
293
293
|
if (scope === "scoped") {
|
|
294
294
|
if (!this._scope.isChild) return Promise.reject(new MissingScopeContextError(this._getTokenName(fastBinding.token)));
|
|
295
295
|
if (this._scope.hasScoped(fastBinding.id)) return Promise.resolve(this._scope.getScoped(fastBinding.id));
|
|
296
296
|
}
|
|
297
|
-
return this._resolveBindingAsync(fastBinding, void 0, resolutionPath,
|
|
297
|
+
return this._resolveBindingAsync(fastBinding, void 0, resolutionPath, resolutionStack);
|
|
298
298
|
}
|
|
299
|
-
return this.resolveAsync(token, void 0, resolutionPath,
|
|
299
|
+
return this.resolveAsync(token, void 0, resolutionPath, resolutionStack);
|
|
300
300
|
}
|
|
301
|
-
async resolveAsync(token, hint, resolutionPath,
|
|
302
|
-
const found = this._findBinding(token, hint, resolutionPath,
|
|
301
|
+
async resolveAsync(token, hint, resolutionPath, resolutionStack) {
|
|
302
|
+
const found = this._findBinding(token, hint, resolutionPath, resolutionStack);
|
|
303
303
|
if (found === void 0) {
|
|
304
304
|
if (this._registry.getAll(token).length > 0) throw new NoMatchingBindingError(this._getTokenName(token), hint ?? {}, this._getAvailableSlots(token));
|
|
305
305
|
throw new TokenNotBoundError(this._getTokenName(token));
|
|
306
306
|
}
|
|
307
307
|
const { binding, owner } = found;
|
|
308
|
-
if (binding.kind === "alias") return this.resolveAsync(binding.target, hint, resolutionPath,
|
|
309
|
-
if ((binding.scope ?? "transient") === "singleton" && owner !== this) return owner._resolveBindingAsync(binding, hint, resolutionPath,
|
|
310
|
-
return this._resolveBindingAsync(binding, hint, resolutionPath,
|
|
308
|
+
if (binding.kind === "alias") return this.resolveAsync(binding.target, hint, resolutionPath, resolutionStack);
|
|
309
|
+
if ((binding.scope ?? "transient") === "singleton" && owner !== this) return owner._resolveBindingAsync(binding, hint, resolutionPath, resolutionStack);
|
|
310
|
+
return this._resolveBindingAsync(binding, hint, resolutionPath, resolutionStack);
|
|
311
311
|
}
|
|
312
|
-
async _resolveBindingAsync(binding, hint, resolutionPath,
|
|
312
|
+
async _resolveBindingAsync(binding, hint, resolutionPath, resolutionStack) {
|
|
313
313
|
if (binding.kind === "constant" && binding.onActivation === void 0 && !this._lifecycle.hasActivationHandlers(binding.token)) return binding.value;
|
|
314
314
|
const scope = binding.scope ?? "transient";
|
|
315
315
|
if (scope === "singleton") {
|
|
@@ -321,36 +321,36 @@ var DependencyResolver = class {
|
|
|
321
321
|
if (!this._scope.isChild) throw new MissingScopeContextError(this._getTokenName(binding.token));
|
|
322
322
|
if (this._scope.hasScoped(binding.id)) return this._scope.getScoped(binding.id);
|
|
323
323
|
}
|
|
324
|
-
const frame = this.
|
|
325
|
-
const
|
|
324
|
+
const frame = this._getResolutionFrame(binding);
|
|
325
|
+
const frameName = frame.tokenName;
|
|
326
326
|
const pathWithSet = resolutionPath;
|
|
327
327
|
let resolutionSet = pathWithSet[RESOLUTION_SET_KEY];
|
|
328
328
|
if (resolutionSet === void 0 && resolutionPath.length >= RESOLUTION_SET_THRESHOLD) {
|
|
329
329
|
resolutionSet = new Set(resolutionPath);
|
|
330
330
|
pathWithSet[RESOLUTION_SET_KEY] = resolutionSet;
|
|
331
331
|
}
|
|
332
|
-
if (resolutionSet !== void 0 ? resolutionSet.has(
|
|
333
|
-
resolutionPath.push(
|
|
334
|
-
resolutionSet?.add(
|
|
335
|
-
|
|
332
|
+
if (resolutionSet !== void 0 ? resolutionSet.has(frameName) : resolutionPath.includes(frameName)) throw new CircularDependencyError([...resolutionPath, frameName]);
|
|
333
|
+
resolutionPath.push(frameName);
|
|
334
|
+
resolutionSet?.add(frameName);
|
|
335
|
+
resolutionStack.push(frame);
|
|
336
336
|
const needsActivation = this._needsActivation(binding);
|
|
337
337
|
if (!needsActivation && scope === "transient" && (binding.kind === "dynamic" || binding.kind === "dynamic-async")) {
|
|
338
|
-
const resolutionCtx = new DefaultResolutionContext(this, resolutionPath,
|
|
338
|
+
const resolutionCtx = new DefaultResolutionContext(this, resolutionPath, resolutionStack, hint);
|
|
339
339
|
try {
|
|
340
340
|
if (binding.kind === "dynamic-async") return await binding.factory(resolutionCtx);
|
|
341
341
|
const dynamicResult = binding.factory(resolutionCtx);
|
|
342
342
|
return dynamicResult instanceof Promise ? await dynamicResult : dynamicResult;
|
|
343
343
|
} finally {
|
|
344
|
-
|
|
344
|
+
resolutionStack.pop();
|
|
345
345
|
resolutionPath.pop();
|
|
346
|
-
resolutionSet?.delete(
|
|
346
|
+
resolutionSet?.delete(frameName);
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
|
-
const resolutionCtx = needsActivation || this._requiresResolutionContext(binding) ? new DefaultResolutionContext(this, resolutionPath,
|
|
349
|
+
const resolutionCtx = needsActivation || this._requiresResolutionContext(binding) ? new DefaultResolutionContext(this, resolutionPath, resolutionStack, hint) : void 0;
|
|
350
350
|
try {
|
|
351
351
|
if (scope === "singleton") {
|
|
352
352
|
const createSingletonPromise = async () => {
|
|
353
|
-
const instance = await this._instantiateAsync(binding, resolutionCtx, resolutionPath,
|
|
353
|
+
const instance = await this._instantiateAsync(binding, resolutionCtx, resolutionPath, resolutionStack);
|
|
354
354
|
let shouldActivate = needsActivation;
|
|
355
355
|
if (binding.kind === "class" && this._classHasPostConstruct.get(binding.target) === void 0) {
|
|
356
356
|
this._refreshClassPostConstructCache(binding.target);
|
|
@@ -369,7 +369,7 @@ var DependencyResolver = class {
|
|
|
369
369
|
this._scope.setInflight(binding.id, singletonPromise);
|
|
370
370
|
return await singletonPromise;
|
|
371
371
|
}
|
|
372
|
-
const instance = await this._instantiateAsync(binding, resolutionCtx, resolutionPath,
|
|
372
|
+
const instance = await this._instantiateAsync(binding, resolutionCtx, resolutionPath, resolutionStack);
|
|
373
373
|
let shouldActivate = needsActivation;
|
|
374
374
|
if (binding.kind === "class" && this._classHasPostConstruct.get(binding.target) === void 0) {
|
|
375
375
|
this._refreshClassPostConstructCache(binding.target);
|
|
@@ -380,40 +380,40 @@ var DependencyResolver = class {
|
|
|
380
380
|
if (scope === "scoped") this._scope.setScoped(binding.id, activated);
|
|
381
381
|
return activated;
|
|
382
382
|
} finally {
|
|
383
|
-
|
|
383
|
+
resolutionStack.pop();
|
|
384
384
|
resolutionPath.pop();
|
|
385
|
-
resolutionSet?.delete(
|
|
385
|
+
resolutionSet?.delete(frameName);
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
|
-
async _instantiateAsync(binding, ctx, resolutionPath,
|
|
388
|
+
async _instantiateAsync(binding, ctx, resolutionPath, resolutionStack) {
|
|
389
389
|
switch (binding.kind) {
|
|
390
390
|
case "constant": return binding.value;
|
|
391
391
|
case "dynamic": {
|
|
392
392
|
if (ctx === void 0) throw new InternalError("dynamic binding requires resolution context");
|
|
393
|
-
const
|
|
394
|
-
return
|
|
393
|
+
const factoryResult = binding.factory(ctx);
|
|
394
|
+
return factoryResult instanceof Promise ? factoryResult : Promise.resolve(factoryResult);
|
|
395
395
|
}
|
|
396
396
|
case "dynamic-async":
|
|
397
397
|
if (ctx === void 0) throw new InternalError("dynamic-async binding requires resolution context");
|
|
398
398
|
return binding.factory(ctx);
|
|
399
399
|
case "class": {
|
|
400
|
-
const deps = await this._resolveClassDepsAsync(binding.target, resolutionPath,
|
|
400
|
+
const deps = await this._resolveClassDepsAsync(binding.target, resolutionPath, resolutionStack);
|
|
401
401
|
return this._instantiateClass(binding.target, deps);
|
|
402
402
|
}
|
|
403
403
|
case "resolved": {
|
|
404
404
|
if (ctx === void 0) throw new InternalError("resolved binding requires resolution context");
|
|
405
|
-
const deps = await this._resolveDescriptorDepsAsync(binding.deps, resolutionPath,
|
|
406
|
-
const
|
|
407
|
-
return
|
|
405
|
+
const deps = await this._resolveDescriptorDepsAsync(binding.deps, resolutionPath, resolutionStack);
|
|
406
|
+
const factoryResult = binding.factory(...deps);
|
|
407
|
+
return factoryResult instanceof Promise ? factoryResult : Promise.resolve(factoryResult);
|
|
408
408
|
}
|
|
409
409
|
case "resolved-async": {
|
|
410
|
-
const deps = await this._resolveDescriptorDepsAsync(binding.deps, resolutionPath,
|
|
410
|
+
const deps = await this._resolveDescriptorDepsAsync(binding.deps, resolutionPath, resolutionStack);
|
|
411
411
|
return binding.factory(...deps);
|
|
412
412
|
}
|
|
413
413
|
case "alias": throw new InternalError("alias should have been followed before instantiation");
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
|
-
async _resolveClassDepsAsync(target, resolutionPath,
|
|
416
|
+
async _resolveClassDepsAsync(target, resolutionPath, resolutionStack) {
|
|
417
417
|
const meta = this._getConstructorMetadata(target);
|
|
418
418
|
if (meta === void 0) {
|
|
419
419
|
if (target.length === 0) return [];
|
|
@@ -422,52 +422,52 @@ var DependencyResolver = class {
|
|
|
422
422
|
if (meta.params.length === 0) return [];
|
|
423
423
|
if (meta.params.length === 1) {
|
|
424
424
|
const param = meta.params[0];
|
|
425
|
-
const paramHint =
|
|
426
|
-
if (param.multi) return [await this.resolveAllAsync(param.token, paramHint, resolutionPath,
|
|
427
|
-
if (param.optional) return [await this.resolveOptionalAsync(param.token, paramHint, resolutionPath,
|
|
428
|
-
if (paramHint === void 0) return [await this.resolveAsyncFromContext(param.token, resolutionPath,
|
|
429
|
-
return [await this.resolveAsync(param.token, paramHint, resolutionPath,
|
|
425
|
+
const paramHint = injectionSlotToResolveOptions(param);
|
|
426
|
+
if (param.multi) return [await this.resolveAllAsync(param.token, paramHint, resolutionPath, resolutionStack)];
|
|
427
|
+
if (param.optional) return [await this.resolveOptionalAsync(param.token, paramHint, resolutionPath, resolutionStack)];
|
|
428
|
+
if (paramHint === void 0) return [await this.resolveAsyncFromContext(param.token, resolutionPath, resolutionStack)];
|
|
429
|
+
return [await this.resolveAsync(param.token, paramHint, resolutionPath, resolutionStack)];
|
|
430
430
|
}
|
|
431
431
|
const pending = new Array(meta.params.length);
|
|
432
432
|
const shouldCloneContext = meta.params.length > 1;
|
|
433
433
|
for (let index = 0; index < meta.params.length; index += 1) {
|
|
434
434
|
const param = meta.params[index];
|
|
435
|
-
const paramHint =
|
|
436
|
-
if (param.multi) pending[index] = this.resolveAllAsync(param.token, paramHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...
|
|
437
|
-
else if (param.optional) pending[index] = this.resolveOptionalAsync(param.token, paramHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...
|
|
438
|
-
else pending[index] = paramHint === void 0 ? this.resolveAsyncFromContext(param.token, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...
|
|
435
|
+
const paramHint = injectionSlotToResolveOptions(param);
|
|
436
|
+
if (param.multi) pending[index] = this.resolveAllAsync(param.token, paramHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
|
|
437
|
+
else if (param.optional) pending[index] = this.resolveOptionalAsync(param.token, paramHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
|
|
438
|
+
else pending[index] = paramHint === void 0 ? this.resolveAsyncFromContext(param.token, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack) : this.resolveAsync(param.token, paramHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
|
|
439
439
|
}
|
|
440
440
|
return Promise.all(pending);
|
|
441
441
|
}
|
|
442
|
-
async _resolveDescriptorDepsAsync(deps, resolutionPath,
|
|
442
|
+
async _resolveDescriptorDepsAsync(deps, resolutionPath, resolutionStack) {
|
|
443
443
|
const pending = new Array(deps.length);
|
|
444
444
|
const shouldCloneContext = deps.length > 1;
|
|
445
445
|
for (let index = 0; index < deps.length; index += 1) {
|
|
446
446
|
const dep = deps[index];
|
|
447
|
-
const depHint =
|
|
448
|
-
if (dep.multi) pending[index] = this.resolveAllAsync(dep.token, depHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...
|
|
449
|
-
else if (dep.optional) pending[index] = this.resolveOptionalAsync(dep.token, depHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...
|
|
450
|
-
else pending[index] = depHint === void 0 ? this.resolveAsyncFromContext(dep.token, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...
|
|
447
|
+
const depHint = injectionSlotToResolveOptions(dep);
|
|
448
|
+
if (dep.multi) pending[index] = this.resolveAllAsync(dep.token, depHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
|
|
449
|
+
else if (dep.optional) pending[index] = this.resolveOptionalAsync(dep.token, depHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
|
|
450
|
+
else pending[index] = depHint === void 0 ? this.resolveAsyncFromContext(dep.token, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack) : this.resolveAsync(dep.token, depHint, shouldCloneContext ? [...resolutionPath] : resolutionPath, shouldCloneContext ? [...resolutionStack] : resolutionStack);
|
|
451
451
|
}
|
|
452
452
|
return Promise.all(pending);
|
|
453
453
|
}
|
|
454
|
-
async resolveOptionalAsync(token, hint, resolutionPath,
|
|
455
|
-
if (this._findBinding(token, hint, resolutionPath,
|
|
456
|
-
return this.resolveAsync(token, hint, resolutionPath,
|
|
454
|
+
async resolveOptionalAsync(token, hint, resolutionPath, resolutionStack) {
|
|
455
|
+
if (this._findBinding(token, hint, resolutionPath, resolutionStack) === void 0) return;
|
|
456
|
+
return this.resolveAsync(token, hint, resolutionPath, resolutionStack);
|
|
457
457
|
}
|
|
458
|
-
async resolveAllAsync(token, hint, resolutionPath,
|
|
458
|
+
async resolveAllAsync(token, hint, resolutionPath, resolutionStack) {
|
|
459
459
|
if (hint?.name !== void 0 && hint.tag === void 0 && (hint.tags?.length ?? 0) === 0) {
|
|
460
460
|
const namedCandidates = this._getSimpleNamedBindingsFromChain(token, hint.name);
|
|
461
461
|
if (namedCandidates.length === 0) return [];
|
|
462
462
|
const pending = new Array(namedCandidates.length);
|
|
463
|
-
for (let index = 0; index < namedCandidates.length; index += 1) pending[index] = this._resolveCandidateAsync(namedCandidates[index], hint, resolutionPath,
|
|
463
|
+
for (let index = 0; index < namedCandidates.length; index += 1) pending[index] = this._resolveCandidateAsync(namedCandidates[index], hint, resolutionPath, resolutionStack);
|
|
464
464
|
return Promise.all(pending);
|
|
465
465
|
}
|
|
466
466
|
const allBindings = this._getAllBindingsFromChain(token);
|
|
467
467
|
if (allBindings.length === 0) return [];
|
|
468
|
-
const candidates = selectAllBindings(allBindings, hint, this._makeConstraintContext(resolutionPath,
|
|
468
|
+
const candidates = selectAllBindings(allBindings, hint, this._makeConstraintContext(resolutionPath, resolutionStack, hint));
|
|
469
469
|
const pending = new Array(candidates.length);
|
|
470
|
-
for (let index = 0; index < candidates.length; index += 1) pending[index] = this._resolveCandidateAsync(candidates[index], hint, resolutionPath,
|
|
470
|
+
for (let index = 0; index < candidates.length; index += 1) pending[index] = this._resolveCandidateAsync(candidates[index], hint, resolutionPath, resolutionStack);
|
|
471
471
|
return Promise.all(pending);
|
|
472
472
|
}
|
|
473
473
|
_getAllBindingsFromChain(token) {
|
|
@@ -498,20 +498,20 @@ var DependencyResolver = class {
|
|
|
498
498
|
_getAvailableSlots(token) {
|
|
499
499
|
return this._registry.availableSlotStrings(token);
|
|
500
500
|
}
|
|
501
|
-
_makeConstraintContext(resolutionPath,
|
|
502
|
-
if (hint === void 0 && resolutionPath.length === 0 &&
|
|
501
|
+
_makeConstraintContext(resolutionPath, resolutionStack, hint) {
|
|
502
|
+
if (hint === void 0 && resolutionPath.length === 0 && resolutionStack.length === 0) return ROOT_CONSTRAINT_CONTEXT;
|
|
503
503
|
return {
|
|
504
504
|
resolutionPath,
|
|
505
|
-
|
|
506
|
-
parent:
|
|
507
|
-
ancestors:
|
|
505
|
+
resolutionStack,
|
|
506
|
+
parent: resolutionStack.at(-1),
|
|
507
|
+
ancestors: resolutionStack.length > 1 ? resolutionStack.slice(0, -1) : [],
|
|
508
508
|
currentResolveHint: hint
|
|
509
509
|
};
|
|
510
510
|
}
|
|
511
|
-
_matchesBindingFast(binding, hint, resolutionPath,
|
|
511
|
+
_matchesBindingFast(binding, hint, resolutionPath, resolutionStack) {
|
|
512
512
|
if (!this._matchesSlotFast(binding.slot, hint)) return false;
|
|
513
513
|
if (binding.predicate === void 0) return true;
|
|
514
|
-
const ctx = this._makeConstraintContext(resolutionPath,
|
|
514
|
+
const ctx = this._makeConstraintContext(resolutionPath, resolutionStack, hint);
|
|
515
515
|
return binding.predicate(ctx);
|
|
516
516
|
}
|
|
517
517
|
_matchesSlotFast(slot, hint) {
|
|
@@ -557,32 +557,32 @@ var DependencyResolver = class {
|
|
|
557
557
|
}
|
|
558
558
|
return false;
|
|
559
559
|
}
|
|
560
|
-
_resolveTransientDynamicSyncFromContext(binding, resolutionPath,
|
|
560
|
+
_resolveTransientDynamicSyncFromContext(binding, resolutionPath, resolutionStack) {
|
|
561
561
|
if (resolutionPath.length < RESOLUTION_SET_THRESHOLD) {
|
|
562
|
-
const frame = this.
|
|
562
|
+
const frame = this._getResolutionFrame(binding);
|
|
563
563
|
const tokenDisplayName = frame.tokenName;
|
|
564
564
|
if (resolutionPath.includes(tokenDisplayName)) throw new CircularDependencyError([...resolutionPath, tokenDisplayName]);
|
|
565
565
|
resolutionPath.push(tokenDisplayName);
|
|
566
|
-
|
|
567
|
-
const resolutionCtx = this._acquireSyncResolutionContext(resolutionPath,
|
|
566
|
+
resolutionStack.push(frame);
|
|
567
|
+
const resolutionCtx = this._acquireSyncResolutionContext(resolutionPath, resolutionStack, void 0);
|
|
568
568
|
try {
|
|
569
569
|
const dynamicResult = binding.factory(resolutionCtx);
|
|
570
570
|
if (dynamicResult instanceof Promise) throw new AsyncResolutionError(tokenDisplayName, tokenDisplayName);
|
|
571
571
|
return dynamicResult;
|
|
572
572
|
} finally {
|
|
573
|
-
|
|
573
|
+
resolutionStack.pop();
|
|
574
574
|
resolutionPath.pop();
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
|
-
if (this._deepActiveLevels > 0 && this._deepSyncCtxPath !== resolutionPath) return this._resolveTransientDynamicSyncSlow(binding, resolutionPath,
|
|
577
|
+
if (this._deepActiveLevels > 0 && this._deepSyncCtxPath !== resolutionPath) return this._resolveTransientDynamicSyncSlow(binding, resolutionPath, resolutionStack);
|
|
578
578
|
if (this._deepActiveLevels === 0) {
|
|
579
579
|
const gen = ++this._deepCycleGen;
|
|
580
|
-
for (const stackFrame of
|
|
580
|
+
for (const stackFrame of resolutionStack) this._deepCycleMarks.set(stackFrame.bindingId, gen);
|
|
581
581
|
let ctx = this._deepSyncCtx;
|
|
582
582
|
if (ctx === void 0) {
|
|
583
|
-
ctx = new DefaultResolutionContext(this, resolutionPath,
|
|
583
|
+
ctx = new DefaultResolutionContext(this, resolutionPath, resolutionStack, void 0);
|
|
584
584
|
this._deepSyncCtx = ctx;
|
|
585
|
-
} else ctx.reset(this, resolutionPath,
|
|
585
|
+
} else ctx.reset(this, resolutionPath, resolutionStack, void 0);
|
|
586
586
|
this._deepSyncCtxPath = resolutionPath;
|
|
587
587
|
}
|
|
588
588
|
if (this._deepCycleMarks.get(binding.id) === this._deepCycleGen) throw new CircularDependencyError([...resolutionPath, tokenName(binding.token)]);
|
|
@@ -596,8 +596,8 @@ var DependencyResolver = class {
|
|
|
596
596
|
if (--this._deepActiveLevels === 0) this._deepSyncCtxPath = void 0;
|
|
597
597
|
}
|
|
598
598
|
}
|
|
599
|
-
_resolveTransientDynamicSyncSlow(binding, resolutionPath,
|
|
600
|
-
const frame = this.
|
|
599
|
+
_resolveTransientDynamicSyncSlow(binding, resolutionPath, resolutionStack) {
|
|
600
|
+
const frame = this._getResolutionFrame(binding);
|
|
601
601
|
const tokenDisplayName = frame.tokenName;
|
|
602
602
|
const pathWithSet = resolutionPath;
|
|
603
603
|
let resolutionSet = pathWithSet[RESOLUTION_SET_KEY];
|
|
@@ -608,19 +608,19 @@ var DependencyResolver = class {
|
|
|
608
608
|
if (resolutionSet.has(tokenDisplayName)) throw new CircularDependencyError([...resolutionPath, tokenDisplayName]);
|
|
609
609
|
resolutionPath.push(tokenDisplayName);
|
|
610
610
|
resolutionSet.add(tokenDisplayName);
|
|
611
|
-
|
|
612
|
-
const resolutionCtx = this._acquireSyncResolutionContext(resolutionPath,
|
|
611
|
+
resolutionStack.push(frame);
|
|
612
|
+
const resolutionCtx = this._acquireSyncResolutionContext(resolutionPath, resolutionStack, void 0);
|
|
613
613
|
try {
|
|
614
614
|
const dynamicResult = binding.factory(resolutionCtx);
|
|
615
615
|
if (dynamicResult instanceof Promise) throw new AsyncResolutionError(tokenDisplayName, tokenDisplayName);
|
|
616
616
|
return dynamicResult;
|
|
617
617
|
} finally {
|
|
618
|
-
|
|
618
|
+
resolutionStack.pop();
|
|
619
619
|
resolutionPath.pop();
|
|
620
620
|
resolutionSet.delete(tokenDisplayName);
|
|
621
621
|
}
|
|
622
622
|
}
|
|
623
|
-
_resolveTransientDynamicAsyncFromContext(binding, resolutionPath,
|
|
623
|
+
_resolveTransientDynamicAsyncFromContext(binding, resolutionPath, resolutionStack) {
|
|
624
624
|
if (resolutionPath.length < RESOLUTION_SET_THRESHOLD) {
|
|
625
625
|
const tokenDisplayName = tokenName(binding.token);
|
|
626
626
|
if (resolutionPath.includes(tokenDisplayName)) return Promise.reject(new CircularDependencyError([...resolutionPath, tokenDisplayName]));
|
|
@@ -633,16 +633,16 @@ var DependencyResolver = class {
|
|
|
633
633
|
} else if (this._deepAsyncCtxPath === void 0) {
|
|
634
634
|
const existing = this._deepAsyncCtx;
|
|
635
635
|
if (existing === void 0) {
|
|
636
|
-
ctx = new DefaultResolutionContext(this, resolutionPath,
|
|
636
|
+
ctx = new DefaultResolutionContext(this, resolutionPath, resolutionStack, void 0);
|
|
637
637
|
this._deepAsyncCtx = ctx;
|
|
638
638
|
} else {
|
|
639
|
-
existing.reset(this, resolutionPath,
|
|
639
|
+
existing.reset(this, resolutionPath, resolutionStack, void 0);
|
|
640
640
|
ctx = existing;
|
|
641
641
|
}
|
|
642
642
|
this._deepAsyncCtxPath = resolutionPath;
|
|
643
643
|
isOwnerLevel = true;
|
|
644
644
|
} else {
|
|
645
|
-
ctx = new DefaultResolutionContext(this, resolutionPath,
|
|
645
|
+
ctx = new DefaultResolutionContext(this, resolutionPath, resolutionStack, void 0);
|
|
646
646
|
isOwnerLevel = false;
|
|
647
647
|
}
|
|
648
648
|
if (isOwnerLevel) this._deepAsyncActiveLevels++;
|
|
@@ -668,10 +668,10 @@ var DependencyResolver = class {
|
|
|
668
668
|
throw err;
|
|
669
669
|
});
|
|
670
670
|
}
|
|
671
|
-
return this._resolveTransientDynamicAsyncSlow(binding, resolutionPath,
|
|
671
|
+
return this._resolveTransientDynamicAsyncSlow(binding, resolutionPath, resolutionStack);
|
|
672
672
|
}
|
|
673
|
-
async _resolveTransientDynamicAsyncSlow(binding, resolutionPath,
|
|
674
|
-
const frame = this.
|
|
673
|
+
async _resolveTransientDynamicAsyncSlow(binding, resolutionPath, resolutionStack) {
|
|
674
|
+
const frame = this._getResolutionFrame(binding);
|
|
675
675
|
const tokenDisplayName = frame.tokenName;
|
|
676
676
|
const pathWithSet = resolutionPath;
|
|
677
677
|
let resolutionSet = pathWithSet[RESOLUTION_SET_KEY];
|
|
@@ -682,33 +682,33 @@ var DependencyResolver = class {
|
|
|
682
682
|
if (resolutionSet.has(tokenDisplayName)) throw new CircularDependencyError([...resolutionPath, tokenDisplayName]);
|
|
683
683
|
resolutionPath.push(tokenDisplayName);
|
|
684
684
|
resolutionSet.add(tokenDisplayName);
|
|
685
|
-
|
|
686
|
-
const resolutionCtx = new DefaultResolutionContext(this, resolutionPath,
|
|
685
|
+
resolutionStack.push(frame);
|
|
686
|
+
const resolutionCtx = new DefaultResolutionContext(this, resolutionPath, resolutionStack, void 0);
|
|
687
687
|
try {
|
|
688
688
|
if (binding.kind === "dynamic-async") return await binding.factory(resolutionCtx);
|
|
689
689
|
const dynamicResult = binding.factory(resolutionCtx);
|
|
690
690
|
return dynamicResult instanceof Promise ? await dynamicResult : dynamicResult;
|
|
691
691
|
} finally {
|
|
692
|
-
|
|
692
|
+
resolutionStack.pop();
|
|
693
693
|
resolutionPath.pop();
|
|
694
694
|
resolutionSet.delete(tokenDisplayName);
|
|
695
695
|
}
|
|
696
696
|
}
|
|
697
|
-
_resolveCandidateSync(binding, hint, resolutionPath,
|
|
697
|
+
_resolveCandidateSync(binding, hint, resolutionPath, resolutionStack) {
|
|
698
698
|
if (binding.kind === "constant" && binding.onActivation === void 0 && !this._lifecycle.hasActivationHandlers(binding.token)) return binding.value;
|
|
699
|
-
if (binding.kind === "alias") return this.resolve(binding.target, hint, resolutionPath,
|
|
699
|
+
if (binding.kind === "alias") return this.resolve(binding.target, hint, resolutionPath, resolutionStack);
|
|
700
700
|
const scope = binding.scope ?? "transient";
|
|
701
701
|
if (scope === "singleton" && this._scope.hasSingleton(binding.id)) return this._scope.getSingleton(binding.id);
|
|
702
702
|
if (scope === "scoped") {
|
|
703
703
|
if (!this._scope.isChild) throw new MissingScopeContextError(this._getTokenName(binding.token));
|
|
704
704
|
if (this._scope.hasScoped(binding.id)) return this._scope.getScoped(binding.id);
|
|
705
705
|
}
|
|
706
|
-
return this._resolveBinding(binding, hint, resolutionPath,
|
|
706
|
+
return this._resolveBinding(binding, hint, resolutionPath, resolutionStack);
|
|
707
707
|
}
|
|
708
|
-
_resolveCandidateAsync(binding, hint, resolutionPath,
|
|
708
|
+
_resolveCandidateAsync(binding, hint, resolutionPath, resolutionStack) {
|
|
709
709
|
if (binding.kind === "constant" && binding.onActivation === void 0 && !this._lifecycle.hasActivationHandlers(binding.token)) return Promise.resolve(binding.value);
|
|
710
710
|
const isolatedPath = [...resolutionPath];
|
|
711
|
-
const isolatedStack = [...
|
|
711
|
+
const isolatedStack = [...resolutionStack];
|
|
712
712
|
if (binding.kind === "alias") return this.resolveAsync(binding.target, hint, isolatedPath, isolatedStack);
|
|
713
713
|
const scope = binding.scope ?? "transient";
|
|
714
714
|
if (scope === "singleton" && this._scope.hasSingleton(binding.id)) return Promise.resolve(this._scope.getSingleton(binding.id));
|
|
@@ -718,11 +718,11 @@ var DependencyResolver = class {
|
|
|
718
718
|
}
|
|
719
719
|
return this._resolveBindingAsync(binding, hint, isolatedPath, isolatedStack);
|
|
720
720
|
}
|
|
721
|
-
|
|
721
|
+
_getResolutionFrame(binding) {
|
|
722
722
|
const existing = this._frameByBindingId.get(binding.id);
|
|
723
723
|
if (existing !== void 0) return existing;
|
|
724
724
|
const scope = binding.scope ?? "transient";
|
|
725
|
-
const frame =
|
|
725
|
+
const frame = buildResolutionFrame(tokenName(binding.token), scope, binding.id, binding.kind, binding.slot);
|
|
726
726
|
this._frameByBindingId.set(binding.id, frame);
|
|
727
727
|
return frame;
|
|
728
728
|
}
|
|
@@ -757,14 +757,14 @@ var DependencyResolver = class {
|
|
|
757
757
|
_requiresResolutionContext(binding) {
|
|
758
758
|
return binding.kind === "dynamic" || binding.kind === "dynamic-async";
|
|
759
759
|
}
|
|
760
|
-
_acquireSyncResolutionContext(resolutionPath,
|
|
761
|
-
const depth =
|
|
760
|
+
_acquireSyncResolutionContext(resolutionPath, resolutionStack, hint) {
|
|
761
|
+
const depth = resolutionStack.length;
|
|
762
762
|
const existing = this._syncResolutionContextPool[depth];
|
|
763
763
|
if (existing !== void 0) {
|
|
764
|
-
existing.reset(this, resolutionPath,
|
|
764
|
+
existing.reset(this, resolutionPath, resolutionStack, hint);
|
|
765
765
|
return existing;
|
|
766
766
|
}
|
|
767
|
-
const created = new DefaultResolutionContext(this, resolutionPath,
|
|
767
|
+
const created = new DefaultResolutionContext(this, resolutionPath, resolutionStack, hint);
|
|
768
768
|
this._syncResolutionContextPool[depth] = created;
|
|
769
769
|
return created;
|
|
770
770
|
}
|