forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer.ts
More file actions
33 lines (30 loc) · 1.41 KB
/
container.ts
File metadata and controls
33 lines (30 loc) · 1.41 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
28
29
30
31
32
33
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { EventEmitter } from 'events';
import { Container, decorate, injectable, interfaces } from 'inversify';
import { traceWarning } from '../common/logger';
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 extension would perform this before our extension).
try {
decorate(injectable(), EventEmitter);
} catch (ex) {
traceWarning('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);
}
}