2 Replies Latest reply: May 14, 2012 10:38 AM by John Doe RSS

    Create producers at runtime

    John Doe Newbie

      I have many annotated interfaces like this.

       

      @A
      public interface Interface1 {
      }
      

       

      At runtime there will be somehow created implementations of these interfaces. In the code I want to inject this implementation like this:

       

      @Inject
      // Optional qualifiers.
      private Interface1 myInterface1;
      
      @Inject
      private void test(Interface1 arg0) {
          ...
      }
      

       

      Now I'm using an extension in which I have one producer:

       

      @Produces
      @MyInternalQualifier
      Object getImplemenation(InjectionPoint injectionPoint) {
          ...
      }
      

      And ProcessAnnotatedType observer in which I replace the type of the field/parameter to Object and add a special internal annotation @MyInternalQualifier.

       

      The disadvantage of this approach is that there is no real producer for interface types, so you cannot create an implementation programmatically with BeanManager. Is there any way to create real producers at runtime?