官术网_书友最值得收藏!

Dependency Injection Using CDI 2.0

CDI (Contexts and Dependency Injection) is one of the most essential and powerful APIs in Java EE. With CDI, you can easily divide your application into separate components interacting with each other, avoiding all the hassles of managing your components, life cycles, calling JNDI, and any other redundant programmatic work. Although the initial goal of CDI was to provide an easy mechanism for tying the web layer to the data access layer, CDI now has a broader scope of usage and implementation scenarios. Let's take an overview of the key features that CDI provides to our middleware solution:

  • DI (Dependency Injection): A popular technique for supplying components with other components they depend on. CDI provides a declarative approach for defining components and their scope of life, and of course obtaining them back. Moreover, DI in Java EE is used to easily retrieve essential platform components such as data sources, entity managers, enterprise Java beans, messaging destinations, and more.
  • Interceptors: Interceptors provide a simple mechanism for handling cross-cutting concerns in enterprise applications. Interceptors are methods that can be forced to precede the call to a set of other methods, in order to perform pre and/or post operations that are common among them, such as logging, transaction management, and more. This technique is commonly referred to by the term aspect-oriented programming.
  • Event Handling: Events are incidents that occur in our application, where one or more different objects are interested to react to. CDI provides a model for publishing events, where other objects can subscribe to those events.

In this chapter, we will learn about the amazing features that CDI provides to your applications, including:

  • Creating and using CDI beans
  • Providing different implementations to your bean
  • Understanding and using bean scopes
  • Injecting beans in other components in different ways
  • Understanding and using producers, interceptors, and events
主站蜘蛛池模板: 莎车县| 鹤岗市| 崇州市| 土默特左旗| 池州市| 公安县| 平南县| 将乐县| 金湖县| 昌宁县| 友谊县| 永和县| 象州县| 封丘县| 西安市| 万年县| 时尚| 新绛县| 桂平市| 嘉兴市| 广宗县| 遂溪县| 东乌| 博兴县| 永兴县| 石柱| 宜丰县| 潜江市| 雷波县| 天峨县| 泗水县| 乡宁县| 日照市| 体育| 临汾市| 禄丰县| 调兵山市| 精河县| 长海县| 庄河市| 西和县|