Enterprise Java Development@TOPIC@

Chapter 97. CDI Injection

97.1. Producer Field
97.2. Producer Method
97.3. Other Producers
97.3.1. Example JNDI Resource Lookup Producer
97.3.2. Example String Resource Producer
97.4. @Any Instance
97.5. Bean Types
97.6. Named Beans
97.7. Summary
       public class CdiDemoConfig {

            @Produces
            @CdiDemo
            @PersistenceContext(unitName="cdi-config")-->-+
 +-<--------public EntityManager em; <--------------------+
 |  
 |      public class ProjectsDaoImpl implements ProjectsDao {
 |          private EntityManager em;
 |          
 +--------> @PersistenceContext @CdiDemo
            public void setEntityManager(EntityManager em) {
                this.em = em;
            }
            @Produces

            @CdiDemo
 +-<------  public JobsDao jobsDao(@CdiDemo EntityManager em) {
 |              JobsDaoImpl impl = new JobsDaoImpl();
 |              impl.setEntityManager(em);
 |              return impl;
 |          }
 |      
 |          @Stateless
 |          @Remote(JobsMgmtRemote.class)
 |          public class JobsMgmtEJB implements JobsMgmtRemote {
 |              @Inject @CdiDemo
 +---------->   private JobsDao jobDao;
 
        @EJB(lookup="java:app/jndiDemoEJB/CookEJB!ejava.examples.jndidemo.ejb.CookLocal")

        @Produces                                        |
        @Cook                                            |
 +---<--public Scheduler cook; <-------------------------+
 |
 |      @Stateless
 |      public class TrainSchedulerEJB 
 |      @Inject @Any
 `----> protected Instance<Scheduler> anyCook;
        protected Scheduler cook2;      |
                        +---------------+
                        v 
        cook2 = anyCook.select(new CookQualifier()).get();
public class CookQualifier extends javax.enterprise.util.AnnotationLiteral<Cook>{}
@Named

public class JPASchedulerDAOImpl extends JPADAOBase<Task> implements SchedulerDAO {
@Typed({SchedulerDAO.class, JPASchedulerDAOImpl.class})

public class JPASchedulerDAOImpl extends JPADAOBase<Task> implements SchedulerDAO {
@Named("sellerController")

@ConversationScoped
public class SellerController implements Serializable {

<h3>Sell Products (#{sellerController.seller.name})</h3>