ServletModule should allow specification of scopes

639 views
Skip to first unread message

Gili

unread,
Feb 7, 2009, 12:40:32 AM2/7/09
to google-guice
Hi,

I tried using com.wideplay.warp.persist.PersistenceFilter with guice-
servlet and got this error:

javax.servlet.ServletException: Filters must be bound as singletons.
Key[type=com.wideplay.warp.persist.PersistenceFilter, annotation=
[none]] was not bound in singleton scope.

Fair enough, but there is no way for me to do this. Shouldn't
ServletModule.filter() allow me to specify a scope? I don't think it's
realistic to assume that I can modify existing Filters because as this
example shows sometimes I am trying to use 3rd-party code which I
cannot modify.

Either guice-servlet needs to automatically bind all servlets and
filters to a singleton scope (which is my personal preference) or it
needs to allow me to specify a scope on a Module level without having
to modify the existing Servlet/Filter class.

Gili

Gili

unread,
Feb 7, 2009, 8:38:53 AM2/7/09
to google-guice
Adding:

binder.bind(PersistenceFilter.class).in(Scopes.SINGLETON);

in a separate Module helped. If this is what developers are supposed
to be doing it wasn't immediately obvious to me. If you wish to keep
the API as-is I would suggest mentioning in the documentation that
Servlet/Filter scopes are supposed to be bound in a separate Module.

Gili

Gili

unread,
Feb 13, 2009, 1:20:38 PM2/13/09
to google-guice
I filed http://code.google.com/p/google-guice/issues/detail?id=334

I believe this needs to be resolved for Guice 2.0 since it affects the
specification.

Gili

Dhanji R. Prasanna

unread,
Feb 13, 2009, 7:30:04 PM2/13/09
to google...@googlegroups.com
We should really annotate PersistenceFilter as a @Singleton in warp-persist. I will fix this shortly.

Dhanji.

Robbie Vanbrabant

unread,
Feb 14, 2009, 9:06:26 AM2/14/09
to google...@googlegroups.com

Dhanji R. Prasanna

unread,
Feb 14, 2009, 6:11:02 PM2/14/09
to google...@googlegroups.com
Thanks! my svn commit failed yesterday, so this is opportune =)
Reply all
Reply to author
Forward
0 new messages