Document Information

Preface

Part I Introduction

1.  Overview

2.  Using the Tutorial Examples

Part II The Web Tier

3.  Getting Started with Web Applications

4.  JavaServerTM Faces Technology

5.  Introduction to Facelets

6.  Unified Expression Language

7.  Using JavaServerTM Faces Technology in Web Pages

8.  Using Converters, Listeners and Validators

9.  Developing With JavaServerTM Faces Technology

10.  Java Servlet Technology

Part III Web Services

11.  Introduction to Web Services

12.  Building Web Services with JAX-WS

13.  Building RESTful Web Services with JAX-RS and Jersey

Part IV Enterprise Beans

14.  Enterprise Beans

15.  Getting Started with Enterprise Beans

16.  Running the Enterprise Bean Examples

Part V Contexts and Dependency Injection for the JavaTM EE Platform

17.  Introduction to Contexts and Dependency Injection for the JavaTM EE Platform

About Beans

About Managed Beans

Beans as Injectable Objects

Using Qualifiers

Injecting Beans

Using Scopes

Giving Beans EL Names

Adding Setter and Getter Methods

Using a Managed Bean in a Facelets Page

Injecting Objects by Using Producer Methods

Configuring a CDI Application

Further Information

18.  Running the Basic Contexts and Dependency Injection Examples

Part VI Persistence

19.  Introduction to the Java Persistence API

20.  Running the Persistence Examples

21.  The Java Persistence Query Language

22.  Creating Queries Using the Criteria API

Part VII Security

23.  Introduction to Security in the Java EE Platform

24.  Getting Started Securing Enterprise Applications

25.  Getting Started Securing Web Applications

Part VIII JavaTM EE Supporting Technologies

26.  Introduction to JavaTM EE Supporting Technologies

27.  Transactions

28.  Resource Connections

Index

 

Overview of Contexts and Dependency Injection for the Java EE Platform

The two most fundamental services provided by CDI are as follows:

  • Contexts: The ability to bind the lifecycle and interactions of stateful components to well-defined but extensible lifecycle contexts

  • Dependency injection: The ability to inject components into an application in a type-safe way, including the ability to choose at deployment time which implementation of a particular interface to inject

In addition, CDI provides the following services:

  • Integration with the Unified Expression Language (EL), which allows any component to be used directly within a JavaServer Faces page (or a JavaServer PagesTM page)

  • The ability to decorate injected components

  • The ability to associate interceptors with components using type-safe interceptor bindings

  • An event notification model

  • A web conversation scope in addition to the three standard scopes (request, session, and application) defined by the Java Servlet specification

  • A complete Service Provider Interface (SPI) that allows third-party frameworks to integrate cleanly in the Java EE 6 environment

A major theme of CDI is loose coupling. CDI does the following:

  • It decouples the server and the client by means of well-defined types and qualifiers, so that the server implementation may vary.

  • It decouples the lifecycles of collaborating components by doing the following:

    • Making components contextual, with automatic lifecycle management

    • Allowing stateful components to interact like services, purely by message passing

  • It completely decouples message producers from consumers, by means of events.

  • It decouples orthogonal concerns by means of Java EE interceptors.

Along with loose coupling, CDI provides strong typing, as follows:

  • It eliminates lookup using string-based names for wiring and correlations, so that the compiler will detect typing errors.

  • It allows the use of declarative Java annotations to specify everything, largely eliminating the need for XML deployment descriptors, and making it easy to provide tools that introspect the code and understand the dependency structure at development time.