Class SessionBeanInjectionPoint


  • public class SessionBeanInjectionPoint
    extends Object

    The spec requires that an InjectionPoint of a session bean returns:

    • a Bean object representing the session bean if the session bean is a contextual instance (obtained using Inject)
    • null if the session bean is a non-contextual instance obtained using @EJB or from JNDI

    Each time a contextual instance of a session bean is created we add its bean class to a thread local collection. The class is removed from the collection after instance creation.

    If an InjectionPoint of a session bean is about to be injected using InjectionPointBean and the session bean class is present in the thread local collection (indicating that it is a contextual instance), we leave the InjectionPoint untouched and inject it. Otherwise, we wrap the InjectionPoint within SessionBeanInjectionPoint.NonContextualSessionBeanInjectionPoint which always returns null from getBean().

    The only known limitation of this approach is that if the same session bean is used both in its contextual and non-contextual form within a single dependency chain (non-contextual instance of Foo injecting another Foo instance using Inject), the behavior will not be reliable.

    Author:
    Jozef Hartinger
    • Method Detail

      • registerContextualInstance

        public static void registerContextualInstance​(org.jboss.weld.ejb.spi.EjbDescriptor<?> descriptor)
        Indicates that a contextual instance of a session bean is about to be constructed.
      • unregisterContextualInstance

        public static void unregisterContextualInstance​(org.jboss.weld.ejb.spi.EjbDescriptor<?> descriptor)
        Indicates that contextual session bean instance has been constructed.
      • wrapIfNecessary

        public static javax.enterprise.inject.spi.InjectionPoint wrapIfNecessary​(javax.enterprise.inject.spi.InjectionPoint ip)
        Returns the InjectionPoint passed in as a parameter if this InjectionPoint belongs to a contextual instance of a session bean. Otherwise, the method wraps the InjectionPoint to guarantee that getBean() always returns null.