Open GoogleCodeExporter opened 9 years ago
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);
Original comment by sberlin
on 27 Feb 2012 at 5:40
Original issue reported on code.google.com by
zorze...@gmail.com
on 27 Feb 2012 at 5:10