users@hk2.java.net

Re: RequestScoped: dispose not called after request is completed

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Mon, 30 Sep 2013 10:42:36 -0400

John,

     On a side-note, I don't think Guice 3.0 provides a mechanism to
dispose RequestScoped resources, so what does the Guice-HK2 bridge due
when dispose() is invoked? :)

Gili

On 30/09/2013 10:40 AM, John Wells wrote:
> I'm not sure why this would happen. However I think this is more of a
> question for the implementors of RequestScoped, which is Jersey (I
> think). You might want to re-post this question in the Jersey mail
> group...
>
> On 9/28/2013 3:16 PM, Andreas Lundblad wrote:
>> Hi,
>>
>> I'm having troubles setting up injection of objects that are request
>> scoped.
>>
>> I've tried the following:
>>
>> bindFactory(new Factory<MyService>() {
>>
>> @Override
>> public MyService provide() {
>> System.out.println("Creating a MyService...");
>> return new MyService(System.currentTimeMillis());
>> }
>>
>> @Override
>> public void dispose(MyService s) {
>> System.out.println("Disposing MyService");
>> }
>>
>> }).in(RequestScoped.class).to(MyService.class);
>>
>>
>> The MyService object is created, it is injected as it should be, but
>> dispose is never called.
>>
>> Any idea why?
>>
>> I'm using Jersey 2.3 and Grizzly.
>>
>> (This post describes the same issue:
>> http://stackoverflow.com/questions/17396165/using-jersey-2-0-how-do-you-register-a-bindable-instance-per-request
>> )
>>
>> best regards,
>> Andreas Lundblad
>