-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
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)
Should it be in the responsibility of the class to know in which context it will be used or the application (via guice module)? |
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. |
Is there a way to detect these 'orphan' classes which are automatically
wired by guice? Breaking the build would be better because even annotations
can be forgotten.
…On Wed, 7 Aug 2019, 10:04 Christoph Sturm, ***@***.***> wrote:
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.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#3058?email_source=notifications&email_token=AALFXXW7RCVOKSWTOR2ORUDQDJ6XZA5CNFSM4IJXZL3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3XSD4A#issuecomment-518988272>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AALFXXVK3UDABTELYJYRO7DQDJ6XZANCNFSM4IJXZL3A>
.
|
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 |
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
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.