-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathbackend-application-module.ts
140 lines (119 loc) · 6.99 KB
/
backend-application-module.ts
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// *****************************************************************************
// Copyright (C) 2017 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { ContainerModule, decorate, injectable } from 'inversify';
import { ApplicationPackage } from '@theia/application-package';
import { REQUEST_SERVICE_PATH } from '@theia/request';
import {
bindContributionProvider, MessageService, MessageClient, ConnectionHandler, RpcConnectionHandler,
CommandService, commandServicePath, messageServicePath, OSBackendProvider, OSBackendProviderPath
} from '../common';
import { BackendApplication, BackendApplicationContribution, BackendApplicationCliContribution, BackendApplicationServer } from './backend-application';
import { CliManager, CliContribution } from './cli';
import { IPCConnectionProvider } from './messaging';
import { ApplicationServerImpl } from './application-server';
import { ApplicationServer, applicationPath } from '../common/application-protocol';
import { EnvVariablesServer, envVariablesPath } from './../common/env-variables';
import { EnvVariablesServerImpl } from './env-variables';
import { ConnectionContainerModule } from './messaging/connection-container-module';
import { QuickInputService, quickInputServicePath, QuickPickService, quickPickServicePath } from '../common/quick-pick-service';
import { WsRequestValidator, WsRequestValidatorContribution } from './ws-request-validators';
import { KeyStoreService, keyStoreServicePath } from '../common/key-store';
import { KeyStoreServiceImpl } from './key-store-server';
import { ContributionFilterRegistry, ContributionFilterRegistryImpl } from '../common/contribution-filter';
import { EnvironmentUtils } from './environment-utils';
import { ProcessUtils } from './process-utils';
import { ProxyCliContribution } from './request/proxy-cli-contribution';
import { bindNodeStopwatch, bindBackendStopwatchServer } from './performance';
import { OSBackendProviderImpl } from './os-backend-provider';
import { BackendRequestFacade } from './request/backend-request-facade';
import { FileSystemLocking, FileSystemLockingImpl } from './filesystem-locking';
import { BackendRemoteService } from './backend-remote-service';
decorate(injectable(), ApplicationPackage);
const commandConnectionModule = ConnectionContainerModule.create(({ bindFrontendService }) => {
bindFrontendService(commandServicePath, CommandService);
});
const messageConnectionModule = ConnectionContainerModule.create(({ bind, bindFrontendService }) => {
bindFrontendService(messageServicePath, MessageClient);
bind(MessageService).toSelf().inSingletonScope();
});
const quickPickConnectionModule = ConnectionContainerModule.create(({ bindFrontendService }) => {
bindFrontendService(quickInputServicePath, QuickInputService);
bindFrontendService(quickPickServicePath, QuickPickService);
});
export const backendApplicationModule = new ContainerModule(bind => {
bind(ConnectionContainerModule).toConstantValue(commandConnectionModule);
bind(ConnectionContainerModule).toConstantValue(messageConnectionModule);
bind(ConnectionContainerModule).toConstantValue(quickPickConnectionModule);
bind(CliManager).toSelf().inSingletonScope();
bindContributionProvider(bind, CliContribution);
bind(BackendApplicationCliContribution).toSelf().inSingletonScope();
bind(CliContribution).toService(BackendApplicationCliContribution);
bind(BackendApplication).toSelf().inSingletonScope();
bindContributionProvider(bind, BackendApplicationContribution);
// Bind the BackendApplicationServer as a BackendApplicationContribution
// and fallback to an empty contribution if never bound.
bind(BackendApplicationContribution).toDynamicValue(ctx => {
if (ctx.container.isBound(BackendApplicationServer)) {
return ctx.container.get(BackendApplicationServer);
} else {
console.warn('no BackendApplicationServer is set, frontend might not be available');
return {};
}
}).inSingletonScope();
bind(IPCConnectionProvider).toSelf().inSingletonScope();
bind(ApplicationServerImpl).toSelf().inSingletonScope();
bind(ApplicationServer).toService(ApplicationServerImpl);
bind(ConnectionHandler).toDynamicValue(ctx =>
new RpcConnectionHandler(applicationPath, () =>
ctx.container.get(ApplicationServer)
)
).inSingletonScope();
bind(EnvVariablesServer).to(EnvVariablesServerImpl).inSingletonScope();
bind(ConnectionHandler).toDynamicValue(ctx =>
new RpcConnectionHandler(envVariablesPath, () => {
const envVariablesServer = ctx.container.get<EnvVariablesServer>(EnvVariablesServer);
return envVariablesServer;
})
).inSingletonScope();
bind(ApplicationPackage).toDynamicValue(({ container }) => {
const { projectPath } = container.get(BackendApplicationCliContribution);
return new ApplicationPackage({ projectPath });
}).inSingletonScope();
bind(WsRequestValidator).toSelf().inSingletonScope();
bindContributionProvider(bind, WsRequestValidatorContribution);
bind(KeyStoreService).to(KeyStoreServiceImpl).inSingletonScope();
bind(ConnectionHandler).toDynamicValue(ctx =>
new RpcConnectionHandler(keyStoreServicePath, () => ctx.container.get<KeyStoreService>(KeyStoreService))
).inSingletonScope();
bind(ContributionFilterRegistry).to(ContributionFilterRegistryImpl).inSingletonScope();
bind(EnvironmentUtils).toSelf().inSingletonScope();
bind(ProcessUtils).toSelf().inSingletonScope();
bind(OSBackendProviderImpl).toSelf().inSingletonScope();
bind(OSBackendProvider).toService(OSBackendProviderImpl);
bind(ConnectionHandler).toDynamicValue(
ctx => new RpcConnectionHandler(OSBackendProviderPath, () => ctx.container.get(OSBackendProvider))
).inSingletonScope();
bind(ProxyCliContribution).toSelf().inSingletonScope();
bind(CliContribution).toService(ProxyCliContribution);
bind(BackendRemoteService).toSelf().inSingletonScope();
bind(BackendRequestFacade).toSelf().inSingletonScope();
bind(ConnectionHandler).toDynamicValue(
ctx => new RpcConnectionHandler(REQUEST_SERVICE_PATH, () => ctx.container.get(BackendRequestFacade))
).inSingletonScope();
bindNodeStopwatch(bind);
bindBackendStopwatchServer(bind);
bind(FileSystemLocking).to(FileSystemLockingImpl).inSingletonScope();
});