1
>
/*---------------------------------------------------------------------------------------------
serviceCollection.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 { ServiceIdentifier } from './instantiation.js';
7
>
import { SyncDescriptor } from './descriptors.js';
8
>
9
>
export class ServiceCollection {
10
>
11
>
private _entries = new Map<ServiceIdentifier<any>, any>();
12
>
13
>
constructor(...entries: [ServiceIdentifier<any>, any][]) {
14
for (const [id, service] of entries) {
15
this.set(id, service);
16
}
17
}
19
>
set<T>(id: ServiceIdentifier<T>, instanceOrDescriptor: T | SyncDescriptor<T>): T | SyncDescriptor<T> {
20
const result = this._entries.get(id);
21
this._entries.set(id, instanceOrDescriptor);
22
return result;
23
}
25
>
has(id: ServiceIdentifier<any>): boolean {
26
return this._entries.has(id);
27
}
29
>
get<T>(id: ServiceIdentifier<T>): T | SyncDescriptor<T> {
30
return this._entries.get(id);
31
}