Chapter 5. Producers

In this chapter we will expand on producers, which were introduced back in Chapter 1, What is a Bean?, by covering their uses in greater detail. We will also see what scopes our produced beans are in and how to ensure that the beans we produce don't leave pieces of themselves behind when they're destroyed.

We've already learned how producers can be useful when we want to make runtime decisions about which bean instance should be used in a given situation. But there can be many situations where producers are beneficial, such as enabling third-party frameworks to be used with CDI by exposing their objects as beans.

Producers allow us to utilize runtime polymorphism, such as:

@SessionScoped public class SearchManager implements ...

Get JBoss Weld CDI for Java Platform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.