12 Replies Latest reply on Dec 15, 2009 6:51 PM by pmuir

    What about qualifying a conversation?

    agori

      I need to begin a conversation. I'd like that DI inside the conversation narrows bean selection using the qualifiers that I pass as parameter. For example:


      conversation.begin();
      conversation.qualify(new AnnotationLiteral<A>(){});
      




      Then if


      @Inject Bean bean;
      



      and


      @A class ABean extends Bean {
      }
      



      ABean is injected instead of Bean. Is this feature already available or not and is a stupid request?

        • 1. Re: What about qualifying a conversation?
          nickarls

          I don't quite follow. Are you talking about Specialization? Or are you referring to filtering the stuff in the conversation scope somehow?

          • 2. Re: What about qualifying a conversation?
            agori

            Yes specialization.
            One conversation should inject ABean, another conversation could inject BBean, another one CBean, depending on some parameter I pass to the conversation.


            If a Facelets page is under the first conversation and I code:


            #{bean}
            



            Expression Language should return an instanceof of type ABean. Do you understand?


            This is the API I have in mind, but it could be achievable in some other way that I don't know...

            • 3. Re: What about qualifying a conversation?
              gavin.king

              It sounds a bit like the activities stuff we had in older drafts of the CDI spec (which was removed). It sounds like you want a set of bean definitions that are local to a certain business task or process. Weld does not support this, however, you can localize bean definitions to a certain module. I would say that is your best bet, if I'm understanding your requirements correctly. Put each task or process in its own jar.

              • 4. Re: What about qualifying a conversation?
                nickarls

                Is the activity-stuff going away from Weld, too, or is there some use for it?

                • 5. Re: What about qualifying a conversation?
                  gavin.king

                  Does Weld actually implement that stuff?? I didn't know...


                  Yes, it's useful. It could easily find it's way back into CDI 1.1.

                  • 6. Re: What about qualifying a conversation?
                    nickarls

                    I don't know if it's functional/used, just noticed some references to it in BeanManager. And since most other obsolete stuff has been cleaned out, I assumed it's there for a reason...

                    • 7. Re: What about qualifying a conversation?
                      agori

                      I don't know what is an activity in CDI. Anyway modularization in different jar or packages  doesn't fit well in my situation.
                      I could explain with a use case. We have a web application for insurances. User login, then:



                      • select an insurance product, named prod1.

                      • WELD start a conversation, the main bean is ProductBean

                      • ProductBean cooperate with interface Service. Every Service implementation should has the same name, because product.xhtml references the bean: #{myService}



                      Ok, here developer coded two Service implementation: Prod1ServiceBean, and Prod2ServiceBean.
                      If user selected prod1 then WELD should inject Prod1ServiceBean into ProductBean. If prod2 was selected WELD should inject Prod2ServiceBean...


                      It's like deciding injection rules at runtime.

                      • 8. Re: What about qualifying a conversation?
                        nickarls

                        Sounds like a job for @Produces?


                          @Inject @Any Instance<ProdService> allProdServices;
                        
                          @Produces @ConversationScoped ProdService getProdService() {
                            if (reallyComplexlogic) {
                              return  allProdServices.selectStuff;
                            } else {
                              return allProdServices.selectOtherStuff;
                            }
                          }
                        



                        scoping may wary depending on where the choise is made. For mid-conversation changes, you might even want to work directly with the InstanceBean...

                        • 9. Re: What about qualifying a conversation?
                          agori

                          Yes thanks, after explosing clearly the problem I realized too that it could be job for @Produces ;).



                          • 10. Re: What about qualifying a conversation?
                            nickarls

                            Speaking of obsolete stuff, is the concept of policy also something of the past? There are plenty of refs around in the code but I didn't find anything in the specs

                            • 11. Re: What about qualifying a conversation?
                              nickarls

                              Nevermind, seems to be alternatives

                              • 12. Re: What about qualifying a conversation?
                                pmuir

                                Nicklas Karlsson wrote on Nov 20, 2009 08:05:


                                I don't know if it's functional/used, just noticed some references to it in BeanManager. And since most other obsolete stuff has been cleaned out, I assumed it's there for a reason...


                                Yup, Gavin told me to keep it in as IBM wanted it :-)