[cdi-dev] CDI.current() in AfterDeploymentValidation

Martin Kouba mkouba at redhat.com
Tue Apr 4 11:00:50 EDT 2017


Hm, that's not very consistent :-(

E.g. BeanManager.getReference() can only be used during 
AfterDeploymentValidation. But BeanManager.createInstance() even during 
AfterBeanDiscovery.

Martin


Dne 4.4.2017 v 16:55 Antoine Sabot-Durand napsal(a):
> John,
>
> During AfterDeploymentValidation, you can use
> BeanManager.createInstance() to retrieve a bean instance. It was added
> for that.
>
> Antoine
>
> On Tue, Apr 4, 2017 at 9:12 AM Martin Kouba <mkouba at redhat.com
> <mailto:mkouba at redhat.com>> wrote:
>
>     FYI I've created https://issues.jboss.org/browse/WELD-2371.
>
>     Martin
>
>     Dne 3.4.2017 v 14:59 Martin Kouba napsal(a):
>     > John,
>     >
>     > that's not true. I'm saying that calling CDI.current() and
>     > CDI.getBeanManager() is valid. However, it is not portable (and NOT
>     > supported by Weld ATM) to call other CDI methods (CDI.select() etc.)
>     > before the application initialization is completed.
>     >
>     > See also 11.3.1. Obtaining a reference to the CDI container:
>     > "A portable extension or other object may obtain a reference to the
>     > current container by calling CDI.current(). CDI.getBeanManager()
>     may be
>     > called at any time after the container fires the BeforeBeanDiscovery
>     > container lifecycle event until the container fires the BeforeShutdown
>     > container lifecycle event. Other methods on CDI may be called
>     after the
>     > application initialization is completed until the application shutdown
>     > starts. If methods on CDI are called at any other time, non-portable
>     > behavior results."
>     >
>     > I believe the spec is clear...
>     >
>     > Martin
>     >
>     > Dne 3.4.2017 v 14:49 John Ament napsal(a):
>     >> All,
>     >>
>     >>
>     >> So Martin below is saying its valid, but then in the ticket is saying
>     >> its not valid.  I'll wait for others to voice opinions on this one.
>     >>
>     >>
>     >> John
>     >>
>     >>
>     >>
>     >>
>     >>
>     ------------------------------------------------------------------------
>     >> *From:* Martin Kouba <mkouba at redhat.com <mailto:mkouba at redhat.com>>
>     >> *Sent:* Monday, April 3, 2017 2:48 AM
>     >> *To:* John Ament; cdi-dev
>     >> *Subject:* Re: [cdi-dev] CDI.current() in AfterDeploymentValidation
>     >>
>     >> Hi John,
>     >>
>     >> I think it's valid to call CDI.current() from within an
>     extension. WRT
>     >> Weld - what version and environment do you use? There was an issue in
>     >> Weld SE which should be fixed in 2.4.2 (see also WELD-2256 [1]).
>     >>
>     >> Martin
>     >>
>     >> [1]
>     >> https://issues.jboss.org/browse/WELD-2256
>     >>
>     >> Dne 3.4.2017 v 04:36 John Ament napsal(a):
>     >>> So I know during the reception of AfterDeploymentValidation, the
>     >>> container isn't fully bootstrapped.  However, its valid to look up
>     >>> beans.  I would therefore expect that CDI.current().select()...
>     to work
>     >>> fine.  However, at least in Weld it doesn't.  This is because
>     >>> CDI.current() cannot figure out what container to use (it's not
>     fully
>     >>> bootstrapped yet).  So my question - is this a Weld issue, or a spec
>     >>> clarification?
>     >>>
>     >>>
>     >>> John
>     >>>
>     >>>
>     ------------------------------------------------------------------------
>     >>> NOTICE: This e-mail message and any attachments may contain
>     >>> confidential, proprietary, and/or privileged information which
>     should be
>     >>> treated accordingly. If you are not the intended recipient, please
>     >>> notify the sender immediately by return e-mail, delete this
>     message, and
>     >>> destroy all physical and electronic copies. Thank you.
>     >>>
>     >>>
>     >>> _______________________________________________
>     >>> cdi-dev mailing list
>     >>> cdi-dev at lists.jboss.org <mailto:cdi-dev at lists.jboss.org>
>     >>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>     >>>
>     >>> Note that for all code provided on this list, the provider licenses
>     >>> the code under the Apache License, Version 2
>     >>> (http://www.apache.org/licenses/LICENSE-2.0.html). For all other
>     ideas
>     >> provided on this list, the provider waives all patent and other
>     >> intellectual property rights inherent in such information.
>     >>>
>     >>
>     >> --
>     >> Martin Kouba
>     >> Senior Software Engineer
>     >> Red Hat, Czech Republic
>     >>
>     ------------------------------------------------------------------------
>     >> NOTICE: This e-mail message and any attachments may contain
>     >> confidential, proprietary, and/or privileged information which
>     should be
>     >> treated accordingly. If you are not the intended recipient, please
>     >> notify the sender immediately by return e-mail, delete this
>     message, and
>     >> destroy all physical and electronic copies. Thank you.
>     >
>
>     --
>     Martin Kouba
>     Senior Software Engineer
>     Red Hat, Czech Republic
>     _______________________________________________
>     cdi-dev mailing list
>     cdi-dev at lists.jboss.org <mailto:cdi-dev at lists.jboss.org>
>     https://lists.jboss.org/mailman/listinfo/cdi-dev
>
>     Note that for all code provided on this list, the provider licenses
>     the code under the Apache License, Version 2
>     (http://www.apache.org/licenses/LICENSE-2.0.html). For all other
>     ideas provided on this list, the provider waives all patent and
>     other intellectual property rights inherent in such information.
>

-- 
Martin Kouba
Senior Software Engineer
Red Hat, Czech Republic


More information about the cdi-dev mailing list