JEE Context & Dependency Injection (CDI)
Purpose
provides objects
their dependencies
without
creating / initializing
receiving as parameters
manage
lifecycle
of dependencies
Services
Context
bind
stateful components
context
lifecycle & interactions
lifecycle
Dependency Injection
inject
components
to application
type-safe way
choose implementation
during deployment time
by resolving by type
additional
EL integration
use in JSP / JSF
decorate
interceptor binding
injected objects
event-notification model
scope
request
session
application
conversation (additional)
Service Provider Integration
for 3rd party frameworks
Themes
loose-coupling
strong-typing
Bean Injection
CDI Beans
source of
contextual
objects / instances
are managed by
container
Configuration
Producer Methods
define application
state / logic
qualifier
purpose
used to identify
which implementation
to inject
creation
METHOD
TYPE
FIELD
PARAMETER
RUNTIME
usage
defined using interface
dependent
scope
types
conversation
session
dependent
request
default
servlet
application
serializable
sessions,
application,
conversation
EL
to be used in JSP/JSF
class name w/
1st letter lowercase
getter / setter
to set and get the fields
of the injected bean
inject method
usage
creation
method definition
no additional configuration required
deployment descriptor
optional
beans.xml
resolved by type
injection
where the instance is being used
purpose
make managed beans
to store state
for web application
almost any class can be injected w/o annotation in declaration
Injection Process Flow for JSF page
1.) Almost any object in the application can be injected since it is done by type.
2.) qualifiers identify which implementation of the interface to inject
3.) For a web application to use beans with injected objects, the bean's definition must be:
3.1) "scoped" to properly handle the context.
3.2) "named" for use with EL.
3.3) have getter and setter to access fields.