6
Mam pewne zasoby, ale nie mogę iterować go i powiązać je wszystkie, Muszę użyć klucza, aby poprosić o zasób. Więc muszę dynamicznie wstrzykiwać.Guice dynamiczne wstrzykiwanie z niestandardową adnotacją
zdefiniować adnotację jak
@Target({ METHOD, CONSTRUCTOR, FIELD })
@Retention(RUNTIME)
@Documented
@BindingAnnotation
public @interface Res
{
String value();// the key of the resource
}
użytku jak ten
public class Test
{
@Inject
@Res("author.name")
String name;
@Inject
@Res("author.age")
int age;
@Inject
@Res("author.blog")
Uri blog;
}
muszę sobie zastrzyk uwagami przez @Res
i muszę znać wstrzykiwać pola i adnotacji.
Czy to możliwe w Guice
i jak? nawet ze spi?
możliwym duplikatu https://stackoverflow.com/questions/5704918/custom-guice-binding-annotations-with-parameters i https : //stackoverflow.com/questions/41958321/guicebinding-annotations-with-attributes – Phil