Hi,
Is it possible to detect the scope associated with Binding returned by
Injector.getBinding(Key)? I'm trying to detect at runtime whether a
user specified multiple Scopes from different frameworks, such as
Guice, Spring, and Jersey (JAX-RS) so I can throw an error.
PS: What happens when a user associates two scope annotations with the
same class? I assume it throws an error?
Thanks,
Gili
Gili
Stuart McCulloch wrote:
> 2008/10/7 Gili <gili.t...@gmail.com <mailto:gili.t...@gmail.com>>
Which new SPI? :)
I assume that Injector.getBinding(Key).acceptScopingVisitor() is the
way to use BindingScopingVisitor on injector bindings, but it isn't
clear how to use it against module bindings.
I would like to suggest the following:
- visitEagerSingleton() should link to
ScopedBindingBuilder.asEagerSingleton()
- visitNoScoping() "An unscoped binding will behave like a scoped one
when it is linked to a scoped binding." should probably reads "[...]
linked to a scoped *target*". I think "target" is easier to understand
in this context (too many uses of the word binding). Alternatively, your
other explanation is also much clearer: "Suppose you bind Foo to
FooImpl. If Foo is unscoped and FooImpl is a singleton, then Foo is
effectively a singleton."
- visitScopeAnnotation(): It isn't clear when this method is even
invoked. I tried invoking Binder.bindScope() and in(scopedAnnotation)
and neither of these triggered this method. visitScope() was triggered
instead. Remember, I am using the Guice-2.0 snapshot, not trunk.
> I took another pass on the scopes wiki. Hopefully it makes it more
> obvious what you'll need to do to define a custom scope:
> http://code.google.com/p/google-guice/wiki/Scopes
Thanks!
Gili