1
>
/*---------------------------------------------------------------------------------------------
instantiationService.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { GlobalIdleValue } from '../../../base/common/async.js';
7
>
import { Event } from '../../../base/common/event.js';
8
>
import { illegalState } from '../../../base/common/errors.js';
9
>
import { DisposableStore, dispose, IDisposable, isDisposable, toDisposable } from '../../../base/common/lifecycle.js';
10
>
import { SyncDescriptor, SyncDescriptor0 } from './descriptors.js';
11
>
import { Graph } from './graph.js';
12
>
import { GetLeadingNonServiceArgs, IInstantiationService, ServiceIdentifier, ServicesAccessor, _util } from './instantiation.js';
13
>
import { ServiceCollection } from './serviceCollection.js';
14
>
import { LinkedList } from '../../../base/common/linkedList.js';
15
>
16
>
// TRACING
17
>
const _enableAllTracing = false
18
>
// || "TRUE" // DO NOT CHECK IN!
19
>
;
20
>
21
>
class CyclicDependencyError extends Error {
22
>
constructor(graph: Graph<any>) {
23
super('cyclic dependency between services');
24
this.message = graph.findCycleSlow() ?? `UNABLE to detect cycle, dumping graph: \n${graph.toString()}`;
25
}
27
>
28
>
export class InstantiationService implements IInstantiationService {
29
>
30
>
declare readonly _serviceBrand: undefined;
31
>
32
>
readonly _globalGraph?: Graph<string>;
33
>
private _globalGraphImplicitDependency?: string;
34
>
35
>
private _isDisposed = false;
36
>
private readonly _servicesToMaybeDispose = new Set<any>();
37
>
private readonly _children = new Set<InstantiationService>();
38
>
39
>
constructor(
40
private readonly _services: ServiceCollection = new ServiceCollection(),
41
private readonly _strict: boolean = false,