On Friday, May 25, 2012 10:35:27 AM UTC+2, Roger Gilliar wrote:
>
> Is it possible to retrieve an object with a specific annotation.
>
> Example:
>
> @ExtensionId(value=123)
> class Test {
> }
>
> @ExtensionId(value=124)
> class Test2 {
> }
>
> Object obj = injector.getInstance(???); // retrieve the object with the
> @ExtensionId(value=123)
> Object obj = injector.getInstance(???); // retrieve the object with the
> @ExtensionId(value=124)
>
> That would allow me to use the extension-id in an Eclipse RCP app to
> retrieve a specifc UI object in a Factory class.
>
1. create a class (say ExtensionIdImpl) that implements the ExtensionId
interface (have a look at Names.named() source code in Guice); make sure
you follow the contract for Annotation#equals()
2. use injector.getInstance(Key.get(Test.class, new ExtensionIdImpl(123)));
--
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/-/FghalGCpbOsJ.
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.