You can always use more than one Injector.

Injector conf = Guice.createInjector( new ConfigurationModule() );
Injector main =
Guice.createInjector( conf.getInstance( MainModule.class ) );

class ConfigurationModule extends AbstractModule {
 // configure Locale provider and locale scope
}

class MainModule extends AbstractModule
{
   // this @Inject fulfilled by Injector 'conf'
   @Inject public MainModule( LocaleScope localeScope )
 ...

I don't know how "best practices" that is, but ...

-d

On Sep 12, 5:00 pm, Leigh Klotz <[EMAIL PROTECTED]> wrote:
> This may be a bizzare question.
>
> Threre aren't many examples of custom scopes, so I've looked at the
> Guice implementation of ServletScopes.REQUEST and friends, and noticed
> that they all use static class access to GuiceFilter to obtain the
> object which implements the scope storage (request attributes, session
> attributes, etc.)
>
> I'm trying to write a scope that keeps track of injected objects by
> Locale, where Locale is determined by my existing Guice modules, which
> collude to be able to inject a Locale.
>
> I'd like to let my LocaleScope implement its own locale-keyed scope
> storage, and in its Provider's get() method, use a Provider<Locale> to
> determine which locale-keyed scope storage to use.
>
> To this end, I find myself wanting to do this:
>
>   public static final Scope LOCALE = new Scope() {
>       private Map<Locale, Map<String, Object>> cache = new
> HashMap<Locale, Map<String, Object>>();
>       @Inject Provider<Locale> localeProvider;
>
>       public <T> Provider<T> scope(Key<T> key, final Provider<T>
> creator) {
>         final String name = key.toString();
>         return new Provider<T>() {
>
>           public T get() {
>             Locale locale = getLocale();
>             ....
>
> It doesn't appear to be possible due to bootstrap issues to inject the
> Locale Provider into the LOCALE scope, even though this would
> eliminate one static reference that appears even in the Guice
> implementation.
>
> Does anybody have suggestions about how I can let my LOCALE Scope
> object use the Guice modules to obtain a Locale Provider?
>
> 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