Comment #1 on issue 687 by sberlin: Allow for scope aliases
http://code.google.com/p/google-guice/issues/detail?id=687

FYI, it is possible to do this today (although somewhat annoying) using the Guice SPI.

untested code:
 Module aliasScopeModule(
    Class<? extends Annotation> originalScope,
    Class<? extends Annotation> aliasScope,
    Module srcModule) {
   List<Element> elements = Elements.getElements(srcModule);
   for (Element element : elements) {
Scope scope = element.acceptVisitor(new DefaultElementVisitor<Scope>()) {
       public Scope visit(ScopeBinding binding) {
         if (binding.getAnnotationType() == originalScope) {
           return binding.getScope();
         }
       }
     });
     if (scope != null) {
       return new AbstractModule() [
         public void configure() {
           bindScope(aliasScope, scope);
         }
       };
     }
   }
throw new IllegalStateException("scope: " + originalScope + " not found in module.");
 }

usage:
  Module m = new MyAppModule();
Module scopeAlias = aliasScopeModule(OriginalScopeAnnotation.class, AliasAnnotation.class, m);
  MyApp app = Guice.createInjector(m, scopeAlias).getInstance(MyApp.class);


--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" 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-dev?hl=en.

Reply via email to