forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserviceRegistry.ts
More file actions
80 lines (71 loc) · 4.04 KB
/
serviceRegistry.ts
File metadata and controls
80 lines (71 loc) · 4.04 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Container } from 'inversify';
import 'reflect-metadata';
import { Disposable, Memento, OutputChannel } from 'vscode';
import { STANDARD_OUTPUT_CHANNEL } from '../client/common/constants';
import { BufferDecoder } from '../client/common/process/decoder';
import { ProcessService } from '../client/common/process/proc';
import { PythonExecutionFactory } from '../client/common/process/pythonExecutionFactory';
import { registerTypes as processRegisterTypes } from '../client/common/process/serviceRegistry';
import { IBufferDecoder, IProcessService, IPythonExecutionFactory } from '../client/common/process/types';
import { registerTypes as commonRegisterTypes } from '../client/common/serviceRegistry';
import { GLOBAL_MEMENTO, IDisposableRegistry, IMemento, IOutputChannel, WORKSPACE_MEMENTO } from '../client/common/types';
import { registerTypes as variableRegisterTypes } from '../client/common/variables/serviceRegistry';
import { registerTypes as formattersRegisterTypes } from '../client/formatters/serviceRegistry';
import { ServiceContainer } from '../client/ioc/container';
import { ServiceManager } from '../client/ioc/serviceManager';
import { IServiceContainer, IServiceManager } from '../client/ioc/types';
import { registerTypes as lintersRegisterTypes } from '../client/linters/serviceRegistry';
import { TEST_OUTPUT_CHANNEL } from '../client/unittests/common/constants';
import { registerTypes as unittestsRegisterTypes } from '../client/unittests/serviceRegistry';
import { MockOutputChannel } from './mockClasses';
import { MockMemento } from './mocks/mementos';
import { IOriginalProcessService, MockProcessService } from './mocks/proc';
export class IocContainer {
public readonly serviceManager: IServiceManager;
public readonly serviceContainer: IServiceContainer;
private disposables: Disposable[] = [];
constructor() {
const cont = new Container();
this.serviceManager = new ServiceManager(cont);
this.serviceContainer = new ServiceContainer(cont);
this.serviceManager.addSingletonInstance<IServiceContainer>(IServiceContainer, this.serviceContainer);
this.serviceManager.addSingletonInstance<Disposable[]>(IDisposableRegistry, this.disposables);
this.serviceManager.addSingleton<Memento>(IMemento, MockMemento, GLOBAL_MEMENTO);
this.serviceManager.addSingleton<Memento>(IMemento, MockMemento, WORKSPACE_MEMENTO);
const stdOutputChannel = new MockOutputChannel('Python');
this.disposables.push(stdOutputChannel);
this.serviceManager.addSingletonInstance<OutputChannel>(IOutputChannel, stdOutputChannel, STANDARD_OUTPUT_CHANNEL);
const testOutputChannel = new MockOutputChannel('Python Test - UnitTests');
this.disposables.push(testOutputChannel);
this.serviceManager.addSingletonInstance<OutputChannel>(IOutputChannel, testOutputChannel, TEST_OUTPUT_CHANNEL);
}
public dispose() {
this.disposables.forEach(disposable => disposable.dispose());
}
public registerCommonTypes() {
commonRegisterTypes(this.serviceManager);
}
public registerProcessTypes() {
processRegisterTypes(this.serviceManager);
}
public registerVariableTypes() {
variableRegisterTypes(this.serviceManager);
}
public registerUnitTestTypes() {
unittestsRegisterTypes(this.serviceManager);
}
public registerLinterTypes() {
lintersRegisterTypes(this.serviceManager);
}
public registerFormatterTypes() {
formattersRegisterTypes(this.serviceManager);
}
public registerMockProcessTypes() {
this.serviceManager.addSingleton<IBufferDecoder>(IBufferDecoder, BufferDecoder);
this.serviceManager.addSingleton<IProcessService>(IOriginalProcessService, ProcessService);
this.serviceManager.addSingleton<IProcessService>(IProcessService, MockProcessService);
this.serviceManager.addSingleton<IPythonExecutionFactory>(IPythonExecutionFactory, PythonExecutionFactory);
}
}