[cdi-dev] Sorting out the "bean name" mess
Pete Muir
pmuir at redhat.com
Thu Sep 6 18:02:58 EDT 2012
On 6 Sep 2012, at 22:39, Bill Shannon wrote:
> Pete Muir wrote on 09/06/2012 02:27 PM:
>>> Can I inject a bean by name? That would motivate the more general
>>> "bean name".
>>
>> You can do
>>
>> @Named("baz")
>> public class Foo {}
>>
>> public class Bar {
>>
>> @Inject @Named Foo baz;
>>
>> }
>>
>> We strongly recommend you don't do it, but you can...
>
> Can I do
>
> @Inject @Named("baz") Foo wombat;
>
> Or, more generally,
>
> @Named("baz")
> public class Foo implements Wombat {}
>
> @Named("bletch")
> public class Frob implements Wombat {}
>
> public class Bar {
> @Inject @Named("baz") Wombat wombat;
> }
>
Yes.
>
More information about the cdi-dev
mailing list