Okay, so there is an explicit step that must be taken for a producer method to win over a @Current bean (does not have additional bindings) of that type. I suspect in most cases developers will choose to use the binding type since that is the type-safe approach.<br>
<br>The designation of the alternative class in beans.xml makes all producer methods in that class have a higher precedence than any @Current bean of that type, correct? Is it also possible to specify a single method in beans.xml? There is alluded to in the Policy section, but no examples to support it.<br>
<br>Btw, I think this would be a lot clearer if it was explicitly stated in the spec how a producer method relates to a @Current bean of that type. I guess you could say it can be implied, but the first time someone goes to create a producer method, I can see them not realizing that they have to take an extra step to make it the preferred source.<br>
<br>-Dan<br><br><div class="gmail_quote">On Wed, Jul 22, 2009 at 7:13 AM, Pete Muir <span dir="ltr">&lt;<a href="mailto:pmuir@redhat.com">pmuir@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br>
On 22 Jul 2009, at 03:18, Dan Allen wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
After the recent revisions of the JSR-299 spec, I&#39;m finding that I&#39;m a tad confused about the bean selection algorithm when a producer method exists.<br>
<br>
Consider the following:<br>
<br>
class PotatoChip {<br>
}<br>
<br>
class SnackFactory() {<br>
    public @Produces PotatoChip createPotatoChip() {<br>
        return new PotatoChip();<br>
    }<br>
}<br>
<br>
1) Does the produced PotatoChip take precedence over the raw dependent type when being selected for injection?<br>
</blockquote>
<br></div>
No.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
2) How do I get the Bean&lt;PotatoChip&gt; that represents the producer method?<br>
<br>
BeanManager#getBeans(PotatoChip.class) returns two beans that are indistinguishable from the public API.<br>
</blockquote>
<br></div>
either:<br>
<br>
@Alternative<div class="im"><br>
class SnackFactory() {<br>
    public @Produces PotatoChip createPotatoChip() {<br>
        return new PotatoChip();<br>
    }<br>
}<br>
<br></div>
&lt;beans&gt;<br>
   &lt;alternatives&gt;<br>
      &lt;alternative&gt;SnackFactory&lt;/alternative&gt;<br>
   &lt;/alternatives&gt;<br>
&lt;/beans&gt;<br>
<br>
or<br>
<br>
class SnackFactory() {<br>
    public @Produces @Snack PotatoChip createPotatoChip() {<br>
        return new PotatoChip();<br>
    }<br>
}<br>
<br>
BeanManager.getBeans(PotatoChip.class, new AnnotationLiteral&lt;Snack&gt;() {});<br>
<br>
where @Snack is a binding type<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
3) What if the producer method is @RequestScoped? How do I get the request-scoped produce instead of the dependent bean?<br>
<br>
      Bean&lt;PotatoChip&gt; potatoChipBean = null;<br>
      for (Bean&lt;PotatoChip&gt; candidate : getBeans(PotatoChip.class))<br>
      {<br>
         if (candidate.getScopeType().equals(RequestScoped.class))<br>
         {<br>
            potatoChipBean = candidate;<br>
            break;<br>
         }<br>
      }<br>
<br>
Sorry if this sounds like a dumb question. The spec has changed a lot and my memory is getting mixed in with the current set of facts.<br>
</blockquote>
<br></div>
As above.<br>
<br>
It&#39;s possible the RI doesn&#39;t actually reflect this behavior atm - if you have a problem, make sure there is a test, then change the RI or file a WBRI.<br>
</blockquote></div><br><br clear="all"><br>-- <br>Dan Allen<br>Senior Software Engineer, Red Hat | Author of Seam in Action<br>Registered Linux User #231597<br><br><a href="http://mojavelinux.com">http://mojavelinux.com</a><br>
<a href="http://mojavelinux.com/seaminaction">http://mojavelinux.com/seaminaction</a><br><a href="http://in.relation.to/Bloggers/Dan">http://in.relation.to/Bloggers/Dan</a><br>