1 Reply Latest reply on Mar 19, 2010 7:47 AM by Nicklas Karlsson

    Mixing scopes and static vs. dynamic injection

    Arbi Sookazian Master

      From SiA, section 6.2.3:

      What would
      happen if a request-scoped variable were to be injected into a session-scoped object
      via static DI? Recall that static DI occurs only once: when the object is created. In this
      situation, as the request-scoped variable changes between HTTP requests, the sessionscoped
      object retains the original value of the request-scoped variable and never gets
      updated. This describes the behavior of most other IoC containers in existence today.
      By using Seam’s dynamic DI, the same property on a session-scoped component would
      always reflect the value of the request-scoped variable from the current request
      because the injection is reapplied each time the component is invoked. Additionally,
      the value isn’t retained beyond the end of the request since Seam breaks the reference
      by disinjecting the value once the method call is complete.

      IIRC, @Inject is used in Weld/EE6 apps and it's static injection on objection instantiation (similar to Spring's constructor injection).

      So what happens in the above scenario?  The request-scoped values that are injected will be stale in the session-scoped component?  Is that true in Weld and what is the workaround if so?