Skip to content

Add dependency-injection support to LayoutRegistry #234

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

Merged
merged 3 commits into from
Sep 1, 2021

Conversation

CamilleLetavernier
Copy link
Contributor

Modify the LayoutRegistry to support LayoutRegistrations via dependency-injection, similar to how it's done for other registries

@gitpod-io
Copy link

gitpod-io bot commented Aug 12, 2021

@CamilleLetavernier
Copy link
Contributor Author

I'm not sure how the default layouts should be registered. Ideally, we want to be able to remove them, or to associate a different implementation with the same key (e.g. providing our own implementation for the "vbox" layout).

@tortmayr tortmayr requested a review from spoenemann August 12, 2021 10:45
Copy link
Contributor

@spoenemann spoenemann left a comment

Choose a reason for hiding this comment

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

Hi @CamilleLetavernier, thanks for the contribution!

You can look at the action handler registrations to see how to define the registration in a way that the default layouts can be overridden:
https://github.com/eclipse/sprotty/blob/6b6f109246bfa56ca11c1a72c0da920d1e194bab/src/base/actions/action-handler.ts#L73-L87

The utility function binds the constructor to itself, so users can override that by rebinding the constructor.

@tortmayr
Copy link
Contributor

Hi @CamilleLetavernier, thanks for the contribution!

You can look at the action handler registrations to see how to define the registration in a way that the default layouts can be overridden:
https://github.com/eclipse/sprotty/blob/6b6f109246bfa56ca11c1a72c0da920d1e194bab/src/base/actions/action-handler.ts#L73-L87

The utility function binds the constructor to itself, so users can override that by rebinding the construc

@spoenemann Maybe we should apply this pattern to all classes that are multiinjected. I haven't had a detailed look yet, but I know that there at least some multiinjected classes that are not bound to itself before they are bound to the multiinjected key.
e.g. https://github.com/eclipse/sprotty/blob/6b6f109246bfa56ca11c1a72c0da920d1e194bab/src/features/move/di.config.ts#L23

@spoenemann
Copy link
Contributor

Yes, that makes sense! In that case it can be expressed more simply:

bind(MoveMouseListener).toSelf().inSingletonScope();
bind(TYPES.MouseListener).toService(MoveMouseListener); 

@CamilleLetavernier
Copy link
Contributor Author

Thanks for the reviews!

I've addressed the simple comments (Using logger & sorting the TYPES). I also noticed that the tests were broken, because manually instantiating a LayoutRegistry no longer registers the 3 default layouts; it should be fixed now.

I still need to add a "configureLayout" function, similar to the Action handlers, but I won't have time to do that (and test that with my use cases) properly this week; so I'll keep it for later :)

@CamilleLetavernier
Copy link
Contributor Author

I've rebased the branch on the current master, and added a configureLayout() function

Copy link
Contributor

@spoenemann spoenemann left a comment

Choose a reason for hiding this comment

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

Great!

@spoenemann spoenemann merged commit f1ef5b6 into eclipse-sprotty:master Sep 1, 2021
@spoenemann
Copy link
Contributor

Maybe we should apply this pattern to all classes that are multiinjected. I haven't had a detailed look yet, but I know that there at least some multiinjected classes that are not bound to itself before they are bound to the multiinjected key.

@tortmayr is there already an issue about this?

@tortmayr
Copy link
Contributor

tortmayr commented Sep 1, 2021

Maybe we should apply this pattern to all classes that are multiinjected. I haven't had a detailed look yet, but I know that there at least some multiinjected classes that are not bound to itself before they are bound to the multiinjected key.

@tortmayr is there already an issue about this?

I don't think so. I created #239 to track this.

@spoenemann spoenemann added this to the v0.10.0 milestone Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants