dev@jersey.java.net

GuiceComponentProviderFactory seems to ignore Guice Scope for object bound in parent injector

From: Jae Lee <jlee119_at_gmail.com>
Date: Sun, 10 May 2009 13:23:25 +0100

Hi all,
I've got a newbie question really...

From brief look through GuiceComponentProviderFactory source code
(1.1.0.ea), it looks like if you built GuiceComponentProviderFactory with an
Injector Guice Scope is ignored for an object explicitly bound by its parent
Injector... is that an intended behaviour?

In my current project, we've got an Application and many Components
underneath. Component being loosely related resources, defines an
independent context. It is achieved by having a child Injector for each
Component under an Application.

Naturally we would have common class/object bound in Injector in Application
(a bit like application scope) and component specific class/object bound in
child Injector in Component (a bit like component scope)

It looks like GuiceComponentProviderFactory uses
GuiceInstantiatedComponentProvider which ignores Guice Scope, for any
explicitly bound class in parent Injector. Which is bit of problem when it
comes to Singleton scoped class.

Injector.getBinding(key) does return binding from parent Injector if
possible then fall back to Just In Time binding with Scopes.NO_SCOPE.

Given that even for Just In Time binding, there's a scope (NO_SCOPE) that
can be mapped to Jersey, is it possible to use GuiceManagedComponentProvider
all the time? Would that makes it functionally different from current
implementation? Benefit would be that then it can support Singleton Guice
object in parent Injector properly.

regards
J