2 Replies Latest reply on May 22, 2012 10:43 AM by cbrock

    Is @Any supported?

    jervisliu

      Hi, I have following code using @Any:

       

      Map<String, Activity> activites = new HashMap<String, Activity>()

       

      @Inject

      void initServices(@Any Instance<Activity> activities) {

          for (Activity activity: activities) {

              activites.put(activity.getNameToken(), activity);

          }

      }

       

      Then I have all Activity classes marked as @ApplicationScoped for example:

       

      @ApplicationScoped

      public class MyAdminAreaActivity extends Activity {

       

      }

       

      I would like to use this code to have all Activity classes instantiated then get them injected into activities. However during the debug I found activities is empty. I wonder if @Any is already supported in Errai or did I do any wrong? Thanks.

       

      Cheers,

      Jervis

        • 1. Re: Is @Any supported?
          cbrock

          This is not yet supported. But will be soon in Errai 2.1. Although, Instance<?> does not exactly work like that.

          • 2. Re: Is @Any supported?
            cbrock

            Instead of doing what you're trying to do, you can simply use the Bean Manager: https://docs.jboss.org/author/display/ERRAI/Client-Side+Bean+Manager

             

             

            public MyManagedBean {

             

              @Inject IOCBeanManager manager;

              

              public void lookupBean() {

                Collection<IOCBeanDef> bean = manager.lookupBeans(Activity.class);

             

                // check to see if the bean exists

                for (Activity activityBean : beans) {

                  // get the instance of the bean

                  Activity bean = (Activity) activityBean.getInstance();

                }

              }

            }