google-code-export / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
2 stars 1 forks source link

Scopes.isSingleton #388

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
A new API that takes a Binding (from either a module or an injector), and 
returns whether it resolves 
to a single instance or not. Should work for linked bindings and provider 
bindings.

Original issue reported on code.google.com by limpbizkit on 12 Jun 2009 at 5:27

GoogleCodeExporter commented 9 years ago
Ohh awesome, this will total help with the flakiness in testing servlet 
singletons.

Original comment by dha...@gmail.com on 12 Jun 2009 at 5:52

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 23 Jun 2009 at 6:34

GoogleCodeExporter commented 9 years ago
I noticed that Scopes.isSingleton returns false for exposed bindings that are 
in fact
singleton. I don't imagine this is the desired result.

Adding this lines in Scopes#isSingleton solved the problem for me

public static boolean isSingleton(Binding<?> binding) {
// handle exposed bindings differently
if (binding instanceof ExposedBinding) {
  ExposedBinding exposed = (ExposedBinding) binding;
  // we are guaranteed to get the child injector and a non-exposed binding
  return
isSingleton(exposed.getPrivateElements().getInjector().getBinding(binding.getKey
()));
}
....
}

Original comment by alen_vre...@yahoo.com on 3 Oct 2009 at 6:56