[cdi-dev] [JBoss JIRA] Updated: (CDI-104) Support automatic dependency injection for non-managed objects

Pete Muir (JIRA) jira-events at lists.jboss.org
Wed Apr 27 06:53:18 EDT 2011


     [ https://issues.jboss.org/browse/CDI-104?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pete Muir updated CDI-104:
--------------------------

    Fix Version/s: TBD


> Support automatic dependency injection for non-managed objects
> --------------------------------------------------------------
>
>                 Key: CDI-104
>                 URL: https://issues.jboss.org/browse/CDI-104
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Beans
>    Affects Versions: 1.0
>            Reporter: Dan Allen
>             Fix For: TBD
>
>
> Allow objects created using the "new" keyword (or created by some other means) to be injected automatically. 
> Conceptually it would look something like this: 
> @AutoInject 
> public class AccountService { 
>     private final Account account; 
>     @Inject 
>     private PaymentProcessor paymentProcessor; 
>     AccountService(Account account) { 
>         this.account = account; 
>     } 
>     public void doPayment(double amount) { 
>         paymentProcessor.processPayment(account, amount); 
>     } 
> } 
> We could then create the object using new and the fields will still be injected: 
> AccountService a = new AccountService(account); 
> a.doPayment(10);
> The inverse design would also be an option. An instance of Account could be retrieved from JPA and the AccountService would be injected into it during construction.
> To implement this feature may require a javaagent, which will modify the bytecode of @AutoInject annotated classes as they are loaded, so that the constructor bytecode looks up the values to inject and sets the injected field values appropriately. (There are other options suggested in the linked thread).
> The primary use case for this feature is to support rich domain models, though the usefulness of this feature extends beyond this case, so I don't think the feature should be dismissed if you don't agree with the rich domain models design.
> The feature also brings the "new" keyword back into the picture of modern programming. You can still create objects in the classic way, but benefit from modern programming model patterns (specifically CDI).
> Spring has a similar feature in it's AOP package: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-atconfigurable

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the cdi-dev mailing list