Discussion:
Clarification regarding getting a singleton instance in GUICE
Keerthi K
2017-08-16 19:18:13 UTC
Permalink
Hi,

I am trying to create a singleton instance per class loader instead of an
injector. I am fairly new to google guice and i am wondering if we can
create a singleton using google guice per class loader instead of an
injector?
Yes only one instance of key [Service] but not of key [ServiceImpl].
instance.
Dhanji.
<javascript:>>
On another note, does the following code also generate one instance
per injector?
public class MyModule implements Module {
public void configure(Binder binder) {
binder.bind(Service.class)
.to(ServiceImpl.class)
.in(Scopes.SINGLETON);
}
}
From Guice's user guide.
That does help. Thanks!!
What I like about this group, I always learn something new, static
is
indeed per classloader:)
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/5f867715-692c-4c13-a7c5-3818b17dbe40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2017-08-16 19:36:08 UTC
Permalink
I don't understand what you are trying to achieve. Guice is all about injecting so you cannot have guice without an injector.

If you try to have Guice inject an instance depending on the current classloader you could try to write a scope which ensures one instance per classloader.
Post by Keerthi K
Hi,
I am trying to create a singleton instance per class loader instead of an
injector. I am fairly new to google guice and i am wondering if we can
create a singleton using google guice per class loader instead of an
injector?
Yes only one instance of key [Service] but not of key [ServiceImpl].
instance.
Dhanji.
<javascript:>>
On another note, does the following code also generate one instance
per injector?
public class MyModule implements Module {
public void configure(Binder binder) {
binder.bind(Service.class)
.to(ServiceImpl.class)
.in(Scopes.SINGLETON);
}
}
From Guice's user guide.
That does help. Thanks!!
What I like about this group, I always learn something new,
static
is
indeed per classloader:)
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/5f867715-692c-4c13-a7c5-3818b17dbe40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/C59D74FB-4066-4B98-A526-1381F8BD5FCF%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2017-08-16 19:36:49 UTC
Permalink
I don't understand what you are trying to achieve. Guice is all about injecting so you cannot have guice without an injector.

If you try to have Guice inject an instance depending on the current classloader you could try to write a scope which ensures one instance per classloader.
Post by Keerthi K
Hi,
I am trying to create a singleton instance per class loader instead of an
injector. I am fairly new to google guice and i am wondering if we can
create a singleton using google guice per class loader instead of an
injector?
Yes only one instance of key [Service] but not of key [ServiceImpl].
instance.
Dhanji.
<javascript:>>
On another note, does the following code also generate one instance
per injector?
public class MyModule implements Module {
public void configure(Binder binder) {
binder.bind(Service.class)
.to(ServiceImpl.class)
.in(Scopes.SINGLETON);
}
}
From Guice's user guide.
That does help. Thanks!!
What I like about this group, I always learn something new,
static
is
indeed per classloader:)
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/5f867715-692c-4c13-a7c5-3818b17dbe40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/E57D778C-A13D-404F-BA9A-981B22F0E6A9%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Loading...