-
1. Re: Outjection vs. Producer method
nickarls Nov 10, 2009 8:16 PM (in response to asookazian)Have a look at producer fields in the RefDoc and, yes, the specification ;-)
-
2. Re: Outjection vs. Producer method
asookazian Nov 10, 2009 8:37 PM (in response to 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 Nov 10, 2009 8:42 PM (in response to asookazian)@Produces @Inject is illegal in CDI.
-
4. Re: Outjection vs. Producer method
asookazian Nov 10, 2009 10:21 PM (in response to 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 Nov 10, 2009 10:40 PM (in response to asookazian)You can still bind to it from EL.
-
6. Re: Outjection vs. Producer method
asookazian Nov 10, 2009 10:54 PM (in response to 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 Nov 10, 2009 10:58 PM (in response to asookazian)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 Nov 10, 2009 11:02 PM (in response to asookazian)
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 Nov 10, 2009 11:16 PM (in response to 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 Nov 10, 2009 11:19 PM (in response to asookazian)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 Nov 10, 2009 11:20 PM (in response to asookazian)and contextual variables are non-typesafe. You have @Named for EL access.
-
12. Re: Outjection vs. Producer method
gavin.king Nov 10, 2009 11:25 PM (in response to asookazian)Right, you can definitely inject primitives, or have producer methods that return a primitive type.
-
13. Re: Outjection vs. Producer method
asookazian Nov 10, 2009 11:45 PM (in response to 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 Nov 11, 2009 8:07 AM (in response to asookazian)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)