Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 343098

Summary: [Xtend] dependency injection support for BindingAnnotations and Named
Product: [Modeling] TMF Reporter: Sven Efftinge <sven.efftinge>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3    
Version: 2.0.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Sven Efftinge CLA 2011-04-18 04:04:45 EDT
The following part from the language reference needs yet to be implemented:


Guice Keys
Xtend uses Guice as the dependency injection container, which in turn uses types as keys. Those types can be generified, which is why you can write the following in Xtend.

@Inject HashMap<String,MyType> myCache;

Also Guice allows to use annotations to further distinct between different implementations of the same type. This is usually done by using the com.google.inject.name.Named annotation or a custom annotation which is itself annotated with com.google.inject.BindingAnnotation .

Xtend supports these two variants:

@Inject @CustomAnnotation my.Service customService; 
@Inject @"NamedThingy" my.Service namedService;

Providers are declared like in plain Guice. That is you wrap your type into com.google.inject.Provider . Example:

@Inject @CustomAnnotation Provider<Service> customServiceProvider;
Comment 1 Sven Efftinge CLA 2011-05-15 10:29:44 EDT
We have changed the language spec and decided to fully support Java Annotations, which makes this superfluous.