On Tuesday, August 14, 2012 2:46:54 AM UTC-4, wujek wrote:
If I understood correctly, you could:1. define a parameter of type InjectionPoint in your provider method
2. call injectionPoint.getMember().getDeclaringClass()
which should give you the class that declares the injection point. From the class, you can easily get the package.
Is that of any help?
You mean, do something like this in the module class?
@Provides
public Settings getSettings(InjectionPoint ip) {
TypeLiteral<?> type = ip.getDeclaringType();
Namespace ns = findNamespace(type);
String namespaceName = ns == null ? Namespace.DEFAULT : ns.value();
return settingsForNamespace.get(namespaceName);
}
It sounds great - clean and elegant. Alas, it doesn't work :
"Could not find a suitable constructor in com.google.inject.spi.InjectionPoint. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private."
Maybe there is some other type that *could* be injected that would provide a path to the InjectionPoint? InjectionPoint is definitely the thing I need to get hold of...
Thanks!
-Tim