Let's say I have an interface called SocialNetworkService
, and three implementations - TwitterService
, FacebookService
and FriendFeedService
.
Now I want, whenever my managed bean (or whatever web component) receives a message, to share it in all social networks. I tried:
@Inject private List<SocialNetworkService> socialNetworkServices;
But it didn't work (deployment error). (Also tried to the @Any
qualifier - same result)
So, is there a way to inject a list of all (or some) implementations of an interface?
I know the rule that a given injection point should not have more than one possible bean. I guess I can achieve that by making a producer that produces the list, and using Instance<SocialNetworkService>
, but that seems like too much for this task.
question from:
https://stackoverflow.com/questions/4009388/inject-list-of-objects-in-cdi-weld 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…