I have some resource, but I can not iterator it and bind them all, I have to use the key to request the resource.So, I have to dynamic inject.
I define an annotation like
@Target({ METHOD, CONSTRUCTOR, FIELD })
@Retention(RUNTIME)
@Documented
@BindingAnnotation
public @interface Res
{
String value();// the key of the resource
}
use like this
public class Test
{
@Inject
@Res("author.name")
String name;
@Inject
@Res("author.age")
int age;
@Inject
@Res("author.blog")
Uri blog;
}
I have to handle the injection annotated by @Res
and I need to know the
inject field and the annotation.
Is this possible in Guice
and how ? even with spi ?
I work out follow CustomInjections
Code like this