ServletScopes.APPLICATION and @ApplicationScoped?

32 views
Skip to first unread message

Brian R. Jackson

unread,
Aug 31, 2010, 11:11:24 AM8/31/10
to google-guice
I have a guice app running in a JavaEE container and realize I have
the need to annotate my classes/providers with a (non-existant)
@ApplicationScoped. Specifically I'm registering ehcache MBeans and
need to dispose of them when the application is unloaded from the
container, and wanted to use guiceyfruit support of JSR-250 to do
that.

My question, is there a good reason this scope doesn't already exist?
Am I missing something silly, like the feature exists in a different
form? Or was it simply overlooked up to this point since many guice
apps don't run within JavaEE containers?

Thanks,
Brian

Dhanji R. Prasanna

unread,
Sep 1, 2010, 1:04:15 AM9/1/10
to google...@googlegroups.com
On Wed, Sep 1, 2010 at 1:11 AM, Brian R. Jackson <brian+...@jaxzin.com> wrote:
I have a guice app running in a JavaEE container and realize I have
the need to annotate my classes/providers with a (non-existant)
@ApplicationScoped.  Specifically I'm registering ehcache MBeans and
need to dispose of them when the application is unloaded from the
container, and wanted to use guiceyfruit support of JSR-250 to do
that.

My question, is there a good reason this scope doesn't already exist?
Am I missing something silly, like the feature exists in a different
form?

Well, it sounds a lot like @Singleton. If you mean is there some broader Java EE specific application scope, then no, we do not have an out-of-box solution for that =)

Dhanji.

Brian R. Jackson

unread,
Sep 1, 2010, 10:22:01 AM9/1/10
to google-guice
On Sep 1, 1:04 am, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:
> On Wed, Sep 1, 2010 at 1:11 AM, Brian R. Jackson
> <brian+goo...@jaxzin.com<brian%2Bgoo...@jaxzin.com>
Thanks Dhanji,
After posting this yesterday I came to the realization that @Singleton
is exactly equivalent to what I'm asking about. I forgot that each
application has their own Injector and that @Singletons aren't shared
at the JVM level, only at the Injector level.

By the way, it was incredibly simple to write the custom scope, which
I had done until I realized it effectively duplicated @Singleton and
Scopes.SINGLETON. Great job with the excellent documentation of
custom scopes. I threw out my implementation when I realized it
didn't add any value over Scopes.SINGLETON, which stored objects in
ServletContext.setAttribute() instead of the private volatile field in
the anonymous Provider that Scopes.SINGLETON uses.

Thanks again,
Brian

Dhanji R. Prasanna

unread,
Sep 1, 2010, 12:59:44 PM9/1/10
to google...@googlegroups.com
Sure. Thanks for the kind words, Jesse deserves a lot of the credit for the good docs in Custom Scopes, and our good docs in general.

Dhanji.

Brian

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.


Reply all
Reply to author
Forward
0 new messages