Registering a bean

An extremely common use case for extension developers is to register one or more beans with Weld to make them available within an application. To make it possible to register new beans, CDI provides the Bean interface, which represents a bean within an application. For every bean in our application, including interceptors, decorators, and producers, there is an instance of Bean that is registered with the BeanManager.

Note

The AnnotatedType represents the metadata of a bean type, which is used by Weld to then construct a physical Bean instance from that metadata.

We will create a simplified example of how an extension can add a bean to a CDI application.

public class AddBeanExtension implements Extension { public void afterBeanDiscovery ...

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.