Reputation: 3043
Let's say we have the following code:
@Inject
private Collection<SomeKind> myCollection;
What I want is that the dependencies after they were solved (I mean, all the classes that are of SomeKind type), could also being added to the collection. I know I can inject the ServiceLocator, and programmatically search for the instances on the registry, and then add them to the collection by myself, I just was wondering if there is a common mechanism for this scenario.
Upvotes: 2
Views: 331
Reputation: 209072
I think what you want is an IterableProvider<SomeKind>
. See the Documentation.
It's an Iterable, so you can use it in a for each loop
for (SomeKind someKind: someKinds) {
...
}
You could look them up by name
@Inject
IterableProvider<SomeKind> someKinds;
...
SomeKind someKind = someKinds.named("someName").get();
Here's a complete example using Jersey
Upvotes: 2