users@jersey.java.net

Re: [Jersey] InjectableProvider question

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 20 Feb 2009 09:26:38 +0100

On Feb 19, 2009, at 10:47 PM, Roytman, Alex wrote:

> Paul,
>
> - Could you please clarify meaning of InjectableProvider.getScope()?

It states the scope under which the injectable provider can inject on
to.


> Is it matched to scope of component which will receive injection?

Yes.


> If several scopes are available, will the closest win (ie if
> injection receiver is PerRequest, it will first for PerRequest
> InjectableProvider and then Singleton?

Yes.


> Is it prohibited to inject PerRequest injectable into Singleton?

Yes, because the scope of the former is narrower than the scope of the
latter.


> It does not seem to be that simple because we can inject say
> HttpContext into Providers which are singletons...
>

Yes, that is because there are two injectable providers for
HttpContext, like in the example i previously provided. It can be
supported with just one, as singleton scoped provider, as i stated,
the use of the per-request is an optimization for per-request
resources because there is no point using a proxy.


> - Order of Providers. If I have InjectableProvider A and B (both of
> the same scope PerRequest) and B has A injected into it as field
> will Jersey reliably perform injection regardless of order A and B
> are loaded?


The scope of the injectable providers themselves are singleton (as are
all providers). Thus they can only have singletons injected on to
them. Currently field injection is the only reliable way to ensure
correct injection dependencies.


> Is there any dependency resolution protocol?

No. I don't want to implement that because it means i will start
writing more of an IoC container.


>
> For me B is not injected. Is it where your proxying can help?

Yes, with the point above that both A and V themselves need to be
singletons.


> Not sure it applies here because my B provider in itself can be
> created at any time even on web application startup so there is no
> need for any deferral.
>
> I wonder if it is not better for me to register A and B in proper
> order via Jersey API. If so are there any samples on it?
>


If you are using field injection they can be in any order. Currently i
do not use an ordered set for registration so order is not guaranteed,
i think i need to change that.


> Sorry for bugging you with my questions
>


No problem,
Paul.

> Alex
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>