02 Mar 2015
We have seen how to inject cdi beans by using [qualifiers] and [producers] so far. Additionally, every cdi bean has a lifecycle, and we can initialize and prepare to destroy any managed bean by using two common annotations;
@PreDestroy. Methods annotated with these annotations are called bean lifecycle callbacks.
23 Feb 2015
Enums (Enumeration) are introduced as a new reference type in Java 1.5 with a bunch of beneficial features. They consist of fix set of constants (each constant is implicitly labeled as
public static final) which each constant can have a data-set. Lets see the simplest example of an Enum;
16 Feb 2015
In this tutorial we will see how to use producer methods for injecting CDI beans by
@Produces annotation. We will use Weld CDI implementation.
Using producer methods provides a programmatic way to solve disambiguation by using injection
points. We have already seen how to solve disambiguation by using qualifiers in this
As a first step, we will create a disambiguation.
21 Jan 2015
Adapter design pattern is a structural design pattern that provides two unrelated interfaces to work together. The most common illustration about adapter design pattern is sockets from different countries. Well most of us faced with laptop adapter issues when traveling, and looked for appropriate adapter for our laptops. So, by using an adapter we are able to plug our laptop chargers to sockets. Or using a card reader to plug our memory card from our camera to our computer. Thus, we make two unrelated interfaces to work together. The elements of adapter design pattern are Client, Target, Adapter and Adaptee. We can see the Gang of Four definition for ADP, and description of each element of it below;
Convert the interface of class into another interface clients expect.Adapter lets class work together that couldn’t otherwise because of incompatible interfaces.
03 Jan 2015
As I described in my previous [post], we can define and inject cdi beans by
@Named annotation. Well according to the CDI specification (JSR-299) injecting beans by their names is legacy and tend to cause issues (if a bean is tried to be injected by an undefined/wrong name then we will get errors which are hard to find). Thus, we are going to create different annotations (qualifiers) to inject different type of beans from same interface. Moreover, we will use Weld CDI implementation.