javaslang List.of() on cdi Instance

240 Views Asked by At

I have multiple class with a Qualifier that I created:

  @ServiceComponent(restPath = "/trucks")
  public class TruckService {
  }

  @ServiceComponent(restPath = "/cars")
  public class CarService {
  }

here is the Qualifier (not important for the question)

    @Qualifier
    @Retention(RetentionPolicy.RUNTIME)
    @Target({TYPE, FIELD})
    public @interface ServiceComponent {

        public boolean exposeAsRest() default true;

        @Nonbinding public String restPath() default "";

        @Nonbinding public String restGetPrefix() default "get,find,all";

        @Nonbinding public String restPostPrefix() default "create,new,post";
    }

in another class, I inject those instance using javax.enterprise.inject.Instance<>

    class SomeConfigurationClasss {

        @Inject
        @ServiceComponent()
        Instance<Object> _restComponents;

         @Override
          public void iterate() throws Exception {

              //iterate
              for(Object obj : _restComponents){
                  somefuncion(obj);

              }

              //List.of(_restComponents)
                //.flatMap(obj -> somefuncion(obj));

          }

      }

if I execute the "normal" iteration (for...) I get the Object (TruckService or CarService) given as parameter to the somefunction().

but if I use javaslang's List.of(...) I get the Instance itself. Which I think it's the expected behavior

Is there a possibility to use List.of on a Instance that can contain one or multiple bean (depending on the injection binding). (I already try to call iterator(), select() on the Instance)

1

There are 1 best solutions below

0
On BEST ANSWER

Instance<T> extends Iterable<T> so you should use List#ofAll(Iterable)