1 Reply Latest reply on May 30, 2011 10:22 AM by Jozef Hartinger

    Change the scope of beans coming from external archive

    George Vagenas Newbie

      Is there a way to change the scope of a bean discovered from an external archive? For example I would like to change bean's scope from @Dependent or @Singleton to @ApplicationScoped.

      I have an external archive that is meant to provide shared functionality for a framework that will come in two versions, one based on CDI and one based on Spring, so this archive can use JSR330 which is shared among CDI and Spring, but @Singleton is not what I am looking for in the CDI version and i would like to change several provided beans scope to @ApplicationScoped.

      Any thought or advices on that?


        • 1. Re: Change the scope of beans coming from external archive
          Jozef Hartinger Master

          How do you register the beans from the external archive? I believe that you implemented a portable extension with a similar method:

          public void registerBeans(@Observes BeforeBeanDiscovery event, BeanManager manager)

          If so, you can easily implement a delegating implementation of the AnnotatedType interface which delegate every method call to the instance created by manager.createAnnotatedType(Foo.class) but will override the getAnnotation() and isAnnotationPresent() methods and return @ApplicationScoped instead of @Singleton.