Chapter 6. Absolute inversion of control

 

This chapter covers

  • Wiring components together dynamically
  • Applying method interceptors
  • Raising and observing component events
  • Resolving context variables on demand

Inversion of control (IoC) is a pattern in aspect-oriented programming (AOP) that espouses loose coupling, allowing the application to focus on consuming services rather than locating them. Seam embraces the use of IoC not only to “wire” components together but also to produce context variables and to enable components to communicate with one another through event notifications. Often, when people talk about IoC, they’re really talking about dependency injection (DI), one use of IoC and the primary focus of this chapter.

Dependency injection is a key concept in POJO-based development that keeps components loosely coupled. In the previous chapter, you learned how static DI can be used to establish references from a component instance to its dependent objects during instantiation. In this chapter, you’ll learn about another assembly mechanism in Seam that links a component instance to its dependencies when it’s invoked, a device known as injection. To complement injection, outjection facilitates exporting state from a component instance after the component is invoked, effectively producing context variables that can be used elsewhere in the application.

6.1. Bijection: dependency injection evolved

6.2. Dynamic dependency @In-jection

6.3. @Out-jecting context variables

6.4. Bypassing bijection

6.5. Component events

6.6. Custom method interceptors

6.7. Factory and manager components

6.8. Summary