Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdi-dev] CDI future - problems and proposal

Hi,

On Wed, Oct 21, 2020 at 5:17 PM Tomas Langer <tomas.langer@xxxxxxxxxx> wrote:

From Arjan Tijms:
 - Interceptors on programmatically created beans - I understand there should be a way to get appropriate decorated instance, that would apply all interceptors when methods are invoked on the returned instance; I think this must be handled with care with regard to the new features we discuss, as a bean computed at build time would already know about all its interceptors. Bean.create in such a case returns an already decorated instance. Why cannot this be done using extension to add an interceptor binding to the bean before it is set up?

The problem is that in Bean.create you'd normally return just an instance instantiated with say new. There's no API available to know about all its interceptors, yet the Bean<T> contract, more specifically javax.enterprise.context.spi.Contextual.create(CreationalContext<T>), demands that the returned instance is already decorated.

As the Bean<T> is by definition added using an extension, I'm not 100% sure what you mean by "add an interceptor binding to the bean before it is set up". How would one go about doing that?


 
 - Access to injection point in Bean#create() -  Do you envision what change in API would be useful here? What is the needed (additional) metadata you want to obtain from the injection point? I guess some sort of “synthetic” injection point could be created when requesting this programmatically. Or we could add support for parameters to @Produces methods, that could be explicitly defined when invoking this...

The needed metadata is essentially everything an existing Producer (or Bean.create method that obtains the InjectionPoint) could see on the InjectionPoint. Parameters would partially solve it, but would make life more complicated for Producers, who then explicitly have to take into account both injected and programmatic lookup. A contrived example would be requesting beans made available by the MP Config API, for instance:

CDI.current().select(String.class, new ConfigPropertyLiteral(), new InjectionPointImpl().withMemberName("foo"));

I know there's other ways to do this, but it's just an example. Here the MP Producer would get to see a non-null InjectionPoint instance, and when inspecting its member it would find the name "foo", and would therefore use that as the property name.

Kind regards,
Arjan Tijms












 

Back to the top