users@jersey.java.net

[Jersey] Accessing Application-side resources from custom InjectableProvider

From: Franck Mangin <franck102_at_yahoo.com>
Date: Thu, 8 Nov 2012 09:04:59 -0800 (PST)

I am fairly new to Jersey and injection in general, and I am trying to figure out what the best way is to access an Application-wide resource from a custom injectable provider?

I would like my JAX-RS service to maintain a connection pool (to some backend service, e.g. DB), and I have a custom ConnectionInjectableProvider that extends  AbstractHttpContextInjectable<E> and works fine, but currently takes connections from a pool java singleton, and I would like to get rid of that singleton.


I could imagine having an injectable provider for the Pool with a Singleton scope, but is it legal for my ConnectionInjectableProvider (request scope) to depend on the PoolInjectableProvider (singleton scope)? Is there a better/simpler design pattern here? I don't see a way to navigate from the HttpContext to some kind of ApplicationContext that could keep a reference to the Pool, did I miss something?
Thanks for your help!