Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/instantiation/common/extensions.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
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 { SyncDescriptor } from './descriptors.js';
7
import { BrandedService, ServiceIdentifier } from './instantiation.js';
8
9
const _registry: [ServiceIdentifier<any>, SyncDescriptor<any>][] = [];
10
11
export const enum InstantiationType {
12
/**
13
* Instantiate this service as soon as a consumer depends on it. _Note_ that this
14
* is more costly as some upfront work is done that is likely not needed
15
*/
16
Eager = 0,
17
18
/**
19
* Instantiate this service as soon as a consumer uses it. This is the _better_
20
* way of registering a service.
21
*/
22
Delayed = 1
23
}
24
25
export function registerSingleton<T, Services extends BrandedService[]>(id: ServiceIdentifier<T>, ctor: new (...services: Services) => T, supportsDelayedInstantiation: InstantiationType): void;
26
export function registerSingleton<T, Services extends BrandedService[]>(id: ServiceIdentifier<T>, descriptor: SyncDescriptor<any>): void;
27
export function registerSingleton<T, Services extends BrandedService[]>(id: ServiceIdentifier<T>, ctorOrDescriptor: { new(...services: Services): T } | SyncDescriptor<any>, supportsDelayedInstantiation?: boolean | InstantiationType): void {
28
if (!(ctorOrDescriptor instanceof SyncDescriptor)) {
29
ctorOrDescriptor = new SyncDescriptor<T>(ctorOrDescriptor as new (...args: any[]) => T, [], Boolean(supportsDelayedInstantiation));
30
}
31
32
_registry.push([id, ctorOrDescriptor]);
33
}
34
35
export function getSingletonServiceDescriptors(): [ServiceIdentifier<any>, SyncDescriptor<any>][] {
36
return _registry;
37
}
38
39