SessionScoped instance not being injected

41 views
Skip to first unread message

Szymon Wartak

unread,
Feb 4, 2011, 3:50:33 AM2/4/11
to google-guice
I have a @SessionScoped DAO that's being injected into a Stripes
framework Interceptor constructor that seems to be found from the
interceptor (on subsequent calls) but is not being injected into a
service in the same request (and session). Why isn't the same instance
(initialized in the interceptor) being reused in the service (which is
in a different package in the same project)?

Making the DAO a @Singleton does the trick, but is unacceptable as the
DAO stores information that must remain consistent throughout a user's
session on an application that has multiple users who would be sharing
the same DAO instance.

Is it possible that Stripes is resetting or clearing the HTTP session
somewhere?

Szymon Wartak

unread,
Feb 8, 2011, 10:05:27 AM2/8/11
to google-guice
ok, I've figured it out. I changed the @SessionScoped to a
bind(DAO.class).in(ServletScopes.SESSION) statement with which the
injection works. As far as I understand, these should be equivalent,
but in my case they're producing different results.

One aspect that was troubling me along the way was that Stripes built
the interceptor that injected the DAO on startup causing errors as
this happened outside the scope of a session (which the DAO is
@SessionScoped. ActionBeanContext context information is needed to
initialize the DAO session context which I set in an
AbstractActionBean setContext method that is called during the
construction of the action bean.

Thanks for your interest and help.
Reply all
Reply to author
Forward
0 new messages