Open arjantijms opened 3 years ago
We need to take a look at whether we can lift the spec restriction of not applying decorators to producers and synth beans https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0.html#decorators If that doesn't work, we can at least take a look at having an API/SPI that will allow this explicitly for a given synth bean.
As per discussion during last CDI mtg (Dec 5), I am closing this issue. It has been stale for three years now indicating that there isn't much interest nor are there any takers to submit proposal or impl drafts for this feature.
@manovotn can you re-open? I actually was working on a PR for this, but with the M1 deadline for security and such didn't had time to push it out yet.
This is still as important as before. Every spec (or library) that provides build-in beans via an Extension needs this, as those provided beans can not be decorated now. It seems there's no interest, but there is. People do run into this, but (almost) nobody understands that this issue is the root cause.
I think it's also somehow a testimony to us (as spec creators, including the other specs) failing to educate both our users and ourselves.
Thanks @starksm64
Currently when adding a
Bean<T>
usingjakarta.enterprise.inject.spi.AfterBeanDiscovery.addBean()
orjakarta.enterprise.inject.spi.AfterBeanDiscovery.addBean(Bean<?>)
any decorators declared or programatically added for the types of theBean<T>
are not automatically applied.Not only is this perhaps surprising, there actually is no portable way to achieve this behaviour. Someone adding a bean must resort to SPIs and implementation specific code. For instance Soteria uses the following code:
Source
Where
decorator.decorateBean
is an SPI, that for Weld uses code such as the following:Source
This code is difficult to come up with, difficult to maintain and error prone. The user must also make sure the right companion SPI implementation is available on the class path.
To simplify this, I'd like to propose a method for
BeanConfigurator
to signal to the runtime that enabled decorators should be applied to the instance returned from theBean.create
(`Contextual.create') method, just like happens for beans which implement the bean types directly and are discovered by CDI.For instance:
Several variants could be considered, like e.g.: