Thursday Jul 17, 2014

Contexts and Dependency Injection for Java 2.0 (CDI 2.0)

CDI (Context and Dependency Injection) is a 'recent' specification. CDI 1.0 has been introduced in Java EE 6 and has been slightly revised (CDI 1.1) for Java EE 7. In just a few years, CDI has become a key technology for the Java EE platform. CDI is becoming increasingly important as different parts of the platform are leveraging CDI more and more (e.g. JTA 1.2 @Transactional, Beans Validation 1.1 method level validations, etc.). And it is expected that CDI adoption within Java EE will only continue to grow as, for example, some upcoming Java EE 8 specifications are considering leveraging CDI too (e.g. JMS 2.1). 

Red Hat, the CDI Specification Lead, has just submitted to the JCP a JSR proposal for CDI 2.0. CDI 2.0 would be a major evolution of the current CDI specification, with 2 main focus : Java SE support and modularity.
  • Java SE support : Define the behaviour of CDI in a pure Java SE environment. 
  • Modularity : Define a granular, modular CDI model to help other Java EE specifications to better integrate with it. This would also probably be useful when CDI will be used in a pure Java SE context.
CDI 2 will be targeted for inclusion in Java EE 8. The Java SE features of CDI 2.0 would work on Java SE 8. In terms ot timing, CDI 2.0 is aligned with the current Java EE 8 roadmap. The CDI 2.0 JSR proposal will soon be posted on the JCP site for a 2 weeks JSR review period, the JSR approval ballot should then follow. 

In the meantime, you can read the CDI 2.0 JSR proposal here and for some technical background on what CDI 2.0 might be, you should check Antoine Sabot Durand (CDI 2.0 Specification Lead) 'Forward CDI 2.0' piece.