Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to rebind messaging services in preload #13199

Merged
merged 1 commit into from
Dec 21, 2023

Conversation

msujew
Copy link
Member

@msujew msujew commented Dec 20, 2023

What it does

Closes #13094

When trying to rebind the messaging services in the preload step, you were only able to bind them for a child container of the original container. That eventually led to multiple messaging services being created, which leads to unexpected issues, such as multiple websocket connections (where only one is actually needed).

This change binds the preload services directly on the global frontend container. This way, adopters can rebind messaging services already in the preload stage, preventing multiple instances of those services from appearing.

How to test

You will need to rebind the messaging services. Create a new module and perform the binding like this:

import { ContainerModule } from 'inversify';
import { LocalConnectionProvider, RemoteConnectionProvider, ServiceConnectionProvider } from '../messaging/service-connection-provider';
import { ConnectionSource } from '../messaging/connection-source';
import { WebSocketConnectionSource } from '../messaging/ws-connection-source';

const backendServiceProvider = Symbol('backendServiceProvider');

export default new ContainerModule((bind, _, __, rebind) => {
    bind(backendServiceProvider).toDynamicValue(ctx => {
        bind(CustomServiceConnectionProvider).toSelf().inSingletonScope();
        const container = ctx.container.createChild();
        container.bind(ConnectionSource).toService(WebSocketConnectionSource);
        return container.get(CustomServiceConnectionProvider);
    }).inSingletonScope();
    rebind(LocalConnectionProvider).toService(backendServiceProvider);
    rebind(RemoteConnectionProvider).toService(backendServiceProvider);
});

class CustomServiceConnectionProvider extends ServiceConnectionProvider {

    override init(): void {
        console.log('Constructing custom service connection');
        super.init();
    }
}

Afterwards put this in an additional frontendPreload entry in the package.json, build and start the browser app. At frontend startup, the logging above should be printed only once and the frontend preload should perform without errors.

Review checklist

Reminder for reviewers

Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

@msujew msujew merged commit 901c806 into master Dec 21, 2023
14 checks passed
@msujew msujew deleted the msujew/allow-rebinding-in-preload branch December 21, 2023 14:14
@github-actions github-actions bot added this to the 1.45.0 milestone Dec 21, 2023
@vince-fugnitto vince-fugnitto modified the milestone: 1.45.0 Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
messaging issues related to messaging
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Theia creates 2 web-sockets if we override the WebSocketConnectionProvider class
3 participants