Did you find a solution to this? I need to do a very similar thing.
On Tuesday, August 14, 2012 1:50:18 PM UTC-5, Tim Boudreau wrote:
>
> 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
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-guice/-/Y25KcekOTYUJ.
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.