Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-723

Obtaining 'original' type/instance of alternatives

    XMLWordPrintable

Details

    • Feature Request
    • Resolution: Obsolete
    • Major
    • None
    • 2.0 .Final
    • None
    • None

    Description

      This issue is based on CDI mailing list discussion.

      The request is, given that there is one (or more) alternative(s) in place, to be able to obtain an instance of the original bean.

      E.g. given that I have:

      public interface FooFace{...} // interface
      
      @ApplicationScoped
      public class FooImpl{...} // 'original' impl
      
      @ApplicationScoped
      @Alternative
      @Priority(1)
      public class AltFooImpl{...} // alternative impl
      

      I want to be able to put my hands on FooImpl instance.

      The use case is to be able to obtain certain data from it, or simply build on top of it and it concerns both, producers and "classic" beans defined as classes and overriden via alternatives.

      As for implementation, this could be done on the Instance level, given an additional structure is added. What would be needed is a way to say that you want to resolve all beans of given type, but without throwing away disabled alternatives. Then you want to allow user to browse through those beans (with access to metadata - Bean<?>. With that in place, user could then browse all the beans and choose which one to instantiate.

      Following is an idea of how this could be done using structures have in Weld:
      For instance, in Weld this would be possible using our internal structure, called Handler, which allows to browse bean metadata. From WeldInstance (enriched version of Instance), you can call getHandler() to obtain the object. With this in place we could pretty easily allows user to get all the beans with given type, inspect them, and then instantiate whichever is needed.

      Attachments

        Activity

          People

            Unassigned Unassigned
            manovotn Matěj Novotný
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: