Hello guys,
i have a handling question about guice. i like really dependency injection
and use this in the most of private projects. But currently i have some
problems with generics and multiple binding for one interface. For the
first problem i have another solution. i don't know if thats works, but i
will test it in the future.
So the second problem is for me currently a little bit difficult to
understand.
The starting point is:
I have an Interface thats supports Generic, for Example:
public interface GenericInterface<T> {}
So i have also an implemented class, for Example:
public class GenericClass<T> implements GenericInterface<T> {}
So this interface and class have some generic methods.
In my Modul i define some bindings:
public class ExampleModule extends AbstractModule {
public void configure() {
bind(GenericInterface.class).annotatedWith(Names.named("Example")).
toInstance(new GenericClass<String>());
bind(GenericInterface.class).annotatedWith(Names.named("Second")).
toInstance(new GenericClass<Integer>());
}
}
Now my Question. In my opinion, i have to different instances from
GenericInterface. So i can inject this with the annotation @Named
But in another case, i have a class, that will add all implementations of
GenericInterface without specify the name.
public class ExmapleClass {
@Inject
public <T> void addGeneric(GenericInterface<T> genericInterface) {}
}
Ok first, i find out, that generic methods doesn't work, but it's also not
possible to add automaticly all GenericInterfaces to this method. So i
searching for an solutions, that has the feature like the ServiceTracker
functionality from OSGi.
--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/293f68ba-b645-493d-9dcb-1f6165564e2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.