[wildfly-dev] WELD/CDI event clarifications

Eric B ebenzacar at gmail.com
Mon Nov 12 09:56:47 EST 2018


I apologize if this not the correct forum to post this question, but I
tried looking at the Weld forums and everything appears dormant (even the
link to the user's forum is 404 on the Weld site).  So I suspected this
would be the second best place to ask for some clarity.

I'm trying to understand the sequencing of CDI events vs bean
initialization.  I'm currently concentrating on CDI 1.2/Weld 2.3.5, but
figure that this information will be applicable to CDI2.0 as well.   I've
tried finding documentation online and posting on StackOverflow and neither
have produced any results.  Specifically, I am confused about the
sequencing of CDI events vs when/how bean methods are called.  Given what I
have read, the following are the events that are triggered by the CDI
container:

   - BeforeBeanDiscovery
   - ProcessAnnotatedType and ProcessSyntheticAnnotatedType
   - AfterTypeDiscovery
   - ProcessInjectionTarget and ProcessProducer
   - ProcessInjectionPoint
   - ProcessBeanAttributes
   - ProcessBean, ProcessManagedBean, ProcessSessionBean,
   ProcessProducerMethod and ProcessProducerField
   - ProcessObserverMethod
   - AfterBeanDiscovery
   - AfterDeploymentValidation
   - BeforeShutdown

Given these events, when are the events which produce
@Initialized(ApplicationScoped.class)
and @Destroyer(ApplicationScoped.class) triggered?  In which part of the
lifecycle?  Are they triggered in the @PostConstruct equivalent of the
Scoping bean (what is the bean backing the ApplicationScope?  I cannot find
the implementation in the Weld core - am I even looking in the right
place?)?

Which brings me to the next question - in which stage of the container
setup are the @PostConstruct methods on the beans called?  Are they called
in the `AfterDeploymentValidation` phase?  Or is it somewhat asynchronous -
in that the @PostConstruct of an ApplicationScoped bean will be called only
when initialized; and that could happen during any of the stages?  From
what I understand, the BeanManager.getReference() is not allowed prior to
the AfterDeploymentValidation event being fired, which to me would imply
that beans can only be instantiated (and therefore @PostConstruct'ed) after
the `AfterDeploymentValidation` phase.

Can anyone direct me towards some clarification of these points?  I've
tried reading the CDI 1.2 user guide (
https://docs.jboss.org/cdi/learn/userguide/CDI-user-guide.html), but that
hasn't provided the details I am looking for.  Additionally, I've tried
reading through the Weld code but can't find the answers I'm looking for.

Thanks,

Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/wildfly-dev/attachments/20181112/d4accb23/attachment.html 


More information about the wildfly-dev mailing list