4 Replies Latest reply on Aug 7, 2012 4:33 AM by Sueleyman Vurucu

    HOWTO create more then one instance of a contextual bean

    Sueleyman Vurucu Expert

      I have a usecase where I need to inject more then one instance (like a stateful session bean in EJB ) of the same beanclass.


      For example.


      Lets assume I have the class hierachiy shown below.



      Controller1 extends AbstractController



      So now I inject the  controllers in my repository:




      // EJB Singleton bean needs to intialize at startup



      @Inject @Qualifier1

      Controller1 controller1_1;


      @Inject @Qualifier1

      Controller1 controller1_2;




      The problem is that in a Session,Conversation or Customscope I speek allway with the same bean instance for  controller1_1 and controller1_2.


      I assume the problem or the limitation is in the Context interface.


      Everytime if I inject something in my scope then this method of the Context will called


      T get(Contextual<T> contextual)


      So I have no Information which bean insance should be retrived.


      How can I handle this with CDI ?


      Thanks in advance.