0 Replies Latest reply on Dec 2, 2009 7:02 PM by Arbi Sookazian

    Injection into producer methods

    Arbi Sookazian Master


      @Produces @Preferred @SessionScoped
      public PaymentStrategy getPaymentStrategy(CreditCardPaymentStrategy ccps,
                                                CheckPaymentStrategy cps,
                                                PayPalPaymentStrategy ppps) {
         switch (paymentStrategy) {
            case CREDIT_CARD: return ccps;
            case CHEQUE: return cps;
            case PAYPAL: return ppps;
            default: return null;

      Wait, what if CreditCardPaymentStrategy is a request-scoped bean? Then the producer method has the effect of 'promoting' the current request scoped instance into session scope. This is almost certainly a bug! The request scoped object will be destroyed by the container before the session ends, but the reference to the object will be left 'hanging' in the session scope. This error will not be detected by the container, so please take extra care when returning bean instances from producer methods!

      Does Seam 2.x handle this scope impedance via scope promotion as well?  I never noticed honestly.  Why can't the container promote then demote as necessary at the end of the method execution or is that not possible?