forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer.ts
More file actions
27 lines (24 loc) · 1.32 KB
/
container.ts
File metadata and controls
27 lines (24 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { EventEmitter } from 'events';
import { Container, decorate, injectable, interfaces } from 'inversify';
import { Abstract, IServiceContainer, Newable } from './types';
// This needs to be done once, hence placed in a common location.
// Used by UnitTestSockerServer and also the extension unit tests.
// Place within try..catch, as this can only be done once (it's
// possible another extesion would perform this before our extension).
try {
decorate(injectable(), EventEmitter);
} catch (ex) {
console.warn('Failed to decorate EventEmitter for DI (possibly already decorated by another Extension)', ex);
}
@injectable()
export class ServiceContainer implements IServiceContainer {
constructor(private container: Container) { }
public get<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, name?: string | number | symbol): T {
return name ? this.container.getNamed<T>(serviceIdentifier, name) : this.container.get<T>(serviceIdentifier);
}
public getAll<T>(serviceIdentifier: string | symbol | Newable<T> | Abstract<T>, name?: string | number | symbol | undefined): T[] {
return name ? this.container.getAllNamed<T>(serviceIdentifier, name) : this.container.getAll<T>(serviceIdentifier);
}
}