If you get too frustrated waiting for this, the hack I described for injecting method interceptors in Guice 1.0 can be applied to scopes as well:
http://tembrel.blogspot.com/2007/09/injecting-method-interceptors-in-guice.html For a more comprehensive solution, if you're willing to do a little legwork, the DWR-Guice integration package I described contains a mini- framework for writing Guice scopes that depend on the notion of a "current" context, where in your case the context would be the Locale. The link in this blog entry http://tembrel.blogspot.com/2007/04/guice-support-in-dwr.html is to older code, in which the DWR and Guice concerns are entangled in the same package. The most recent code on the DWR site contains all the non-DWR Guice support in an separate independent package, org.directwebremoting.guice.util, but I haven't had time to bundle it up for nicely for general consumption. (Several folks have taken a look at it and said the lack of complete documentation was a showstopper for them.) --tim On Sep 15, 7:58 pm, Leigh Klotz <[EMAIL PROTECTED]> wrote: > 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: > Inhttp://code.google.com/p/google-guice/source/browse/trunk/servlet/src... > 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 > ashttp://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 -~----------~----~----~----~------~----~------~--~---
