2 Replies Latest reply on Nov 19, 2009 8:43 PM by Gavin King

    context of example in 16.4. The InjectionTarget interface

    Arbi Sookazian Master

      Regarding the code example below, is this an SE or EE context?

      //get the BeanManager from JNDI
      BeanManager beanManager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
      //CDI uses an AnnotatedType object to read the annotations of a class
      AnnotatedType<SomeFrameworkComponent> type = beanManager.createAnnotatedType(SomeFrameworkComponent.class);
      //The extension uses an InjectionTarget to delegate instantiation, dependency injection
      //and lifecycle callbacks to the CDI container
      InjectionTarget<SomeFrameworkComponent> it = beanManager.createInjectionTarget(type);
      //each instance needs its own CDI CreationalContext
      CreationalContext instanceContext = beanManager.createCreationalContext(null);
      //instantiate the framework component and inject its dependencies
      SomeFrameworkComponent instance = it.produce(instanceContext); //call the constructor
      it.inject(instance, ctx); //call initializer methods and perform field injection
      it.postConstruct(instance); //call the @PostConstruct method
      //destroy the framework component instance and clean up dependent objects
      it.preDestroy(instance); //call the @PreDestroy method
      it.dispose(instance); //it is now safe to discard the instance
      ctx.release(); //clean up dependent objects

      I'm wondering why it's doing a JNDI lookup rather than using DI to get the BeanManager instance?