Contexts and Dependency Injection for the Java EE platform

CDI 1.1 Expert Group

Pete Muir

CDI 1.1 Specification Lead
Red Hat Middleware, LLC

CDI 1.0 Expert Group

Gavin King

CDI 1.0 Specification Lead
Red Hat Middleware, LLC

CDI 1.1 Working Draft

08 November 2012


Table of Contents

Evaluation license
Foreword
1. Major changes
1.1. 1.1 Early Draft Review
1.2. 1.1 Public Review Draft
2. Open issues
2.1. Bean visibility
2.2. @ApplicationScoped beans shared between all EAR modules
2.3. Startup event
2.4. @WithAnnotations
2.5. Allowing arrays as qualifier members
2.6. Restricting what CDI scans
2.7. Observer resolution
1. Architecture
1.1. Contracts
1.2. Relationship to other specifications
1.2.1. Relationship to the Java EE platform specification
1.2.2. Relationship to EJB
1.2.3. Relationship to managed beans
1.2.4. Relationship to Dependency Injection for Java
1.2.5. Relationship to Java Interceptors
1.2.6. Relationship to JSF
1.2.7. Relationship to Bean Validation
1.3. Introductory examples
1.3.1. JSF example
1.3.2. EJB example
1.3.3. Java EE component environment example
1.3.4. Event example
1.3.5. Injection point metadata example
1.3.6. Interceptor example
1.3.7. Decorator example
2. Concepts
2.1. Functionality provided by the container to the bean
2.2. Bean types
2.2.1. Legal bean types
2.2.2. Restricting the bean types of a bean
2.2.3. Typecasting between bean types
2.3. Qualifiers
2.3.1. Built-in qualifier types
2.3.2. Defining new qualifier types
2.3.3. Declaring the qualifiers of a bean
2.3.4. Specifying qualifiers of an injected field
2.3.5. Specifying qualifiers of a method or constructor parameter
2.4. Scopes
2.4.1. Built-in scope types
2.4.2. Defining new scope types
2.4.3. Declaring the bean scope
2.4.4. Default scope
2.5. Bean names
2.5.1. Declaring the bean name
2.5.2. Default bean names
2.5.3. Beans with no name
2.6. Alternatives
2.6.1. Declaring an alternative
2.7. Stereotypes
2.7.1. Defining new stereotypes
2.7.1.1. Declaring the default scope for a stereotype
2.7.1.2. Specifying interceptor bindings for a stereotype
2.7.1.3. Declaring a @Named stereotype
2.7.1.4. Declaring an @Alternative stereotype
2.7.1.5. Stereotypes with additional stereotypes
2.7.2. Declaring the stereotypes for a bean
2.7.3. Built-in stereotypes
2.8. Problems detected automatically by the container
2.9. Priority ordering
3. Programming model
3.1. Managed beans
3.1.1. Which Java classes are managed beans?
3.1.2. Bean types of a managed bean
3.1.3. Declaring a managed bean
3.1.4. Specializing a managed bean
3.1.5. Default bean name for a managed bean
3.2. Session beans
3.2.1. EJB remove methods of session beans
3.2.2. Bean types of a session bean
3.2.3. Declaring a session bean
3.2.4. Specializing a session bean
3.2.5. Default bean name for a session bean
3.3. Producer methods
3.3.1. Bean types of a producer method
3.3.2. Declaring a producer method
3.3.3. Specializing a producer method
3.3.4. Default bean name for a producer method
3.4. Producer fields
3.4.1. Bean types of a producer field
3.4.2. Declaring a producer field
3.4.3. Default bean name for a producer field
3.5. Disposer methods
3.5.1. Disposed parameter of a disposer method
3.5.2. Declaring a disposer method
3.5.3. Disposer method resolution
3.6. Resources
3.6.1. Declaring a resource
3.6.2. Bean types of a resource
3.7. Additional built-in beans
3.8. Bean constructors
3.8.1. Declaring a bean constructor
3.9. Injected fields
3.9.1. Declaring an injected field
3.10. Initializer methods
3.10.1. Declaring an initializer method
3.11. The default qualifier at injection points
3.12. Vetoing types
3.13. The qualifier @Named at injection points
3.14. @New qualified beans
3.15. Unproxyable bean types
4. Inheritance and specialization
4.1. Inheritance of type-level metadata
4.2. Inheritance of member-level metadata
4.3. Specialization
4.3.1. Direct and indirect specialization
5. Dependency injection, lookup and EL
5.1. Modularity
5.1.1. Declaring selected alternatives for a bean archive
5.1.2. Enabled and disabled beans
5.1.3. Inconsistent specialization
5.1.4. Inter-module injection
5.2. Typesafe resolution
5.2.1. Performing typesafe resolution
5.2.2. Unsatisfied and ambiguous dependencies
5.2.3. Legal injection point types
5.2.4. Assignability of raw and parameterized types
5.2.5. Primitive types and null values
5.2.6. Qualifier annotations with members
5.2.7. Multiple qualifiers
5.3. EL name resolution
5.3.1. Ambiguous EL names
5.4. Client proxies
5.4.1. Client proxy invocation
5.5. Dependency injection
5.5.1. Injection using the bean constructor
5.5.2. Injection of fields and initializer methods
5.5.3. Destruction of dependent objects
5.5.4. Invocation of producer or disposer methods
5.5.5. Access to producer field values
5.5.6. Invocation of observer methods
5.5.7. Injection point metadata
5.5.8. Bean metadata
5.6. Programmatic lookup
5.6.1. The Instance interface
5.6.2. The built-in Instance
5.6.3. Using AnnotationLiteral and TypeLiteral
6. Scopes and contexts
6.1. The Contextual interface
6.1.1. The CreationalContext interface
6.2. The Context interface
6.3. Normal scopes and pseudo-scopes
6.4. Dependent pseudo-scope
6.4.1. Dependent objects
6.4.2. Destruction of objects with scope @Dependent
6.4.3. Dependent pseudo-scope and Unified EL
6.5. Contextual instances and contextual references
6.5.1. The active context object for a scope
6.5.2. Contextual instance of a bean
6.5.3. Contextual reference for a bean
6.5.4. Contextual reference validity
6.5.5. Injectable references
6.5.6. Injectable reference validity
6.6. Passivation and passivating scopes
6.6.1. Passivation capable beans
6.6.2. Passivation capable dependencies
6.6.3. Passivating scopes
6.6.4. Validation of passivation capable beans and dependencies
6.7. Context management for built-in scopes
6.7.1. Request context lifecycle
6.7.2. Session context lifecycle
6.7.3. Application context lifecycle
6.7.4. Conversation context lifecycle
6.7.5. The Conversation interface
7. Lifecycle of contextual instances
7.1. Restriction upon bean instantiation
7.2. Container invocations and interception
7.3. Lifecycle of contextual instances
7.3.1. Lifecycle of managed beans
7.3.2. Lifecycle of stateful session beans
7.3.3. Lifecycle of stateless session and singleton beans
7.3.4. Lifecycle of producer methods
7.3.5. Lifecycle of producer fields
7.3.6. Lifecycle of resources
8. Decorators
8.1. Decorator beans
8.1.1. Declaring a decorator
8.1.2. Decorator delegate injection points
8.1.3. Decorated types of a decorator
8.2. Decorator enablement and ordering
8.3. Decorator resolution
8.3.1. Assignability of raw and parameterized types for delegate injection points
8.4. Decorator invocation
9. Interceptor bindings
9.1. Interceptor binding types
9.1.1. Interceptor binding types with additional interceptor bindings
9.1.2. Interceptor bindings for stereotypes
9.2. Declaring the interceptor bindings of an interceptor
9.3. Binding an interceptor to a bean
9.4. Interceptor enablement and ordering
9.5. Interceptor resolution
9.5.1. Interceptors with multiple bindings
9.5.2. Interceptor binding types with members
10. Events
10.1. Event types and qualifier types
10.2. Observer resolution
10.2.1. Assignability of type variables, raw and parameterized types
10.2.2. Event qualifier types with members
10.2.3. Multiple event qualifiers
10.3. Firing events
10.3.1. The Event interface
10.3.2. The built-in Event
10.4. Observer methods
10.4.1. Event parameter of an observer method
10.4.2. Declaring an observer method
10.4.3. Conditional observer methods
10.4.4. Transactional observer methods
10.5. Observer notification
10.5.1. Observer method invocation context
11. Portable extensions
11.1. The Bean interface
11.1.1. The Decorator interface
11.1.2. The Interceptor interface
11.1.3. The ObserverMethod interface
11.2. The Producer and InjectionTarget interfaces
11.3. The BeanManager object
11.3.1. Obtaining a reference to the CDI container
11.3.2. Obtaining a contextual reference for a bean
11.3.3. Obtaining an injectable reference
11.3.4. Obtaining a CreationalContext
11.3.5. Obtaining a Bean by type
11.3.6. Obtaining a Bean by name
11.3.7. Obtaining a passivation capable bean by identifier
11.3.8. Resolving an ambiguous dependency
11.3.9. Validating an injection point
11.3.10. Firing an event
11.3.11. Observer method resolution
11.3.12. Decorator resolution
11.3.13. Interceptor resolution
11.3.14. Determining if an annotation is a qualifier type, scope type, stereotype or interceptor binding type
11.3.15. Determining the hash code and equivalence of qualifiers and interceptor bindings
11.3.16. Obtaining the active Context for a scope
11.3.17. Obtaining the ELResolver
11.3.18. Wrapping a Unified EL ExpressionFactory
11.3.19. Obtaining an AnnotatedType for a class
11.3.20. Obtaining an InjectionTarget for a class
11.3.21. Obtaining a Producer for a field or method
11.3.22. Obtaining an InjectionPoint
11.3.23. Obtaining a BeanAttributes
11.3.24. Obtaining a Bean
11.3.25. Obtaining the instance of an Extension
11.4. Alternative metadata sources
11.5. Container lifecycle events
11.5.1. BeforeBeanDiscovery event
11.5.2. AfterBeanDiscovery event
11.5.3. AfterDeploymentValidation event
11.5.4. BeforeShutdown event
11.5.5. ProcessModule event
11.5.6. ProcessAnnotatedType event
11.5.7. ProcessInjectionPoint event
11.5.8. ProcessInjectionTarget event
11.5.9. ProcessProducer event
11.5.10. ProcessBeanAttributes event
11.5.11. ProcessBean event
11.5.12. ProcessObserverMethod event
12. Packaging and deployment
12.1. Bean archives
12.2. Application initialization lifecycle
12.3. Application shutdown lifecycle
12.4. Bean discovery
12.5. Integration with Unified EL