Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-473

Standardize eager initialisation of ApplicationScoped bean

    Details

    • Type: Feature Request
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: TBD
    • Component/s: Contexts
    • Labels:
      None

      Description

      Given the proxying strategy documented in the CDI specification, normal scoped beans get initialize when an injected proxy reference is first called.

      While that's perfectly fine in the vast majority of use cases, that proves inconvenient when dealing with ApplicationScoped beans that capture application singletons which we want to bound to the application lifecycle with a postConstruct callback. As this callback is only called when a proxy is invoked, it is frequent to see the application developers using a CDI extension to meet that need, e.g.:

      void forceInitialization(@Observes AfterDeploymentValidation adv, BeanManager manager) {
          for (AnnotatedType<?> type : eagerBeans)
              // Calling toString is necessary to force the initialization of normal-scoped beans
              BeanManagerHelper.getReferencesByType(manager, type.getBaseType(), AnyLiteral.INSTANCE).toString();
      }
      

      There should be a concise way to declare that intent which would then be address by the CDI container, for example:

      @ApplicationScoped(eager = true}
      class EagerApplicationScopedBean {
      }
      

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                stefanutti Antonin Stefanutti
              • Votes:
                7 Vote for this issue
                Watchers:
                15 Start watching this issue

                Dates

                • Created:
                  Updated: