Annotation Type Inject

public @interface Inject

Used to annotate a method as one that is used to inject a registered component into another component. The component to be constructed must be built using the org.jboss.cache.factories.ComponentFactory#construct(Class) method, or if your object that needs components injected into it already exists, it can be built using the org.jboss.cache.factories.ComponentFactory#wireComponents(Object) method.

Usage example:

       public class MyClass
          private TransactionManager tm;
          private BuddyManager bm;
          private Notifier n;

&Inject public void setTransactionManager(TransactionManager tm) { = tm; }

&Inject public void injectMoreStuff(BuddyManager bm, Notifier n) { = bm; this.n = n; } }

and an instance of this class can be constructed and wired using
       MyClass myClass = componentFactory.construct(MyClass.class); // instance will have dependencies injected.
If you wish to use named components, you can use the optional ComponentName annotation on each parameter.

Manik Surtani
See Also:

Copyright © 2008 JBoss, a division of Red Hat. All Rights Reserved.