1 Reply Latest reply on Apr 27, 2010 8:46 AM by nickarls

    Multiple otherwise identical producer methods?

    ljnelson

      I am new to Weld.  I hope you'll forgive this introductory theory question.


      If I have a bean with an @Inject-annotated field on which I would like dependency injection to be performed, and if I have two different classes that each define a producer method that is capable of making objects that could conceivably go in this field, which of these two producer methods is invoked?


      My hunch is that buried in the spec somewhere is a clause that says this state of affairs is an error.  Is it?


      Is there any kind of way to have an aggregation of the return values of several auto-discovered producer methods injected into a single collection field?


      Thanks,
      Laird

        • 1. Re: Multiple otherwise identical producer methods?
          nickarls

          If two producers produce the same result (type and qualifiers) the result is an ambiguous resolve exception.


          You could have something like


             @Inject Instance<Foo> foos; // here go all beans that satisfy the Foo type or interface
          
             @Produces @TheRight
             public produceFoo()
             {
               // iterate over foos and return the one you want
             }
          



          Check out Instance in the spec or refguide.