contexts and dependency injection for java ee (cdi) magical mystery tour
DESCRIPTION
This is a fast demo-driven tour of Contexts and Dependency Injection for Java EE, the new cool kid on the dependency injection block. We discuss features such as injection, automatic context management, scoping, qualifiers, naming, object factories, producers, disposers, dynamic lookup, stereotypes, interceptors, decorators and lightweight type-safe events. The relationship between this critical Java EE API covering generic dependency injection services and the rest of the platform including Dependency Injection for Java (JSR 330), managed beans, EJB 3, JSF and JPA will also be discussed.TRANSCRIPT
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public1
Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour
Reza RahmanJava EE/GlassFish [email protected]@reza_rahman
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public3
Program Agenda
CDI Primer
Demo
CDI Ecosystem
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public4
Contexts and Dependency Injectionfor Java EE (CDI)
Cool new kid on dependency injection block Synthesizes best ideas from Seam 2, Guice and Spring Many innovations on its own right Loose-coupling, Java-centric type-safety, annotations,
expressiveness and ease-of-use Makes Java EE much more flexible, testable, pluggable and
extensible Large ecosystem rapidly evolving around CDI
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public5
CDI and Java EE
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public6
CDI Features
Basic dependency injection– @Inject, @Qualifier, @Stereotype, @Alternative, @All, @Any
Component naming– @Named
Custom Object Factories– @Produces, @Disposes, InjectionPoint
Context management– @RequestScoped, @SessionScoped, @ConversationScoped,
@ApplicationScoped, @Scope
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public7
CDI Features
Lightweight Events– Event, @Observes
Interceptors/Decorators– @Interceptor, @InterceptorBinding, @AroundInvoke,
InvocationContext, @Decorator, @Delegate
Portable extensions SPI!
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public8
Weld
CDI reference implementation Weld reference excellent documentation for CDI Evolved from Seam 2 core Included in GlassFish, WebLogic and JBoss AS Can be used with Tomcat, Jetty, Java SE
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public9
OpenWebBeans
Apache implementation of CDI included in Geronimo, WebSphere Closely related to Apache OpenEJB Great integration with Tomcat along with OpenEJB (TomEE) Runs in standalone Java SE
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public10
CanDI
Caucho implementation forms core of Resin itself CanDI XML used to configure Resin Use of annotations like @TransactionAttribute, @Schedule,
@Asynchronous, @RolesAllowed, @RunAs, @Lock, @Startup and @Remote outside EJB in plain CDI managed beans
@PoolScoped, @TransactionScoped, @ThreadScoped Optimized embedded container based Test Framework CDI-PHP integration
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public11
Demo Time!
https://github.com/m-reza-rahman/cdi-tour
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public12
CDI Ecosystem
Implementations
Weld CanDI
RuntimesPortable Extensions
Tools
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public13
CDI Plugins
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public14
Resources
Contexts and Dependency Injection for Java EE, http://www.cdi-spec.org
Java EE Tutorial, http://docs.oracle.com/javaee/7/tutorial/doc/partcdi.htm
OpenWebBeans, http://openwebbeans.apache.org CanDI, http://caucho.com/projects/candi/ DeltaSpike, http://deltaspike.apache.org
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1215
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public16