-
1. Re: DI performance analysis
gavin.king Jul 8, 2009 4:04 AM (in response to asookazian)In web beans, there is no outjection (though there are producer fields), and therefore injection happens once at instantiation time.
-
2. Re: DI performance analysis
asookazian Jul 8, 2009 10:11 PM (in response to asookazian)So we have
reverted
from dynamic injection (Seam @In) to static injection like Spring? Is the performance gains from using static vs. dynamic injection the reason for this reversion? Dynamic injection is convenient for many use cases (fresh
data injection from conversation or session context, for example).from SiA book:
When you use component configuration, you’re performing static dependency injection. With static injection, Seam assigns a value to a field or property of a component instance when it’s created. The value is specified using the EL variant of component configuration. This style of injection is analogous to that used by other lightweight containers, such as Spring and the JSF managed bean facility. The assignment happens once, drawing from resources available at the time the component is instantiated. After that point, the values of the fields and properties of the component instance aren’t affected by this mechanism. What’s done is done. The properties get their shot again when a new instance is created. Seam also supports a style of dependency injection that’s dynamic. This hook is activated by placing the @In annotation above a field or JavaBean-style property “setter” method. Annotation-based injections are resolved each time a method is invoked on a component.
from the Intro to Web Beans guide:
Web Beans supports three primary mechanisms for dependency injection: Constructor parameter injection: public class Checkout { private final ShoppingCart cart; @Initializer public Checkout(ShoppingCart cart) { this.cart = cart; } } Initializer method parameter injection: public class Checkout { private ShoppingCart cart; @Initializer void setShoppingCart(ShoppingCart cart) { this.cart = cart; } } And direct field injection: public class Checkout { private @Current ShoppingCart cart; } Dependency injection always occurs when the Web Bean instance is first instantiated.
-
3. Re: DI performance analysis
pmuir Jul 20, 2009 6:01 PM (in response to asookazian)
John Jameson wrote on Jul 08, 2009 22:11:
So we havereverted
from dynamic injection (Seam @In) to static injection like Spring?Read section 5.5 in the PFD.
-
4. Re: DI performance analysis
luxspes Jul 22, 2009 11:10 PM (in response to asookazian)
Pete Muir wrote on Jul 20, 2009 18:01:
John Jameson wrote on Jul 08, 2009 22:11:
So we havereverted
from dynamic injection (Seam @In) to static injection like Spring?
Read section 5.5 in the PFD.PFD? maybe PDF? Which one? Certainly not webbeans_reference.pdf because Chapter 5 ends at 5.4
-
5. Re: DI performance analysis
luxspes Jul 22, 2009 11:27 PM (in response to asookazian)I guess you mean Proposed Final Draft ( contexts-1_0-pfd-spec.pdf ). Yes... 5.5. Dependency injection
-
6. Re: DI performance analysis
luxspes Jul 22, 2009 11:30 PM (in response to asookazian)Seems like
Contextual instances
somewhat deal with this... but I do not fully understand how.. -
7. Re: DI performance analysis
asookazian Dec 29, 2009 7:44 PM (in response to asookazian)5.5. Dependency injection From time to time the container instantiates beans and other Java EE component classes supporting injection. The resulting instance may or may not be a contextual instance as defined by Section 6.5.2, “Contextual instance of a bean. The container is required to perform dependency injection whenever it creates one of the following contextual objects: • contextual instances of session beans, and • contextual instances of managed beans. The container is also required to perform dependency injection whenever it instantiates any of the following noncontextual objects: • non-contextual instances of session beans (for example, session beans obtained by the application from JNDI or injected using @EJB), • non-contextual instances of managed beans, and • instances of any other Java EE component class supporting injection.
So like GKing stated above, the DI occurs upon bean creation/instantiation only. This is basically static injection like Spring.
But nobody answered why CDI uses static injection vs. dynamic DI like in Seam...