Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

JBoss Weld CDI for Java Platform

DZone's Guide to

JBoss Weld CDI for Java Platform

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

CDI stands for Context and Dependency Injection and is the standardization of the process of dependency injection for Java EE. This article presents some of my comments and observations when reading “JBoss Weld CDI for Java Platform” which covers everything you need to successfully implement the new standard in your Java EE application.

Recently - due to my current job - I mainly deal with the .Net technology stack and JavaScript frontend development. Several years have elapsed when I last hacked on a Java EE setup. At that time it was when I first got in touch with concepts like IoC and aspect-oriented programming style with interceptors using the Spring framework. As such it was particularly interesting to go through a Java book again.

The book setup is very clear and well structured. I like how it slowly introduces you to the concept of beans and then quite quickly dives into the topic, first giving you a rough overview of the entire platform before then each chapter gets straight down to the nitty gritty of the different concepts. Lots of detailed code samples contribute to further clarifications.

Chapter 2, which is dedicated to the IoC mechanism and its implementation in Weld CDI, presents some interesting concepts such as Client proxies which allow that even though an application-scoped bean ApplicationBean exists only once per applicaton you still get a different instance on each request for its request-scoped dependency bean.

@RequestScopedpublicclassRequestBean{...}@ApplicationScopedpublicclassApplicationBean{@InjectRequestBean bean;}

While I didn’t (yet) setup Weld by myself on my workstation, chapter 3 should be of a help as it describes the correct setup using a variety of containers like JBoss, Glassfish or Apache Tomcat.
The subsequent chapters target each of the core concepts in a more detailed way like

  • Contexts and scopes,
  • Producers,
  • Interceptors and decorators,
  • Events or on
  • how to extend CDI with portable extensions.

Finally the last two chapters illustrate the mentioned concepts in the creation of a sample application that features a modern AngularJS based JavaScript frontend with a REST backend.

Conclusion

To conclude, the book is definitely worth reading if you plan to implement the CDI specification in one of your next JEE projects. It is contains enough details to easily get started, it is clearly written with proper practical code examples and the author has chosen the right pace and amount of information that is presented throughout the chapters.

Unfortunately - due to time constraints - I wasn’t yet able to create some setup using Weld by myself. I hope to find some spot to do so as you learn most when you try it out by yourself.
But apart from this specific book, I always again enjoy to leave my “comfort zone” to learn about new technologies and compare them with what I have already seen in other areas (like .Net, NodeJS) and so should you! Keep yourself open-minded for new stuff!
Interestingly, for instance, I found lots of similarities between some concepts in Weld CDI and .Net’s Managed Extensibility Framework (MEF) and PRISM.

Links

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. Our APIs verify, standardize, and correct the Big 4 + more – name, email, phone and global addresses – to ensure accurate delivery, prevent blacklisting and identify risks in real-time.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}