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

use singleton annotation instead of binding as singleton #3058

Merged
merged 4 commits into from
Aug 13, 2019

Conversation

christophsturm
Copy link
Contributor

this is the correct way to do it. the way it is currently done means
that if a component is not declared in a module, guice still finds it
but does not use the singleton lifecycle

binding as singleton in the module is meant to be used for classes that
we don't have the sourcecode for (i.e. jdk classes)

also update guice because the current version has some incompatibilites with our asm lib and outputs internal errors when the wiring fails.

this pr only converts the components that were declared in the desktop module. will convert the others later.

this is the correct way to do it. the way it is currently done means
that if a component is not declared in a module, guice still finds it
but does not use the singleton lifecycle

binding as singleton in the module is meant to be used for classes that
we don't have the sourcecode for (i.e. jdk classes)
@ManfredKarrer
Copy link
Contributor

Should it be in the responsibility of the class to know in which context it will be used or the application (via guice module)?

@christophsturm
Copy link
Contributor Author

definately the class, the class knows if its a singleton. also the problem is that even when the class is not defined in the module but still on the classpath it will be found by guice, but have the wrong lifecycle. doing it by annotation ensures that the lifecycle is always correct.

@mrosseel
Copy link
Contributor

mrosseel commented Aug 7, 2019 via email

@christophsturm
Copy link
Contributor Author

It's not really orphan classes, it's just how guice works. Binding a class in the module is for classes that you don't have the sourcecode for. If you add an Inject annotation and the class is a singleton you need to add a Singleton annotation too.

Copy link

@blabno blabno left a comment

Choose a reason for hiding this comment

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

The code looks good.
I see pros and cons in both approaches. Just as forgetting to configure class as singleton in a module you can forget about annotating the class. Defining life cycle inside module allows for class reuse in different context, but that's very theoretical benefit.

Copy link
Member

@sqrrm sqrrm left a comment

Choose a reason for hiding this comment

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

ACK

@sqrrm sqrrm merged commit e52c255 into bisq-network:master Aug 13, 2019
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.

5 participants