Version 1

    History:

     

    There's a long history of how various technologies integrated in JBoss AS were doing injection in their own separate way http://community.jboss.org/message/259825#259825.

     

    Injection in AS6:

     

    Starting AS6 a new injection mechanism has been put in place to have a single injection manager which can be used to allow various services/technologies to carry out injection in an unified way. The project is named jboss-injection. The initial requirements can be found here http://community.jboss.org/wiki/InjectionMechanism-Contracts

     

    InjectionManager API:

     

    The jboss-injection project is mainly based on the InjectionManager API which looks like this:

     

    package org.jboss.injection.manager.spi;
    
    public interface InjectionManager
    {
       <T> T inject(T instance, final Class<? super T> clazz);
    
       <T> T inject(T instance);
    
       void addInjector(Injector injector);
    
    }
    
    

     

    As can be seen, the InjectionManager allows multiple Injector(s) to be added to the manager. The Injector interface is as follows:

     

    package org.jboss.injection.manager.spi;
    
    public interface Injector
    {
       <T> void inject(InjectionContext<T> injectionContext) throws InjectionException;
    }
    
    

     

    An Injector is responsible for working with an InjectionContext. The InjectionContext interface is as follows:

     

    public interface InjectionContext<T>
    {
    
       void proceed() throws InjectionException;
    
       T getInjectionTarget();
    
       Class<? super T> getInjectedType();
    }
    
    

     

    The InjectionContext provides access to the object being injected via getInjectionTarget() method.

     

    How it works:

     

    For each Java EE component (like an EJB), there is one InjectionManager instance which manages the injection on that EJB. That single InjectionManager instance can have multiple Injector(s) (for example, an Injector responsible for doing CDI injection like @Inject, another Injector for doing the Java EE injections like @EJB). Whenever a container managed component is being instantiated, the container will invoke the inject() API on the InjectionManager and pass it the instance of the component which was instantiated. The InjectionManager will then pass on this instance to all the Injectors which have been added to that InjectionManager. This way, the InjectionManager provides a unified, yet extensible way, of carrying out injection on the Java EE components.    

     

     

    Source code:

     

    The source currently is located at https://github.com/jaikiran/jboss-injection