261
throw new CyclicDependencyError(graph);
262
}
264
>
}
265
>
266
>
for (const { data } of roots) {
267
>
// Repeat the check for this still being a service sync descriptor. That's because
268
>
// instantiating a dependency might have side-effect and recursively trigger instantiation
269
>
// so that some dependencies are now fullfilled already.
270
>
const instanceOrDesc = this._getServiceInstanceOrDescriptor(data.id);
271
>
if (instanceOrDesc instanceof SyncDescriptor) {
272
>
// create instance and overwrite the service collections
273
>
const instance = this._createServiceInstanceWithOwner(data.id, data.desc.ctor, data.desc.staticArguments, data.desc.supportsDelayedInstantiation, data._trace);
274
>
this._setCreatedServiceInstance(data.id, instance);
275
>
}
276
>
graph.removeNode(data);
277
>
}
278
>
}
279
>
return <T>this._getServiceInstanceOrDescriptor(id);
280
}
281
282
private _createServiceInstanceWithOwner<T>(id: ServiceIdentifier<T>, ctor: any, args: unknown[] = [], supportsDelayedInstantiation: boolean, _trace: Trace): T {
284
>
return this._createServiceInstance(id, ctor, args, supportsDelayedInstantiation, _trace, this._servicesToMaybeDispose);
285
>
} else if (this._parent) {
286
return this._parent._createServiceInstanceWithOwner(id, ctor, args, supportsDelayedInstantiation, _trace);
287
} else {
288
throw new Error(`illegalState - creating UNKNOWN service instance ${ctor.name}`);
289
}
291
292
private _createServiceInstance<T>(id: ServiceIdentifier<T>, ctor: any, args: unknown[] = [], supportsDelayedInstantiation: boolean, _trace: Trace, disposeBucket: Set<any>): T {
294
// eager instantiation
295
const result = this._createInstance<T>(ctor, args, _trace);