The CDI specification enhances the EJB component model with contextual life cycle management.
The EJB specification defines a programming model for application components that access transactional resources in a multi-user environment. Concerns, such as role-based security, transaction demarcation, concurrency, and scalability are specified declaratively using annotations and XML deployment descriptors that are enforced by the EJB container at run time. EJB components might be stateful, but are not by nature, contextual.
The WebSphere® Application Server CDI container performs dependency injection on all session and message-driven bean instances, even instances that are not contextual instances. WebSphere Application Server CDI supports injection of CDI beans inside enterprise beans and vice versa.
Define producers making the EJB available for non-contextual injection:
@Produces @EJB PaymentService paymentService;
@Inject PaymentService myPaymentService
WebSphere Application Server supports failover (activation and passivation) of CDI beans and enterprise beans, along with their interceptors and decorators. EJB failover support with CDI only works for stateful session beans and requires the same configuration as stateful session bean failover. See the stateful session bean failover for the EJB container topic for more information. Configure EJB failover with web HTTP session failover. See the "Configuring for database session persistence" and the "Configuring memory-to-memory replication for the peer-to-peer mode (default memory-to-memory replication)" topics for more information. Except for abstract decorators, failover services are based on currentWebSphere Application Server failover providers. Web session failover and EJB stateful session bean failover and configured separately.
When a contextual (@Injected) instance of an EJB container is destroyed as a result of going out of scope, and if the underlying EJB container was not already removed by direct invocation of a remove method by the application, the WebSphere Application Server CDI container removes the stateful session bean.You must also consider the scope and state propagation of CDI beans. The request and application scope CDI beans maintain state in their respective contexts across the web and EJB containers. For instance, a request-scoped CDI bean injected in a servlet holds its state when a business method on stateful session enterprise bean accesses the same request-scoped bean.