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

Support for "self" injection or intercepted self invocation

    XMLWordPrintable

Details

    Description

      Many features of CDI and EJB work by means of a proxy that intercepts calls and adds 'aspects'. In Java it's however not possible to decorate the this pointer, so methods called on the same bean instance from within a method in the bean do not get their 'aspects' applied.

      This is a well known limitation, but in EJB it's possible to work around this by injecting a bean into itself. E.g.

      @Stateless
      public class Foo {
      
          @EJB
          private Foo self;
      
          // ...
      }
      

      Also see http://adam-bien.com/roller/abien/entry/how_to_self_invoke_ejb

      Unfortunately using CDI and @Inject this doesn't work. Weld for instance fails the deployment and logs:

      WELD-001443 Pseudo scoped bean has circular dependencies.
      

      See also: http://adam-bien.com/roller/abien/entry/inject_vs_ejb

      Although there are workarounds, it would be great if @Inject in combination with CDI could support self injection as well.

      With that projects migrating from @EJB to @Inject can do so more easily and the capability can be convenient for new projects as well (e.g. calling two separate @Transactional methods from a single method without being required to create a new bean).

      Attachments

        Activity

          People

            Unassigned Unassigned
            arjan.tijms@gmail.com Arjan Tijms (Inactive)
            Votes:
            11 Vote for this issue
            Watchers:
            16 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: