Given a custom annotation MyAnnotation it shall be possible to inject an 
instance of MyManager (interface):

@MyAnnotation( classes = { A.class })

private MyManager myManager;


Currently I'm not sure how to bind the value of the found annotation 
parameter to inject it into the provider implementation:

protected void configure() {

//...

bind(MyManager.class).toProvider(MyManagerProvider.class);

bindListener(Matchers.any(), new MyManagerTypeListener());

 }

The TypeListener implementation:

public <T> void hear(TypeLiteral<T> typeLiteral,

TypeEncounter<T> typeEncounter) {


 for (Field field : typeLiteral.getRawType().getDeclaredFields()) {

if (field.getType() == MyManager.class

&& field.isAnnotationPresent(MyAnnotation.class)) {

typeEncounter.register(new MyManagerInjector<T>(field,

typeEncounter.getProvider(MyManager.class).get());

}

}

}

And finally the Provider implementation:

public class MyManagerProvider implements Provider<MyManager> {


private final Class<?>[] classes;


@Inject

public MyManagerProvider(final Class<?>... classes) {

this.classes = classes;

}


public MyManager get() {

return MyManagerImpl(classes);

}

}


Kindest regards, Lars

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to