Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdi-dev] Extend lookup by method types and annotations?

Hi,

note that a bean can often be declared and injected based solely on its interface. In such case, CDI specification declares certain inheritance rules[1] one of which is that you don't inherit from interfaces. That would break your model plus in then incentivises use of some concrete implementation class instead of interfaces and/or abstractions.

Other issue I can see is that in a complex bean class hierarchy you can override methods, inherit and not inherit (based on presence of `@Inherited`) some or all of their annotations which then ends up heavily affecting the resolution process for your proposal. It also requires a deep preliminary knowledge of existing classes to even make use of this approach which, to me personally, seems counterintuitive/counterproductive.
Not to mention that it introduces a (for instance) question of whether a bean is eligible for injection if it doesn't have given annotation on its method, but its predecessor does.

Last but not least, this change would basically affect the whole resolution model changing the bean definition from {Set<Type>, Set<Qualifier>} to something akin to {Set<Type>, Set<Qualifier>, Map<Method, Qualifier>} which is a lot more complex for seemingly no gain. So I am -1 for this.

> However, not rarely we need to find beans with annotations on methods and/or methods with a type

This doesn't feel like a good match for what CDI does and I honestly haven't seen that used until now. In theory, you could achieve this with existing model by iterating over all instances of given type and qualifiers or just starting from BM#getBeans() from you can inspect?

Matej
__________________________________________________________________________________________________

[1]https://jakarta.ee/specifications/cdi/2.0/cdi-spec-2.0.html#inheritance

On Thu, Sep 9, 2021 at 2:32 PM arjan tijms <arjan.tijms@xxxxxxxxx> wrote:
Hi,

In CDI we currently have lookup capabilities to lookup by type, qualifiers, or a combination of this.

E.g.

CDI.current().select(SomeType.class, SomeQualifier.LITERAL);

However, not rarely we need to find beans with annotations on methods and/or methods with a type. For instance, consider the following code:

   @RequestScoped
    @ViewAction
    public class IndexPageBean {
     
      @FacesViewId("/index")
      public String execute() {
          ...    
      }
    }

We could select such bean with an extended lookup like:

CDI.current()
      .select(ViewAction.Literal.INSTANCE)
      .methods()
      .select(String.class, FacesViewId.Literal.of("/index");

Thoughts?

Kind regards,
Arjan Tijms




_______________________________________________
cdi-dev mailing list
cdi-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/cdi-dev

Back to the top