Skip to content

Commit

Permalink
Replace toDynamicValue with toService when possible
Browse files Browse the repository at this point in the history
When we have a binding in the form

  bind(OpenerService).toDynamicValue(context => context.container.get(DefaultOpenerService));

we prefer the equivalent form

  bind(OpenerService).toService(DefaultOpenerService);

This patch changes all instances I could find.  It was mostly generated
using sed, and a few more instances were adjusted by hand.

Change-Id: I82493bd8f4631fd8271bf1919c09ce5e2bcc5ea6
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
  • Loading branch information
Simon Marchi authored and paul-marechal committed Nov 9, 2018
1 parent bc233dd commit cea6233
Show file tree
Hide file tree
Showing 35 changed files with 68 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ function createHierarchyTreeContainer(parent: interfaces.Container): Container {

child.unbind(TreeImpl);
child.bind(CallHierarchyTree).toSelf();
child.rebind(Tree).toDynamicValue(ctx => ctx.container.get(CallHierarchyTree));
child.rebind(Tree).toService(CallHierarchyTree);

child.unbind(TreeModelImpl);
child.bind(CallHierarchyTreeModel).toSelf();
child.rebind(TreeModel).toDynamicValue(ctx => ctx.container.get(CallHierarchyTreeModel));
child.rebind(TreeModel).toService(CallHierarchyTreeModel);

child.bind(CallHierarchyTreeWidget).toSelf();
child.rebind(TreeWidget).toDynamicValue(ctx => ctx.container.get(CallHierarchyTreeWidget));
child.rebind(TreeWidget).toService(CallHierarchyTreeWidget);

return child;
}
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/browser/frontend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo

bindContributionProvider(bind, OpenHandler);
bind(DefaultOpenerService).toSelf().inSingletonScope();
bind(OpenerService).toDynamicValue(context => context.container.get(DefaultOpenerService));
bind(OpenerService).toService(DefaultOpenerService);
bind(HttpOpenHandler).toSelf().inSingletonScope();
bind(OpenHandler).toDynamicValue(ctx => ctx.container.get(HttpOpenHandler)).inSingletonScope();
bind(OpenHandler).toService(HttpOpenHandler);

bindContributionProvider(bind, WidgetFactory);
bind(WidgetManager).toSelf().inSingletonScope();
bind(ShellLayoutRestorer).toSelf().inSingletonScope();
bind(CommandContribution).toDynamicValue(ctx => ctx.container.get(ShellLayoutRestorer));
bind(CommandContribution).toService(ShellLayoutRestorer);

bind(DefaultResourceProvider).toSelf().inSingletonScope();
bind(ResourceProvider).toProvider(context =>
Expand All @@ -125,7 +125,7 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo

bind(SelectionService).toSelf().inSingletonScope();
bind(CommandRegistry).toSelf().inSingletonScope();
bind(CommandService).toDynamicValue(context => context.container.get(CommandRegistry));
bind(CommandService).toService(CommandRegistry);
bindContributionProvider(bind, CommandContribution);
bind(QuickOpenContribution).to(CommandQuickOpenContribution);

Expand All @@ -141,15 +141,15 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo

bind(CommonFrontendContribution).toSelf().inSingletonScope();
[CommandContribution, KeybindingContribution, MenuContribution].forEach(serviceIdentifier =>
bind(serviceIdentifier).toDynamicValue(ctx => ctx.container.get(CommonFrontendContribution)).inSingletonScope()
bind(serviceIdentifier).toService(CommonFrontendContribution)
);

bind(QuickOpenService).toSelf().inSingletonScope();
bind(QuickPickService).toSelf().inSingletonScope();
bind(QuickCommandService).toSelf().inSingletonScope();
bind(QuickCommandFrontendContribution).toSelf().inSingletonScope();
[CommandContribution, KeybindingContribution].forEach(serviceIdentifier =>
bind(serviceIdentifier).toDynamicValue(ctx => ctx.container.get(QuickCommandFrontendContribution)).inSingletonScope()
bind(serviceIdentifier).toService(QuickCommandFrontendContribution)
);

bind(PrefixQuickOpenService).toSelf().inSingletonScope();
Expand All @@ -165,7 +165,7 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo
bind(StorageService).toService(LocalStorageService);

bind(StatusBarImpl).toSelf().inSingletonScope();
bind(StatusBar).toDynamicValue(ctx => ctx.container.get(StatusBarImpl)).inSingletonScope();
bind(StatusBar).toService(StatusBarImpl);
bind(LabelParser).toSelf().inSingletonScope();

bindContributionProvider(bind, LabelProviderContribution);
Expand Down Expand Up @@ -193,10 +193,10 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo
};
});
bind(FrontendConnectionStatusService).toSelf().inSingletonScope();
bind(ConnectionStatusService).toDynamicValue(ctx => ctx.container.get(FrontendConnectionStatusService)).inSingletonScope();
bind(FrontendApplicationContribution).toDynamicValue(ctx => ctx.container.get(FrontendConnectionStatusService)).inSingletonScope();
bind(ConnectionStatusService).toService(FrontendConnectionStatusService);
bind(FrontendApplicationContribution).toService(FrontendConnectionStatusService);
bind(ApplicationConnectionStatusContribution).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toDynamicValue(ctx => ctx.container.get(ApplicationConnectionStatusContribution)).inSingletonScope();
bind(FrontendApplicationContribution).toService(ApplicationConnectionStatusContribution);

bind(ApplicationServer).toDynamicValue(ctx => {
const provider = ctx.container.get(WebSocketConnectionProvider);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/browser/keybinding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ before(async () => {

bind(TestContribution).toSelf().inSingletonScope();
[CommandContribution, KeybindingContribution].forEach(serviceIdentifier =>
bind(serviceIdentifier).toDynamicValue(ctx => ctx.container.get(TestContribution)).inSingletonScope()
bind(serviceIdentifier).toService(TestContribution)
);

bind(KeybindingContext).toConstantValue({
Expand All @@ -69,8 +69,8 @@ before(async () => {
});

bind(StatusBarImpl).toSelf().inSingletonScope();
bind(StatusBar).toDynamicValue(ctx => ctx.container.get(StatusBarImpl)).inSingletonScope();
bind(CommandService).toDynamicValue(context => context.container.get(CommandRegistry));
bind(StatusBar).toService(StatusBarImpl);
bind(CommandService).toService(CommandRegistry);
bind(LabelParser).toSelf().inSingletonScope();
bind(FrontendApplicationStateService).toSelf().inSingletonScope();
});
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/browser/tree/tree-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ export function createTreeContainer(parent: interfaces.Container, props?: Partia
child.parent = parent;

child.bind(TreeImpl).toSelf();
child.bind(Tree).toDynamicValue(ctx => ctx.container.get(TreeImpl));
child.bind(Tree).toService(TreeImpl);

child.bind(TreeSelectionServiceImpl).toSelf();
child.bind(TreeSelectionService).toDynamicValue(ctx => ctx.container.get(TreeSelectionServiceImpl));
child.bind(TreeSelectionService).toService(TreeSelectionServiceImpl);

child.bind(TreeExpansionServiceImpl).toSelf();
child.bind(TreeExpansionService).toDynamicValue(ctx => ctx.container.get(TreeExpansionServiceImpl));
child.bind(TreeExpansionService).toService(TreeExpansionServiceImpl);

child.bind(TreeNavigationService).toSelf();

child.bind(TreeModelImpl).toSelf();
child.bind(TreeModel).toDynamicValue(ctx => ctx.container.get(TreeModelImpl));
child.bind(TreeModel).toService(TreeModelImpl);

child.bind(TreeWidget).toSelf();
child.bind(TreeProps).toConstantValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ export default new ContainerModule(bind => {

bind(ElectronMenuContribution).toSelf().inSingletonScope();
for (const serviceIdentifier of [FrontendApplicationContribution, KeybindingContribution, CommandContribution, MenuContribution]) {
bind(serviceIdentifier).toDynamicValue(ctx => ctx.container.get(ElectronMenuContribution)).inSingletonScope();
bind(serviceIdentifier).toService(ElectronMenuContribution);
}
});
2 changes: 1 addition & 1 deletion packages/core/src/node/backend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ decorate(injectable(), ApplicationPackage);
export function bindServerProcess(bind: interfaces.Bind, masterFactory: RemoteMasterProcessFactory): void {
bind(RemoteMasterProcessFactory).toConstantValue(masterFactory);
bind(ServerProcess).toSelf().inSingletonScope();
bind(BackendApplicationContribution).toDynamicValue(ctx => ctx.container.get(ServerProcess)).inSingletonScope();
bind(BackendApplicationContribution).toService(ServerProcess);
}

export const backendApplicationModule = new ContainerModule(bind => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/node/logger-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function bindLogger(bind: interfaces.Bind): void {
bind(LoggerWatcher).toSelf().inSingletonScope();
bind(ILoggerServer).to(ConsoleLoggerServer).inSingletonScope();
bind(LogLevelCliContribution).toSelf().inSingletonScope();
bind(CliContribution).toDynamicValue(ctx => ctx.container.get(LogLevelCliContribution));
bind(CliContribution).toService(LogLevelCliContribution);
bind(LoggerFactory).toFactory(ctx =>
(name: string) => {
const child = new Container({ defaultScope: 'Singleton' });
Expand Down
4 changes: 2 additions & 2 deletions packages/cpp/src/browser/cpp-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ import { TaskContribution } from '@theia/task/lib/browser/task-contribution';
export default new ContainerModule(bind => {
bind(CommandContribution).to(CppCommandContribution).inSingletonScope();
bind(CppKeybindingContext).toSelf().inSingletonScope();
bind(KeybindingContext).toDynamicValue(context => context.container.get(CppKeybindingContext));
bind(KeybindingContext).toService(CppKeybindingContext);
bind(KeybindingContribution).to(CppKeybindingContribution).inSingletonScope();

bind(CppLanguageClientContribution).toSelf().inSingletonScope();
bind(LanguageClientContribution).toDynamicValue(ctx => ctx.container.get(CppLanguageClientContribution));
bind(LanguageClientContribution).toService(CppLanguageClientContribution);

bind(CppTaskProvider).toSelf().inSingletonScope();
bind(CppBuildConfigurationManager).to(CppBuildConfigurationManagerImpl).inSingletonScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export default new ContainerModule(bind => {
}));

bind(ExtensionWidgetFactory).toSelf().inSingletonScope();
bind(WidgetFactory).toDynamicValue(ctx => ctx.container.get(ExtensionWidgetFactory)).inSingletonScope();
bind(WidgetFactory).toService(ExtensionWidgetFactory);

bind(ExtensionOpenHandler).toSelf().inSingletonScope();
bind(OpenHandler).toDynamicValue(ctx => ctx.container.get(ExtensionOpenHandler)).inSingletonScope();
bind(OpenHandler).toService(ExtensionOpenHandler);
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function bindNodeExtensionServer(bind: interfaces.Bind, args?: Applicatio
bind(ApplicationProjectOptions).toConstantValue(args);
} else {
bind(ApplicationProjectCliContribution).toSelf().inSingletonScope();
bind(CliContribution).toDynamicValue(ctx => ctx.container.get(ApplicationProjectCliContribution)).inSingletonScope();
bind(CliContribution).toService(ApplicationProjectCliContribution);
bind(NpmClientOptions).toDynamicValue(ctx =>
ctx.container.get(ApplicationProjectCliContribution).args
).inSingletonScope();
Expand All @@ -44,9 +44,7 @@ export function bindNodeExtensionServer(bind: interfaces.Bind, args?: Applicatio

bind(ExtensionKeywords).toConstantValue([extensionKeyword]);
bind(NodeExtensionServer).toSelf().inSingletonScope();
bind(ExtensionServer).toDynamicValue(ctx =>
ctx.container.get(NodeExtensionServer)
).inSingletonScope();
bind(ExtensionServer).toService(NodeExtensionServer);
}

export default new ContainerModule(bind => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function createFileDialogContainer(parent: interfaces.Container): Contain

child.unbind(FileTreeModel);
child.bind(FileDialogModel).toSelf();
child.rebind(TreeModel).toDynamicValue(ctx => ctx.container.get(FileDialogModel));
child.rebind(TreeModel).toService(FileDialogModel);

child.unbind(FileTreeWidget);
child.bind(FileDialogWidget).toSelf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export function createFileTreeContainer(parent: interfaces.Container): Container

child.unbind(TreeImpl);
child.bind(FileTree).toSelf();
child.rebind(Tree).toDynamicValue(ctx => ctx.container.get(FileTree));
child.rebind(Tree).toService(FileTree);

child.unbind(TreeModelImpl);
child.bind(FileTreeModel).toSelf();
child.rebind(TreeModel).toDynamicValue(ctx => ctx.container.get(FileTreeModel));
child.rebind(TreeModel).toService(FileTreeModel);

child.unbind(TreeWidget);
child.bind(FileTreeWidget).toSelf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default new ContainerModule(bind => {
).inSingletonScope();

bind(FileResourceResolver).toSelf().inSingletonScope();
bind(ResourceResolver).toDynamicValue(ctx => ctx.container.get(FileResourceResolver));
bind(ResourceResolver).toService(FileResourceResolver);

bind(FrontendApplicationContribution).to(FileSystemFrontendContribution).inSingletonScope();
});
6 changes: 2 additions & 4 deletions packages/filesystem/src/node/filesystem-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { NsfwFileSystemWatcherServer } from './nsfw-watcher/nsfw-filesystem-watc

export function bindFileSystem(bind: interfaces.Bind): void {
bind(FileSystemNode).toSelf().inSingletonScope();
bind(FileSystem).toDynamicValue(ctx => ctx.container.get(FileSystemNode)).inSingletonScope();
bind(FileSystem).toService(FileSystemNode);
}

export function bindFileSystemWatcherServer(bind: interfaces.Bind): void {
Expand All @@ -39,9 +39,7 @@ export function bindFileSystemWatcherServer(bind: interfaces.Bind): void {
});
} else {
bind(FileSystemWatcherServerClient).toSelf();
bind(FileSystemWatcherServer).toDynamicValue(ctx =>
ctx.container.get(FileSystemWatcherServerClient)
);
bind(FileSystemWatcherServer).toService(FileSystemWatcherServerClient);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function bindGitHistoryModule(bind: interfaces.Bind) {
}));

bind(GitCommitDetailOpenHandler).toSelf();
bind(OpenHandler).toDynamicValue(ctx => ctx.container.get(GitCommitDetailOpenHandler));
bind(OpenHandler).toService(GitCommitDetailOpenHandler);

bindViewContribution(bind, GitHistoryContribution);

Expand Down
2 changes: 1 addition & 1 deletion packages/git/src/node/git-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function bindGit(bind: interfaces.Bind, bindingOptions: GitBindingOptions

export function bindRepositoryWatcher(bind: interfaces.Bind): void {
bind(DugiteGitWatcherServer).toSelf();
bind(GitWatcherServer).toDynamicValue(context => context.container.get(DugiteGitWatcherServer));
bind(GitWatcherServer).toService(DugiteGitWatcherServer);
}

export default new ContainerModule(bind => {
Expand Down
10 changes: 5 additions & 5 deletions packages/java/src/browser/java-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ import './monaco-contribution';

export default new ContainerModule(bind => {
bind(JavaCommandContribution).toSelf().inSingletonScope();
bind(CommandContribution).toDynamicValue(ctx => ctx.container.get(JavaCommandContribution)).inSingletonScope();
bind(KeybindingContribution).toDynamicValue(ctx => ctx.container.get(JavaCommandContribution)).inSingletonScope();
bind(MenuContribution).toDynamicValue(ctx => ctx.container.get(JavaCommandContribution)).inSingletonScope();
bind(CommandContribution).toService(JavaCommandContribution);
bind(KeybindingContribution).toService(JavaCommandContribution);
bind(MenuContribution).toService(JavaCommandContribution);

bind(JavaClientContribution).toSelf().inSingletonScope();
bind(LanguageClientContribution).toDynamicValue(ctx => ctx.container.get(JavaClientContribution));
bind(LanguageClientContribution).toService(JavaClientContribution);

bind(KeybindingContext).to(JavaEditorTextFocusContext).inSingletonScope();

bind(JavaResourceResolver).toSelf().inSingletonScope();
bind(ResourceResolver).toDynamicValue(ctx => ctx.container.get(JavaResourceResolver));
bind(ResourceResolver).toService(JavaResourceResolver);

bind(LabelProviderContribution).to(JavaLabelProviderContribution).inSingletonScope();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ export default new ContainerModule(bind => {
}

bind(LanguageClientProviderImpl).toSelf().inSingletonScope();
bind(LanguageClientProvider).toDynamicValue(ctx => ctx.container.get(LanguageClientProviderImpl)).inSingletonScope();
bind(LanguageClientProvider).toService(LanguageClientProviderImpl);

});
4 changes: 2 additions & 2 deletions packages/markers/src/browser/problem/problem-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export function createProblemTreeContainer(parent: interfaces.Container): Contai

child.unbind(TreeImpl);
child.bind(ProblemTree).toSelf();
child.rebind(Tree).toDynamicValue(ctx => ctx.container.get(ProblemTree));
child.rebind(Tree).toService(ProblemTree);

child.unbind(TreeWidget);
child.bind(ProblemWidget).toSelf();

child.unbind(TreeModelImpl);
child.bind(ProblemTreeModel).toSelf();
child.rebind(TreeModel).toDynamicValue(ctx => ctx.container.get(ProblemTreeModel));
child.rebind(TreeModel).toService(ProblemTreeModel);

child.rebind(TreeProps).toConstantValue(PROBLEM_TREE_PROPS);
child.bind(MarkerOptions).toConstantValue(PROBLEM_OPTIONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ export default new ContainerModule(bind => {
bind(MergeConflictsFrontendContribution).toSelf().inSingletonScope();
bind(MergeConflictsProvider).toSelf().inSingletonScope();
[CommandContribution, FrontendApplicationContribution].forEach(serviceIdentifier =>
bind(serviceIdentifier).toDynamicValue(c => c.container.get(MergeConflictsFrontendContribution)).inSingletonScope()
bind(serviceIdentifier).toService(MergeConflictsFrontendContribution)
);
});
2 changes: 1 addition & 1 deletion packages/messages/src/node/messages-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ConnectionHandler, JsonRpcConnectionHandler, MessageClient, Dispatching
export default new ContainerModule((bind, unbind, isBound, rebind) => {

bind(DispatchingMessageClient).toSelf().inSingletonScope();
rebind(MessageClient).toDynamicValue(ctx => ctx.container.get(DispatchingMessageClient)).inSingletonScope();
rebind(MessageClient).toService(DispatchingMessageClient);
bind(ConnectionHandler).toDynamicValue(ctx =>
new JsonRpcConnectionHandler<MessageClient>(messageServicePath, client => {
const dispatching = ctx.container.get<DispatchingMessageClient>(DispatchingMessageClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { MiniBrowserEndpoint, MiniBrowserEndpointHandler, HtmlHandler, ImageHand
export default new ContainerModule(bind => {
bind(MiniBrowserEndpoint).toSelf().inSingletonScope();
bind(BackendApplicationContribution).toService(MiniBrowserEndpoint);
bind(MiniBrowserService).toDynamicValue(context => context.container.get(MiniBrowserEndpoint));
bind(MiniBrowserService).toService(MiniBrowserEndpoint);
bind(ConnectionHandler).toDynamicValue(context => new JsonRpcConnectionHandler(MiniBrowserServicePath, () => context.container.get(MiniBrowserService))).inSingletonScope();
bindContributionProvider(bind, MiniBrowserEndpointHandler);
bind(MiniBrowserEndpointHandler).to(HtmlHandler).inSingletonScope();
Expand Down
6 changes: 2 additions & 4 deletions packages/monaco/src/browser/monaco-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
);

bind(MonacoOutlineContribution).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toDynamicValue(ctx => ctx.container.get(MonacoOutlineContribution));
bind(FrontendApplicationContribution).toService(MonacoOutlineContribution);

bind(MonacoStatusBarContribution).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(MonacoStatusBarContribution);
Expand All @@ -93,9 +93,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
rebind(StrictEditorTextFocusContext).to(MonacoStrictEditorTextFocusContext).inSingletonScope();

bind(MonacoQuickOpenService).toSelf().inSingletonScope();
rebind(QuickOpenService).toDynamicValue(ctx =>
ctx.container.get(MonacoQuickOpenService)
).inSingletonScope();
rebind(QuickOpenService).toService(MonacoQuickOpenService);

MonacoTextmateModuleBinder(bind, unbind, isBound, rebind);

Expand Down
Loading

0 comments on commit cea6233

Please sign in to comment.