8 Replies Latest reply on Sep 19, 2010 8:50 AM by staenker

    Portable Extensions Package

    sunls

      Who can help me,where can I find the
      Guice-style configuration API?


      Thanks.

        • 1. Re: Portable Extensions Package
          nickarls

          From the top of the page:


          Ideas for the JSR-299 portable extensions package.
          



          I don't think there is an implementation yet(?)

          • 2. Re: Portable Extensions Package
            pmuir

            Yes, this is still to be done ;-) Anyone interested in working on it?

            • 3. Re: Portable Extensions Package
              tittop

              Pete Muir wrote on Jun 03, 2010 06:18:


              Yes, this is still to be done ;-) Anyone interested in working on it?


              Amm... is it really necessary in CDI? I'm speaking of Guice's binder.bind().to() and @ImplementedBy. That is to say, if I really wanna bind somewhat ImplClass to it's interface, it's supposed to use CDI's Qualifier, maybe..




              @Inject
              @Any
              Instance<SomeInterface> instance;
              
              SomeInterface ins = MyInjector.getInstance(instance);



              where MyInjector is my newly created injector:



              public class MyInjector {
                  public static <T> T getInstance(Instance<T> instance) {
                      return instance.select(SomeQualifierAnnotation).get();
                  }
              }



              but I'm not sure if it is right..

              • 4. Re: Portable Extensions Package
                alin.heyoulin.qq.com

                It's to extension old code.Some old code have not qualifierAnnotation and can't modify.But this can do in xml module.I think weld should using Guice-style configuration instead of load all package class as bean.

                • 5. Re: Portable Extensions Package
                  pmuir

                  Liu Kai wrote on Jun 03, 2010 07:19:



                  Pete Muir wrote on Jun 03, 2010 06:18:


                  Yes, this is still to be done ;-) Anyone interested in working on it?


                  Amm... is it really necessary in CDI? I'm speaking of Guice's binder.bind().to() and @ImplementedBy. That is to say, if I really wanna bind somewhat ImplClass to it's interface, it's supposed to use CDI's Qualifier, maybe..



                  @Inject
                  @Any
                  Instance<SomeInterface> instance;
                  
                  SomeInterface ins = MyInjector.getInstance(instance);



                  where MyInjector is my newly created injector:


                  public class MyInjector {
                      public static <T> T getInstance(Instance<T> instance) {
                          return instance.select(SomeQualifierAnnotation).get();
                      }
                  }



                  but I'm not sure if it is right..


                  The code you show is about programmatic lookup of instance, whilst Binder is a way to programatically configure the beans themselves. CDI supports programatic configuration of beans, but not using a fluent API (instead it uses lifecycle events). The task is to map a fluent to the lifecycle events.



                  It's to extension old code.Some old code have not qualifierAnnotation and can't modify.But this can do in xml module.I think weld should using Guice-style configuration instead of load all package class as bean.


                  This is what the extension would allow you to do. We can't do it natively by default in Weld, as Weld must implement the CDI spec.

                  • 6. Re: Portable Extensions Package
                    hmo

                    Supporting Guice style configuration is definitely a step forward, just wire the beans you want and this way Weld won't scan everything in the classpath. Pete, when are you planning to release this? 

                    • 7. Re: Portable Extensions Package
                      pmuir

                      Currently no firm date, we're really looking for a volunteer to work on it.

                      • 8. Re: Portable Extensions Package
                        staenker
                        Hi,
                        I was searching for a solution to set up weld without scanning or multiple beans.xml files. In guice this is no problem using the binder / module approach. I only need this for testing. I found weld-se doing the work using weld outside of a container - perfect for testing. But it scans the whole class path. So it's not possible to create a "weld" only responsible for 3 of 1000 classes. Of course a weld binder would solve the problem, but I don't think this is the most easy way to solve the problem. That's why I wrote a builder. It is used like this

                        TestWeldBuilder builder = new TestWeldBuilder();
                        builder.addManagedClass(MockInterface.class);
                        builder.addManagedClass(MockInterfaceImpl.class);
                        builder.addManagedClass(MockInterfaceImplAlternativeByStereo.class);
                        builder.addAlternativeStereotype(MockAlternativeStereotype.class);
                        Weld weld = builder.toWeld();
                        WeldContainer weldContainer = weld.initialize();
                        MockInterface mock =  weldContainer.instance().select(MockInterface.class).get();
                        assertEquals("Alternative by Stereo", mock.getName());

                        This solves my problem. Does it also solves yours?