On Sep 13, 1:21 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Sep 12, 5:00 pm, Leigh Klotz <[EMAIL PROTECTED]> wrote:
>
> > Does anybody have suggestions about how I can let my LOCALE Scope
> > object use the Guice modules to obtain a Locale Provider?
>
> Your scopes shouldn't be static.
> There's a new method in recent snapshots called requestInjection()
> on AbstractModule. Use this method to get your
> scope instance injected in the same place that
> you call bindScope().

Thank you! This looks like just what I want.   Unfortunately, I can't
get it to work.

First Issue (minor):

I looked in SVN head for examples on how to make the scope not be
static.
SVN head still seems to use static scopes:
In 
http://code.google.com/p/google-guice/source/browse/trunk/servlet/src/com/google/inject/servlet/ServletScopes.java
  public static final Scope REQUEST = new Scope()

I found I could use
     bindScope(LocaleScoped.class, LocaleScope.LOCALE);
     requestInjection(LocaleScope.LOCALE);
and this appeared to work, until I ran into another bug (see bellw).
I'm not clear on what I would do with a non-static scope (i.e., how to
refer to it elsewhere, but I suppose this will become clear when the
Guice ServletScopes get re-written to be non-static.)

Second issue (killer):
Once I try to use the Provider<Locale> that I inject into my Locale
Scope, in snapshot20080818 but I run into a NullPointerException.   I
think it's the same issue as 
http://code.google.com/p/google-guice/issues/detail?id=222
which was from snapshot20080713.

In 20080818 the NullPointerException is in
com.google.inject.InjectorImpl$8.get(InjectorImpl.java:1037)
instead of line 1015.

To work around the Scope issue with NullPointerException, I tried
using a Provider<MyClass> instead of a Scope for @Locale MyClass, but
ran into the problem that I can't force MyClassProvider to use Guice
to create the MyClass object I need to populate its cache; i.e., I see
no equivalent of the creator.get() call from Scope.scope, except of
course provider.get(), which I obviously can't use because it would
just call MyClassProvider.get() infinitely.  (I suppose I could do
some hack with two Providers for MyClass, and use an annotation to
mark the real one.  Ugh.)

So, I think the right thing is to wait for Issue 222 to be resolved.

Thank you,
Leigh.


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

Reply via email to