[weld-dev] Automatic non contextual injection using bytecode instrumentation

Marius Bogoevici mariusb at redhat.com
Sun Nov 14 18:08:53 EST 2010


I think it would be something nice to have. For example, Spring does this via @Configurable, backed by AspectJ. 

I think that exploring bytecode instrumentation would be interesting for Weld,and I have for some time considered the possibility of using it as an option for interception/decoration as well.

Regarding javaagent: for certain classloaders that support instrumentation and registering a ClassFileTransformer directly, we may forgo using a javaagent altogether and register the transformer during the bootstrap process. In the least, this would possible with Tomcat, Glassfish(partly) and JBoss.

On 2010-11-14, at 5:35 PM, Stuart Douglas wrote:

> I just had an idea for something that I think would be rather cool,
> and allow objects created using new 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);
> 
> To implement this will 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. Would this be something that is
> worth putting into weld extensions?
> 
> Stuart
> _______________________________________________
> weld-dev mailing list
> weld-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/weld-dev




More information about the weld-dev mailing list