[weld-dev] BeanManagerImpl permits multiple Contexts per scope type: why?
Martin Kouba
mkouba at redhat.com
Fri Nov 2 04:25:57 EDT 2018
Hi Laird,
The reason why it is possible to register multiple context objects for a
scope is that a particular context implementation may be intended for a
specific use case/technology. Take for example the request context - it
should be active during HTTP requests, async EJB invocation, MDB, etc.
It wouldn't be practical to only have one Context implementation for all
use cases.
The spec is very clear that this should be possible. See for example
6.5.1. The active context object for a scope:
"The container must search for an active instance of Context associated
with the scope type."
And even 6.2. The Context interface:
"A context object may be defined for any of the built-in scopes and
registered with the container using the AfterBeanDiscovery event as
described in AfterBeanDiscovery event."
HTH
Martin
Dne 01. 11. 18 v 22:46 Laird Nelson napsal(a):
> I noticed that BeanManagerImpl permits many Contexts to be indexed under
> a given scope type
> <https://github.com/weld/core/blob/d8a8cb64f3a9751dcac07c8d9eda0dd3a0e682b8/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java#L663>.
> Why is that?
>
> The CDI 2.0 specification says
> <http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#contexts>:
>
> "Associated with every scope type is a context object."
>
> I took "a context object" to mean "exactly one context object" but maybe
> I'm mistaken? Obviously Weld can do things outside of the specification
> but I was curious what the use case might be here.
>
> I do understand that certainly only one Context of a given scope type
> may be active. I was just curious why the container even permits many
> to be registered.
>
> Best,
> Laird
>
> _______________________________________________
> weld-dev mailing list
> weld-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/weld-dev
>
--
Martin Kouba
Senior Software Engineer
Red Hat, Czech Republic
More information about the weld-dev
mailing list