Path: blob/main/src/vs/platform/instantiation/common/extensions.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { SyncDescriptor } from './descriptors.js';6import { BrandedService, ServiceIdentifier } from './instantiation.js';78const _registry: [ServiceIdentifier<any>, SyncDescriptor<any>][] = [];910export const enum InstantiationType {11/**12* Instantiate this service as soon as a consumer depends on it. _Note_ that this13* is more costly as some upfront work is done that is likely not needed14*/15Eager = 0,1617/**18* Instantiate this service as soon as a consumer uses it. This is the _better_19* way of registering a service.20*/21Delayed = 122}2324export function registerSingleton<T, Services extends BrandedService[]>(id: ServiceIdentifier<T>, ctor: new (...services: Services) => T, supportsDelayedInstantiation: InstantiationType): void;25export function registerSingleton<T, Services extends BrandedService[]>(id: ServiceIdentifier<T>, descriptor: SyncDescriptor<any>): void;26export function registerSingleton<T, Services extends BrandedService[]>(id: ServiceIdentifier<T>, ctorOrDescriptor: { new(...services: Services): T } | SyncDescriptor<any>, supportsDelayedInstantiation?: boolean | InstantiationType): void {27if (!(ctorOrDescriptor instanceof SyncDescriptor)) {28ctorOrDescriptor = new SyncDescriptor<T>(ctorOrDescriptor as new (...args: any[]) => T, [], Boolean(supportsDelayedInstantiation));29}3031_registry.push([id, ctorOrDescriptor]);32}3334export function getSingletonServiceDescriptors(): [ServiceIdentifier<any>, SyncDescriptor<any>][] {35return _registry;36}373839