contexts and dependency injection for java ee (cdi) magical mystery tour

16
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public 1

Upload: reza-rahman

Post on 08-May-2015

1.754 views

Category:

Technology


4 download

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

Page 1: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public1

Page 2: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

Reza RahmanJava EE/GlassFish [email protected]@reza_rahman

Page 3: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public3

Program Agenda

CDI Primer

Demo

CDI Ecosystem

Page 4: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

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

Page 5: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public5

CDI and Java EE

Page 6: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

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

Page 7: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

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!

Page 8: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

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

Page 9: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

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

Page 10: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

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

Page 11: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public11

Demo Time!

https://github.com/m-reza-rahman/cdi-tour

Page 12: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public12

CDI Ecosystem

Implementations

Weld CanDI

RuntimesPortable Extensions

Tools

Page 13: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public13

CDI Plugins

Page 14: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

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

Page 15: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1215

Page 16: Contexts and Dependency Injection for Java EE (CDI) Magical Mystery Tour

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public16