In CDI, classes annotated with @Dependent are "pseudo-scoped", what means:
- "No injected instance of the bean is ever shared between multiple injection points"
- Multiple instances can exist at the same time
- "Any instance of the bean injected into an object that is being created by the container is bound to the lifecycle of the newly created object."
- A "POJO" declared with
@Dependentannotation and injected into a e.g.
@RequestScopedbean has the same lifecycle as the corresponding bean.
- "Any instance of the bean that receives a producer method, producer field, disposer method or observer method invocation exists to service that invocation only."
@Dependentonly lives as long, as the e.g.
- "Any instance of the bean injected into method parameters of a disposer method or observer method exists to service the method invocation only."
- An as e.g. parameter injected
@Dependentbean lives as long as the method invocation takes.
Because there is 1:1 relation between the
@Dependent bean and the host instance, proxies are not needed in the standard case. The
can be directly injected by the container.
Good news: the dependent scope is the default scope, if no scope is defined (if a class is not annotated).
Following the "Convention over Configuration" principle, you don't have to declare the
@Dependent annotation. All not annotated classes, or "POJOs", are dependent-scoped.
In an ECB/BCE application, the
boundary is annotated with
and all other
control instances come as vanilla POJOs without any annotations. They are dependent-objects.
Web Apps, SPA, PWA with vanilla Java Script (ES 6+), CSS 3 and WebStandards only. As simple as possible, but not simpler. See you at: (Progressive) Web apps, Single Page Apps and WebStandards airhacks workshops at MUC airport, Winter Edition
airhacks.fm the podcast:
Stay in touch: airhacks.news.