Let's say I have an interface called SocialNetworkService, and multiple implementations - TwitterService, FacebookService and FriendFeedService, MyService etc.
Now I want, whenever my managed bean receives a message, to select one/or more implementations depending on certain rules contained within the message and transmit the message accordingdly.
I am not quite sure which would be the best pattern to use?
a) Use Interface Instance i.e
@Inject @Any Instance<SocialNetworkService> socialNetworkService;
SocialNetworkService service = socialNetworkService.get();
How would I pass the message to the SocialNetworkServiceFactory ?
b) Use Events observe the event in all services (regardless of their interface, which is not exactly what i would like. I.e if i dont support dont transmit...
c). i could have annotaded injection i.e @Twitter, @Facebook all in a controller bean and then select the appropriate but my service implementations number will grow....
Thanks in advance,
Dimitri
You can always use iterator in order to obtain all current implementations