1 2 3 Previous Next 72 Replies Latest reply on Nov 13, 2009 8:15 PM by gavin.king

    Outjection vs. Producer method

    asookazian

      referring to: http://seamframework.org/Community/UseOutjectionWisely#comment71405


      Plz provide a simple example that refactors a Seam component using @Out to a Weld component using producer method.  I noticed 'outject' keyword is not in the 299 spec.



      Provider and @Produces have nothing to do with each other. You use Provider to get instances from the injector. You use @Produces to provide instances to the injector.

      http://relation.to/Bloggers/JSR299ProposedFinalDraft2#comment12402


      Keyword 'injector' is not found in the spec...

        • 1. Re: Outjection vs. Producer method
          nickarls

          Have a look at producer fields in the RefDoc and, yes, the specification ;-)

          • 2. Re: Outjection vs. Producer method
            asookazian

            Ok, here is my attempt based on this post from Francisco:


            http://seamframework.org/Community/WebBeansRIAndEquivalentIfAnyToSMPC#comment81209


            CDI:


            public class foo {
               @Produces @ConversationScoped @Injects
               String foo;
               ...
            }



            Seam 2:


            @Name("foo")
            @Scope(ScopeType.CONVERSATION)
            public class foo {
               @In @Out
               String foo;
               ...
            }



            So are these equivalent?  Or maybe not exactly equivalent (would be if I moved @ConversationScoped to the class level for the CDI class.)


            But I'm asking in terms of injection and outjection...

            • 3. Re: Outjection vs. Producer method
              gavin.king

              @Produces @Inject is illegal in CDI.

              • 4. Re: Outjection vs. Producer method
                asookazian

                Gavin King wrote on Nov 10, 2009 20:42:


                @Produces @Inject is illegal in CDI.



                So does that mean you can't inject and outject the same field/property?  And if yes, why not?

                • 5. Re: Outjection vs. Producer method
                  nickarls

                  You can still bind to it from EL.

                  • 6. Re: Outjection vs. Producer method
                    asookazian

                    Nicklas Karlsson wrote on Nov 10, 2009 22:40:


                    You can still bind to it from EL.


                    Bind to what?  Like a method call to a getter/setter from JSF tag?  What does that have to do with simultaneous inject/outject on same field (that's now apparently illegal)?

                    • 7. Re: Outjection vs. Producer method
                      nickarls

                      Give me a usecase, what are you trying to achieve when you are injecting and outjecting on the same field.


                      (I give up for today and go to bed, just turned Wednesday...)

                      • 8. Re: Outjection vs. Producer method
                        gavin.king

                        So does that mean you can't inject and outject the same field/property?

                        You can't inject or outject period because there is nothing to inject from or outject to. There are no contextual variables in 299. There are only beans. Why are there no contextual variables? Because things don't have string-based names. It's a different model.


                        But you can do much the same things with it.

                        • 9. Re: Outjection vs. Producer method
                          asookazian

                          Gavin King wrote on Nov 10, 2009 23:02:


                          So does that mean you can't inject and outject the same field/property?

                          You can't inject or outject period because there is nothing to inject from or outject to. There are no contextual variables in 299. There are only beans. Why are there no contextual variables? Because things don't have string-based names. It's a different model.

                          But you can do much the same things with it.


                          You mean to say you can't inject and outject period with respect to non-JavaBean variables?  i.e. You can't inject or outject a String or Integer wrapper class instance in Weld?


                          public class Foo {
                             @Inject int foo;
                          }



                          the above is illegal, correct?


                          public class Foo {
                             @Inject MyBean bean;
                          }



                          the above is legal, b/c it's a bean and not a primitive?


                          so what if you actually want to inject a primitive int, then you must add that int as an instance variable and getter/setter in a JavaBean, EJB, etc. and @Inject the class instance effectively?


                          so what exactly is the advantage of removing contextual variables from this programming model?  The beans (instead of primitives or non-beans, etc.) are still residing in conversation or sesssion, etc. scopes...

                          • 10. Re: Outjection vs. Producer method
                            nickarls
                            A bean type may be a primitive type. Primitive types are considered to be identical to their corresponding wrapper
                            types in java.lang.

                            • 11. Re: Outjection vs. Producer method
                              nickarls

                              and contextual variables are non-typesafe. You have @Named for EL access.

                              • 12. Re: Outjection vs. Producer method
                                gavin.king

                                Right, you can definitely inject primitives, or have producer methods that return a primitive type.

                                • 13. Re: Outjection vs. Producer method
                                  asookazian

                                  Sorry, but now I'm really confused.  Why did GKing state this?:



                                  You can't inject or outject period because there is nothing to inject from or outject to.

                                  So what is it exactly that you can't inject or outject?


                                  B/c apparently you can inject primitives and beans.  ok.......


                                  No contextual variables in 299.  Ok, but you can inject primitives and beans.


                                  So the from/to concept from Seam is gone.  And replaced with what?

                                  • 14. Re: Outjection vs. Producer method
                                    nickarls

                                    It is obviously a bit strong to say that CDI doesn't have injection ;-)


                                    But the Seam way was that @Name made something a bean and that name was the handle to the bean. This handle could be mapped in any context (even multiple contexts) and changed (outjected) when methods executed.


                                    The Weld way is that the Bean scope is king (no pun intended). A bean either doesn't exist (in that scope) and one will be created on first reference or it exists (in that scope) and that instance will be fetched when referenced. So it's kind of pull-only.


                                    Theoretically, Weld could be implemented with one single data structure for the context scope (as long as you keep track of the lifecycle somewhere else and ignore BeanMap quirks, but you get the point)

                                    1 2 3 Previous Next