SlideShare une entreprise Scribd logo
1  sur  41
The future of
Enterprise Dependency
       Injection
       Paul Bakker
Outline


•   The history of JSR-299
•   JSR-299 dependency injection
•   Contextual components
•   Conversations
•   Producers
About me


  Paul Bakker
• Trainer Info Support            Hibernat
                         EJB 3
                                  e
• NLJUG speaker          JSF
                                  Flex
• Java Magazine author   Seam
                                  Groovy
                         JavaFX
                                  Grails
                         Spring
History



          WebBeans
History



Contexts & Dependency Injection
            WebBeans
for the Java EE platform
History



          Contexts & Dependency Injection
                      WebBeans
          for the Java EE platform



JSR-330                  JSR-299
Dependency        Uses   Contexts & Dependency
Injection for            Injection for the Java EE
Java                     platform
        Java SE                              Java EE
JSR-330


• Standardized dependency injection for Java SE
    –maximize reusability, testability and
     maintainability
•   Bob Lee and Rod Johnson
•   Specifies annotations and use of annotations
•   Does NOT specify a container
•   JSR-299 uses JSR-330 annotations
JSR-330 annotations

• @Inject
• @Qualifier
• @Named
  –String based qualifier
• @Scope
• @Singleton
  –singleton scope
• Provider<T>
  –provides instances of T
JSR-299


• Type safe Dependency Injection for Java EE
  components
• Lifecycle aware
  –EE components often have a scope/context
  –i.e. request scoped JSF managed bean
• Integration with the Unified Expression
  Language
• Additional services
  –i.e. event notification, decoration and interceptors
Implementations


• Reference Implementation:
  –WebBeans
• First alternative implementation
  –Apache OpenWebBeans
  –ASL-Licenced
  –aims to provide a new set of WebBeans
   components of other Apache projects
Implementations


• Reference Implementation:
  –WebBeans Weld
• First alternative implementation
  –Apache OpenWebBeans
  –ASL-Licenced
  –aims to provide a new set of WebBeans
   components of other Apache projects
Exposes bean to EL
Bean valid for this request
Inject instance of Greeter
An instance will be created
by the container, and bound
to request scope
The Greeter class


• The Greeter is a simple POJO
The Greeter class

• But could have been a EJB Session Bean...
Types of injection


     Field injection



Constructor injection




  Setter injection
Types of injection


     Field injection



Constructor injection




  Setter injection
Where can I use CDI?


• Inject into:
  –every POJO
  –every EJB Session Bean
  –every Servlet
• Injectable types:
  –every POJO
  –every EJB Session Bean
  –JEE Resources (e.g. a DataSource)
Stereotypes

• Declare common meta data in a new annotation
 –@Model is a standard stereotype
Qualifiers


• An interface could have multiple
  implementations
  –the container must choose an implementation
• Add a qualifier (another annotation) to each
  implementation
  –the container chooses the correct implementation
Qualifiers
Qualifiers

  Self written qualifier annotation




   Self written qualifier annotation
Qualifiers
Qualifiers




No compile-time
   coupling
Scopes

• In a web application, an object always has a
  scope (e.g. Request or Session scope)
• CDI is context/scope aware
  –injection is scope sensitive
  –instances may be shared by injection points
  –container cleans up
• Scopes: Request, Session, Conversation,
  Application
• Default scope: @Dependent
  –never shared, bound to lifecycle of injection point
Default Scope


@Dependent              @Dependent
MyClass                 MyClass


       @Inject                 @Inject



Request                 Request
scoped                  scoped
bean ‘A’                bean ‘B’


             request
Request Scope



           @RequestScoped             @RequestScoped
           MyClass                    MyClass


@Inject                     @Inject           @Inject


Request          Request               Request
scoped           scoped                scoped
bean ‘A’         bean ‘B’              bean ‘A’


            request 1                  request 2
Session Scope



                       @SessionScoped
                       MyClass



@Inject                      @Inject     @Inject



Request         Request                 Request
scoped          scoped                  scoped
bean ‘A’        bean ‘B’                bean ‘A’


           request 1                    request 2
Conversation scope


      • Multi-request scope within a session
      • Isolated from other conversations
      • Defined begin and end point

      browser tab 2
                       find room   book room      step 2   confirm

browser tab 1
                 find room   book room   step 2     confirm



    Login                                                          Logout
Conversations example


Conversational bean



    Upgrade to
    long-running


    Schedule end of
    conversation at
    end of request
Producer methods


• A source of injectable objects
  –objects are not required to be beans (e.g. a List)
  –concrete type varies at runtime
  –objects require extra initialization
• Most similar to a traditional Factory Method
  –but more loosely coupled
Producer methods
Producer methods
Producer methods



Exposed to EL
Producer methods



          Put in Application Scope
Producer methods



                   Custom qualifier
Using CDI



• CDI is part of JEE 6
  –Every JEE 6 app server must be CDI compatible
  –GlassFish V3 and JBoss 5.2 bundled with Weld
• Weld can be installed on Tomcat or Jetty
The verdict

 Pros
• Finally a decent DI
  framework
• Makes extreme loose
  coupling possible

 Cons
• Can code be too
  decoupled?
• Where did my instance
  come from?
More about this

• January 11: Season Class
• Bert Ertman & Paul Bakker
More about this

• January 11: Season Class
  –JSF 2.0
  –Servlet 3.0
  –EJB 3.1 (lite)
  –JPA 2.0
  –Contexts & DI
  –JAX-RS
  –JavaFX

Contenu connexe

Similaire à The Future of Enterprise Dependency Injection

Spring - CDI Interop
Spring - CDI InteropSpring - CDI Interop
Spring - CDI InteropRay Ploski
 
Spring framework
Spring frameworkSpring framework
Spring frameworkAircon Chen
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologySimon Ritter
 
Spring framework
Spring frameworkSpring framework
Spring frameworkAjit Koti
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Rohit Kelapure
 
CUST-9 Spring Config for Alfresco Developers
CUST-9 Spring Config for Alfresco DevelopersCUST-9 Spring Config for Alfresco Developers
CUST-9 Spring Config for Alfresco DevelopersAlfresco Software
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansPawanMM
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Hitesh-Java
 
Java EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseConJava EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseConLudovic Champenois
 
Best Java Online Training in India
Best Java Online Training in IndiaBest Java Online Training in India
Best Java Online Training in IndiaNagendra Kumar
 
Ejb3.1 for the starter
Ejb3.1 for the starterEjb3.1 for the starter
Ejb3.1 for the startershohancse
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionKelum Senanayake
 
API Testing with Open Source Code and Cucumber
API Testing with Open Source Code and CucumberAPI Testing with Open Source Code and Cucumber
API Testing with Open Source Code and CucumberSmartBear
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfBruceLee275640
 
Top spring interview question and answer
Top spring interview question and answerTop spring interview question and answer
Top spring interview question and answerJasmeet Kaur
 

Similaire à The Future of Enterprise Dependency Injection (20)

Unit4wt
Unit4wtUnit4wt
Unit4wt
 
Unit4wt
Unit4wtUnit4wt
Unit4wt
 
Spring - CDI Interop
Spring - CDI InteropSpring - CDI Interop
Spring - CDI Interop
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010
 
Spring session
Spring sessionSpring session
Spring session
 
CUST-9 Spring Config for Alfresco Developers
CUST-9 Spring Config for Alfresco DevelopersCUST-9 Spring Config for Alfresco Developers
CUST-9 Spring Config for Alfresco Developers
 
Java Online Training
Java Online TrainingJava Online Training
Java Online Training
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI Beans
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
Java Online Training
Java Online TrainingJava Online Training
Java Online Training
 
Java EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseConJava EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseCon
 
Best Java Online Training in India
Best Java Online Training in IndiaBest Java Online Training in India
Best Java Online Training in India
 
Ejb3.1 for the starter
Ejb3.1 for the starterEjb3.1 for the starter
Ejb3.1 for the starter
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
 
API Testing with Open Source Code and Cucumber
API Testing with Open Source Code and CucumberAPI Testing with Open Source Code and Cucumber
API Testing with Open Source Code and Cucumber
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdf
 
Top spring interview question and answer
Top spring interview question and answerTop spring interview question and answer
Top spring interview question and answer
 

Dernier

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Dernier (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

The Future of Enterprise Dependency Injection

  • 1. The future of Enterprise Dependency Injection Paul Bakker
  • 2. Outline • The history of JSR-299 • JSR-299 dependency injection • Contextual components • Conversations • Producers
  • 3. About me Paul Bakker • Trainer Info Support Hibernat EJB 3 e • NLJUG speaker JSF Flex • Java Magazine author Seam Groovy JavaFX Grails Spring
  • 4. History WebBeans
  • 5. History Contexts & Dependency Injection WebBeans for the Java EE platform
  • 6. History Contexts & Dependency Injection WebBeans for the Java EE platform JSR-330 JSR-299 Dependency Uses Contexts & Dependency Injection for Injection for the Java EE Java platform Java SE Java EE
  • 7. JSR-330 • Standardized dependency injection for Java SE –maximize reusability, testability and maintainability • Bob Lee and Rod Johnson • Specifies annotations and use of annotations • Does NOT specify a container • JSR-299 uses JSR-330 annotations
  • 8. JSR-330 annotations • @Inject • @Qualifier • @Named –String based qualifier • @Scope • @Singleton –singleton scope • Provider<T> –provides instances of T
  • 9. JSR-299 • Type safe Dependency Injection for Java EE components • Lifecycle aware –EE components often have a scope/context –i.e. request scoped JSF managed bean • Integration with the Unified Expression Language • Additional services –i.e. event notification, decoration and interceptors
  • 10. Implementations • Reference Implementation: –WebBeans • First alternative implementation –Apache OpenWebBeans –ASL-Licenced –aims to provide a new set of WebBeans components of other Apache projects
  • 11. Implementations • Reference Implementation: –WebBeans Weld • First alternative implementation –Apache OpenWebBeans –ASL-Licenced –aims to provide a new set of WebBeans components of other Apache projects
  • 13. Bean valid for this request
  • 14. Inject instance of Greeter An instance will be created by the container, and bound to request scope
  • 15. The Greeter class • The Greeter is a simple POJO
  • 16. The Greeter class • But could have been a EJB Session Bean...
  • 17. Types of injection Field injection Constructor injection Setter injection
  • 18. Types of injection Field injection Constructor injection Setter injection
  • 19. Where can I use CDI? • Inject into: –every POJO –every EJB Session Bean –every Servlet • Injectable types: –every POJO –every EJB Session Bean –JEE Resources (e.g. a DataSource)
  • 20. Stereotypes • Declare common meta data in a new annotation –@Model is a standard stereotype
  • 21. Qualifiers • An interface could have multiple implementations –the container must choose an implementation • Add a qualifier (another annotation) to each implementation –the container chooses the correct implementation
  • 23. Qualifiers Self written qualifier annotation Self written qualifier annotation
  • 26. Scopes • In a web application, an object always has a scope (e.g. Request or Session scope) • CDI is context/scope aware –injection is scope sensitive –instances may be shared by injection points –container cleans up • Scopes: Request, Session, Conversation, Application • Default scope: @Dependent –never shared, bound to lifecycle of injection point
  • 27. Default Scope @Dependent @Dependent MyClass MyClass @Inject @Inject Request Request scoped scoped bean ‘A’ bean ‘B’ request
  • 28. Request Scope @RequestScoped @RequestScoped MyClass MyClass @Inject @Inject @Inject Request Request Request scoped scoped scoped bean ‘A’ bean ‘B’ bean ‘A’ request 1 request 2
  • 29. Session Scope @SessionScoped MyClass @Inject @Inject @Inject Request Request Request scoped scoped scoped bean ‘A’ bean ‘B’ bean ‘A’ request 1 request 2
  • 30. Conversation scope • Multi-request scope within a session • Isolated from other conversations • Defined begin and end point browser tab 2 find room book room step 2 confirm browser tab 1 find room book room step 2 confirm Login Logout
  • 31. Conversations example Conversational bean Upgrade to long-running Schedule end of conversation at end of request
  • 32. Producer methods • A source of injectable objects –objects are not required to be beans (e.g. a List) –concrete type varies at runtime –objects require extra initialization • Most similar to a traditional Factory Method –but more loosely coupled
  • 36. Producer methods Put in Application Scope
  • 37. Producer methods Custom qualifier
  • 38. Using CDI • CDI is part of JEE 6 –Every JEE 6 app server must be CDI compatible –GlassFish V3 and JBoss 5.2 bundled with Weld • Weld can be installed on Tomcat or Jetty
  • 39. The verdict Pros • Finally a decent DI framework • Makes extreme loose coupling possible Cons • Can code be too decoupled? • Where did my instance come from?
  • 40. More about this • January 11: Season Class • Bert Ertman & Paul Bakker
  • 41. More about this • January 11: Season Class –JSF 2.0 –Servlet 3.0 –EJB 3.1 (lite) –JPA 2.0 –Contexts & DI –JAX-RS –JavaFX