5 Replies Latest reply on Feb 1, 2010 10:12 AM by nickarls

    Producing dependent instance into SessionScoped bean

    lfryc

      Hi,


      I have problem with producer method injecting actual instance to SessionScoped bean.


      It seems, that injection point behave as SessionScoped, but I annotated producer as Depedent, so each use of my InjectionProvider should obtain new reference for toInject, shouldn't it?


      @Named @SessionScoped
      public class InjectionProvider implements Serializable {
          private String toInject = "initial";
      
          @Produces @Dependent @ToInject
          public String getToInject() {
              return toInject;
          }
      
          public void setToInject(String toInject) {
              this.toInject = toInject;
          }
      }



      @Named
      @SessionScoped
      public class InjectionConsumer implements Serializable {
      
          @Inject @ToInject transient String toInject;
      
          public String getFromInject() {
              return toInject;
          }
      }



      @Qualifier
      @Target({FIELD, PARAMETER, TYPE, METHOD})
      @Retention(RUNTIME)
      public @interface ToInject {
      }



      First invocation of InjectionConsumer.getFromInject gave initial as expected, but when we call InjectionProvider.setToInject("othervalue"), it got:


      InjectionProvider.getToInjectothervalue


      InjectionConsumer.getFromInject = initial


      Is it my misunderstanding of producer or can it be bug?



      Workaround for this sample is use InjectionConsumer as RequestScoped, but it isn't desired solution.


      Thans for reply,
      Lukas


      (I verified that it misbehaves on  latest JBoss 6 Snapshot .
      But it fails also on GlassFish v3.)