0 Replies Latest reply on May 30, 2010 11:23 AM by John Ament

    RequestScoped and Nonbinding Qualifiers

    John Ament Master

      I'm not sure if this is a short coming, a misunderstanding, a flaw or a new feature that I'm describing, but I found something that seems impossible in Weld.


      This may go back to the dynamic vs static injection argument, but it seems like something that should fall under static injection.  Essentially, I have a Qualifier:




      public @interface MyQualifier {
      @Nonbinding public String type() default "";
      }





      So that means I can have injection points like




      @Inject @MyQualifier(type="type1") Something type1;
      @Inject @MyQualifier(type="type2") Something type2;





      I can have a dependent producer that can get the MyQualifier and use it depending on what's passed in.




      @Produces @MyQualifier(type="")
      public Something produceTypedSomething(InjectionPoint ip) { ... }





      Now that works fine, but the producer gets called way too much (each injection point calls the producer).  That's fine if making Something's is simple, but if it's complex then it's a big drain on performance.  What I really wanted though was a @RequestScoped @MyQualifier Something.  But then it dawns on me, I can only use InjectionPoint if it's a dependent object, since RequestScoped objects are instantiated with the request itself, not the injection points.  Now that makes sense, but then it means that the qualifier used has no attributes, or all possible attribute combinations need to be listed in the producer itself.  for the app developer, that makes it easier, but for the framework developer it becomes more of a pain.  I suppose a work around would be an extension to handle this somehow?