CDI bean scopes
CDI stands for “Contexts and Dependency Injection,” CDI Beans have a scope which defines their lifecycle, their scope determines when the Jakarta EE runtime creates and destroys CDI beans. “Contexts” in “Contexts and Dependency Injection” refers to CDI scopes. When a CDI bean is needed, either because of injection or because it is referred to from a Jakarta Faces page, CDI looks for an instance of the bean in the scope it belongs to and injects it into the dependent code. If no instance is found, one is created and stored in the appropriate scope for future use. The different scopes are the context in which the bean exists.
The following table lists the different valid CDI scopes:
Scope |
Annotation |
Description |
Request |
|
Request-scoped... |