Context and Dependency Injection (CDI 1.1)

Learn how to decouple and inject your components with CDI (Context and Dependency Injection) in your Java SE and Java EE applications.
Course info
Rating
(150)
Level
Intermediate
Updated
Mar 24, 2015
Duration
3h 44m
Table of contents
Description
Course info
Rating
(150)
Level
Intermediate
Updated
Mar 24, 2015
Duration
3h 44m
Description

Context and Dependency Injection takes its roots from injection frameworks and today has become a common ground for several Java EE specifications. In this course you will discover the CDI programming model and its concept of "loose coupling, strong typing." You will see that decoupling goes further by bringing interceptors and decorators to the entire platform.

About the author
About the author

Antonio is a senior software architect living in Paris.

More from the author
Java Persistence API 2.2
Intermediate
4h 15m
May 10, 2019
Microservices: The Big Picture
Beginner
1h 45m
Apr 16, 2018
Java EE: Getting Started
Beginner
5h 0m
Jun 22, 2017
More courses by Antonio Goncalves
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi everyone. My name is Antonio Goncalves. Welcome to my course Context and Dependency Injection 1. 1. I'm an independent developer, a book author, and a recognized Java Champion. I also like to speak at international conferences about various technical topics. So, you know Java EE. The project you are working on is challenging, and you feel you need for more Java EE. This course is for you. In this course, you will learn context and dependency injection, the hidden gem of Java EE. Some of the major topics that I will cover include understanding CDI, what it is, what it does, why you need it; from simple injection to using qualifiers or alternatives; producers and disposers to be able to integrate any external framework in a Java EE application; decouple your code using interceptors, decorators, and events. I will also cover how CDI can bring the web tier and the business tier together thanks to expression language binding and building scopes. Finally, you will put all these pieces together so you can take CDI to your project. By the end of this course, you'll have a very good understanding of the possibilities brought by CDI. Before beginning the course, you should be familiar with the Java programming language, have notions of Java EE, as well as a few design patterns. This course will guide you through most of the capabilities of CDI. I hope you will join me on this journey to learn how to extend your Java EE code with the Context and Dependency Injection 1. 1 course at Pluralsight.

Understanding Context and Dependency Injection
Hi, my name is Antonio Goncalves, and I want to welcome you to this module about Understanding Context and Dependency Injection. I will use this second module to show you what CDI is, what it's not, and in which layer of our applications we can use it. In this module I will recap what injection is and why we delegate these tasks to injectors, also known as containers. Then I will introduce Context and Dependency Injection, tell you what it is, what it does, but also what it's not. I'll then show in which layers of our application we can use CDI to inject objects in both Java SE and Java EE.

Injection With CDI
Hi, my name is Antonio Goncalves, and I want to welcome you to this module about Injection with CDI. A very important feature of CDI is its type-safe approach to a dependency injection. In this module, I will cover this topic by starting with basic dependency injection and show you how easy it is to inject one class or one implementation into another class. When things become more confusing and dependencies ambiguous, CDI uses qualifiers as a type-safe approach to distinguish between beans. I'll also cover more advanced qualifiers features, and we'll talk about vetoing beans from dependency injection. I'll wrap up this module by talking about alternatives and how we can switch dependencies at deployment time with some XML configuration.

Producers and Disposers
Hi, my name is Antonio Goncalves, and I want to welcome you to this fourth module that explains how CDI can be used to inject third-party frameworks. Through producers, CDI is able to create any data type so it can be managed. Thanks to disposers, you will learn how a produced bean can be destroyed. As you'll see, alternatives can also be used with perusers. Until now we've seen how CDI can inject bean into other beans that are valuable in the bean archive. The problem is that when we integrate third-party frameworks their classes are not packaged in bean archives and, therefore, are not discovered by CDI and can't be injected. But thanks to producers, CDI allows us to create any Java class and turn it into a CDI bean so it becomes managed by the container. Once managed, we can use alternatives as we saw in the previous module. Thanks to disposers, you will learn how to clean up the creation of these produced beans.

Interceptors, Decorators, and Events
Hi, my name is Antonio Goncalves and I want to welcome you to this fifth module about Interceptors, Decorators, and Events in CDI. As you know by now, CDI is all about loose coupling. We've seen how injection, with or without producers, bring loosely coupled components together. In this module, we will go even further by using interceptors. Interceptors are a way to solve the problem of cross-cutting concerns by intercepting methods invocation. Thanks to interceptor bindings, you will see how to do interception in a type safe way on methods, as well as on the CDI bean lifecycle. Decoration is similar to interception, but is applied to business concerns. I'll wrap up this module by explaining how CDI events bring even more loose coupling between observers and observables in a very easy way.

Bringing the Web Tier and Service Tier Together
Hi, my name is Antonio Goncalves, and I want to welcome you to this module about how CDI can help in simplifying the integration between the web tier and the service tier. In this module I'll start by giving you a short overview about Java EE architectural layers and the different languages used in these layers, Java and Expression Language. Then I'll explain how CDI can bring an integration between these layers. The CDI integration comes in two flavors. The first is binding. CDI can give an Expression Language name to any CDI bean, thanks to the Named annotation. The second is state Management. Thanks to scopes and contexts, a CDI bean can be valuable for a certain period of time.

CDI 1.1 Within Java EE 7
Hi, my name is Antonio Goncalves, and I want to welcome you to this last module that covers integration between CDI 1. 1 and Java EE 7. In this module I will give you a very quick overview of Java EE 7, and I will focus on the services given by the Java EE container to CDI. You will see how CDI is deeply integrated with some specifications such as Java Server Faces, transactional components, Java Persistence API, and Bean Validation. I'll finish this module with a summary of the course and will give you some extra pointers for external references.