frjaeger220 / google-guice

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

Scoping.getScopeAnnotation() tends to return null for custom scopes #356

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It even seems to be null for Singleton objects.

When binding a scope as this

{{{
bindScope(MyScopeAnnotation, someScope);
}}}

then later on you call BindingImpl.getScoping().getScopeAnnotation() it
returns null for methods annotated with MyScopeAnnotation. This looks like
a minor bug? (albeit in private code that end users are not meant to be
calling :).

Maybe we need a new method like Scoping.fromInstance(scope) which also
takes the scope annotation

{{{
Scoping.fromInstance(scope, scopeAnnotation)
}}}

Then we can pass in the scope annotation to the scoping? Or maybe just
document that the getScopeAnnotation() mostly returns null?

Original issue reported on code.google.com by james.st...@gmail.com on 7 Apr 2009 at 7:36

GoogleCodeExporter commented 9 years ago
I'm sorry, neither BindingImpl nor Scoping are public APIs. In theory we could 
add a public API method to 
binding to get the scoping annotation, but that wouldn't work for bindings that 
were bound using a scope 
instance rather than a scope annotation. Consider this is perfectly legal:
  bindScope(ScopeAnnotationOne.class, someScope);
  bindScope(ScopeAnnotationTwo.class, someScope);
  bind(Foo.class).in(someScope);
What scope annotation would that return?

If you'd to programatically check how a binding is scoped, please use 
Binding.acceptScopingVisitor(). You may 
also need to follow multiple layers of LinkedBindings.

Original comment by limpbizkit on 26 Apr 2009 at 8:22