users@jersey.java.net

[Jersey] CloseableService and InjectableProvider

From: Franck Mangin <franck102_at_yahoo.com>
Date: Fri, 15 Mar 2013 05:54:58 -0700 (PDT)

Hi all,

I would like to use a CloseableService to properly release an injected session object when the request gets out of scope.

It seems like the pattern below should work, however I would rather not depend on the resource classes to add the session to the closeable service, I would like that to be the responsibility of the InjectableProvider itself... However I don't know/understand whether injecting a CloseableService into the provider itself would work, and would have the proper scope?

Suggestions welcome!
Thanks,
Franck Mangin

class MyResource
{
    @Context CloseableService _cs;

    public MyResource getIt(@Context Session session, ...)
    {
        _cs.add(session);
        ...

    }

}

class SessionProvider implements InjectableProvider<Session>

{

    ...


    public ComponentScope getScope()
    {
        return ComponentScope.PerRequest;
    }
}