8 Replies Latest reply on Dec 2, 2009 5:17 PM by gavin.king

    provider from beanmanager

    brackxm

      How would i get a Provider for a certain bean from the BeanManager?


        • 1. Re: provider from beanmanager
          gavin.king

          I presume that by provider, you mean an instance of Provider<X>. This will work:


          bm.getReference( bm.resolve( bm.getBeans( new TypeLiteral<Provider<Foo>>() {}, new AnnotationLiteral<SomeQualifier>() {} ) ), Provider.class, bm.createCreationalContext(null) )



          It's much, much better to just inject the thing if you can:


          @Inject @SomeQualifier Provider<Foo> fooProvider;



          Why are you wanting to get it from the BeanManager? Are you writing a portable extension?

          • 2. Re: provider from beanmanager
            brackxm

            Thanks.
            Yes, i'm trying to write a portable extension.
            I must say, form the javadoc it's not easy to understand the SPI.
            Where would you suggest to look for more information?

            • 3. Re: provider from beanmanager
              nickarls

              If you'll give some overview of what you are trying to achieve, we might be able to give you more information (and fill in the gap in the docs)

              • 4. Re: provider from beanmanager
                gavin.king

                So why does your portable extension need to obtain a Provider?  I can't really think why you would want to do that...

                • 5. Re: provider from beanmanager
                  brackxm

                  I am trying to write a portable extension for reasteasy.


                  With a Provider resteasy can get a CDI created instance when it needs one.
                  Probably the BeanManager could be used each time, but using a Provider seemed easier.


                  I just noticed Jozef Hartinger is going to do JAX-RS integration
                  (http://www.seamframework.org/Documentation/Seam3Modules)

                  • 6. Re: provider from beanmanager
                    gavin.king

                    In a portable extension, I recommend using BeanManager directly. Provider is intended for use in application code.

                    • 7. Re: provider from beanmanager
                      brackxm

                      getReference() returns an object, that's a disadvantage


                      perhaps you can add that code example to section 16.3 of the reference guice


                      note that there is a typo: getType() on the type literal is missing


                      Are there any (example) portable extensions?

                      • 8. Re: provider from beanmanager
                        gavin.king

                        getReference() returns an object, that's a disadvantage

                        Really? In generic code, you generally work with Object anyway. A JAX-RS resource is just an Object as far as your PE is concerned....