Weld 3.0.2.Final - CDI Reference Implementation CDI: Contexts and Dependency In- jection for the Java EE platform by Gavin King, Pete Muir, Jozef Hartinger, Martin Kouba, Dan Allen, and David Allen and thanks to Nicola Benaglia, Gladys Guerrero, Eun- Ju Ki,, Terry Chuang, Francesco Milesi, and Sean Wu A note about naming and nomenclature ............................................................................. ix I. Beans ............................................................................................................................ 1 1. Introduction ......................................................................................................... 5 1.1. What is a bean? ......................................................................................... 5 1.2. Getting our feet wet .................................................................................... 5 2. More about beans ................................................................................................ 9 2.1. The anatomy of a bean ............................................................................. 10 2.1.1. Bean types, qualifiers and dependency injection ............................... 10 2.1.2. Scope ............................................................................................ 13 2.1.3. EL name ........................................................................................ 13 2.1.4. Alternatives .................................................................................... 14 2.1.5. Interceptor binding types ................................................................. 14 2.2. What kinds of classes are beans? ............................................................. 16 2.2.1. Managed beans ............................................................................. 16 2.2.2. Session beans ............................................................................... 17 2.2.3. Producer methods .......................................................................... 18 2.2.4. Producer fields ............................................................................... 20 3. JSF web application example ............................................................................ 21 4. Dependency injection and programmatic lookup ............................................... 25 4.1. Injection points .......................................................................................... 25 4.2. What gets injected .................................................................................... 27 4.3. Qualifier annotations ................................................................................. 27 4.4. The built-in qualifiers @Default and @Any .................................................. 29 4.5. Qualifiers with members ............................................................................ 29 4.6. Multiple qualifiers ...................................................................................... 30 4.7. Alternatives ............................................................................................... 31 4.8. Fixing unsatisfied and ambiguous dependencies ......................................... 32 4.9. Client proxies ............................................................................................ 33 4.10. Obtaining a contextual instance by programmatic lookup ........................... 34 4.10.1. Enhanced version of javax.enterprise.inject.Instance ....................... 35 4.11. The InjectionPoint object ......................................................................... 37 5. Scopes and contexts ......................................................................................... 41 5.1. Scope types ............................................................................................. 41 5.2. Built-in scopes .......................................................................................... 42 5.3. The conversation scope ............................................................................ 42 5.3.1. Conversation demarcation .............................................................. 43 5.3.2. Conversation propagation ............................................................... 44 5.3.3. Conversation timeout ...................................................................... 45 5.3.4. CDI Conversation filter ................................................................... 45 5.3.5. Lazy and eager conversation context initialization ............................. 46 5.4. The singleton pseudo-scope ...................................................................... 47 5.5. The dependent pseudo-scope .................................................................... 48 II. Getting Start with Weld, the CDI Reference Implementation ........................................... 51 6. Getting started with Weld .................................................................................. 53 iii Weld 3.0.2.Final - CDI Refere... 6.1. Prerequisites ............................................................................................. 53 6.2. First try .................................................................................................... 53 6.3. Deploying to WildFly ................................................................................. 54 6.4. Deploying to GlassFish ............................................................................. 56 6.5. Deploying to Apache Tomcat ..................................................................... 56 7. Diving into the Weld examples .......................................................................... 59 7.1. The numberguess example in depth .......................................................... 59 7.1.1. The numberguess example in Apache Tomcat or Jetty ...................... 64 7.2. The numberguess example for Java SE with Swing .................................... 65 7.2.1. Creating the Eclipse project ............................................................ 65 7.2.2. Running the example from Eclipse .................................................. 66 7.2.3. Running the example from the command line ................................... 68 7.2.4. Understanding the code .................................................................. 68 7.3. The translator example in depth ................................................................. 74 III. Loose coupling with strong typing ................................................................................ 79 8. Producer methods ............................................................................................. 81 8.1. Scope of a producer method ..................................................................... 82 8.2. Injection into producer methods ................................................................. 82 8.3. Disposer methods ..................................................................................... 83 9. Interceptors ........................................................................................................ 85 9.1. Interceptor bindings ................................................................................... 85 9.2. Implementing interceptors .......................................................................... 86 9.3. Enabling interceptors ................................................................................. 87 9.4. Interceptor bindings with members ............................................................. 88 9.5. Multiple interceptor binding annotations ...................................................... 89 9.6. Interceptor binding type inheritance ............................................................ 90 9.7. Use of @Interceptors ................................................................................ 90 9.8. Enhanced version of javax.interceptor.InvocationContext ............................. 91 10. public void afterPersonalBlogUpdate(@Observes @Updated @Personal @Blog Document document) { … } ...................................................................... 105 10.1. Transactional observers ......................................................................... 105 10.2. Enhanced version of javax.enterprise.event.Event ................................... 107 11. Stereotypes .................................................................................................... 109 11.1. Default scope for a stereotype ............................................................... 109 11.2. Interceptor bindings for stereotypes ........................................................ 110 11.3. Name defaulting with stereotypes ........................................................... 110 11.4. Alternative stereotypes .......................................................................... 111 11.5. Stereotype stacking ............................................................................... 111 11.6. Built-in stereotypes ................................................................................ 112 12. Specialization, inheritance and alternatives ................................................... 113 12.1. Using alternative stereotypes ................................................................. 113 12.2. A minor problem with alternatives ........................................................... 115 12.3. Using specialization ..............................................................................
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages226 Page
-
File Size-