users@hk2.java.net

RequestScoped: dispose not called after request is completed

From: Andreas Lundblad <andreas.lundblad_at_gmail.com>
Date: Sat, 28 Sep 2013 21:16:15 +0200

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