Your
EmailMessageSender
class implementsMessageSender
and therefore it is a bean available for injection with type eitherEmailMessageSender
orMessageSender
.Your producer returns a bean of type
MessageSender
.Your injection point wants the only bean in the whole application whose type and qualifiers exactly match the type and qualifiers of the injection point.
From one and two you have 2 beans that match a single injection point - therefore that's an ambiguous dependency.
Bottom line, your producer is absolutely pointless (aside from causing the error) in the above example because it simply returns a new instance of EmailMessageSender
which is the same exact effect as simply @Inject MessageSender
since EmailMessageSender
has the default scope @Dependent
.