Combining my attempts with an answer from the Weld forum:
@Inject @Any
private Instance<SocialNetworkService> services;
Instance implements Iterable, so it is then possible to simply use the for-each loop. The @Any qualifier is needed.
Another way to do this is by using the event system:
- create a
MessageEvent(containing all the information about the message) -
instead of injecting a list of social networks, simply inject the event:
@Inject private Event<MessageEvent> msgEvent;and fire it:
msgEvent.fire(new MessageEvent(message)); -
observe the event in all services (regardless of their interface, which might be a plus):
public void consumeMessageEvent(@Observes MessageEvent msgEvent) {..}