org.infinispan.factories.annotations
Annotation Type Inject


@Retention(value=RUNTIME)
@Target(value=METHOD)
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 AbstractComponentFactory.construct(Class) method, or if your object that needs components injected into it already exists, it can be built using the AbstractComponentRegistry.wireDependencies(Object) method.

Usage example:

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

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

&Inject public void injectMoreStuff(BuddyManager bm, Notifier n) { this.bm = 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.
 
Methods annotated with this Inject annotation should *only* set class fields. They should do nothing else. If you need to do some work to prepare the component for use, do it in a @Start method since this is only called once when a component starts.

Since:
4.0
Author:
Manik Surtani


Google Analytics

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