[cdi-dev] [JBoss JIRA] (CDI-414) Support for "self" injection or intercepted self invocation

Mark Struberg (JIRA) issues at jboss.org
Thu Feb 18 04:15:02 EST 2016


    [ https://issues.jboss.org/browse/CDI-414?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13164754#comment-13164754 ] 

Mark Struberg commented on CDI-414:
-----------------------------------

To further clarify what Jozef (assumingly) means: There are 2 technically possible ways
1.) split this out into 2 different chains
 1.a.) a general interceptor proxy (as we have today) for all class level outside invocations
 1.b.) an own subclassing proxy for all self interceptors. Maybe we even need an own subclass per interceptor.
2.) ThreadLocals to transport the info of a 'local' call. That totally trashes concurrency, and thus a -1 to require it

I also think that the self interception is _not_ a question for the whole proxy but rather for the interceptor itself? or even for the interceptor + the class?
You probably like to apply a generic log interceptor from 'outside' and just like to trigger the @Transactional for your locally invoked method?

Not sure it is really worth all the hassle. At the end this feature is _very_ rarely used. Of course it IS used and sometimes needed. But for those occasions there is the well-known pattern of simply using self-injection manually.

We would also need to take a very close look at @PostConstruct and @PreDestroy as those are per definition trigger different interceptor mechanics.

PS: 'business method' _is_ a well defined term in the EJB spec.

> Support for "self" injection or intercepted self invocation
> -----------------------------------------------------------
>
>                 Key: CDI-414
>                 URL: https://issues.jboss.org/browse/CDI-414
>             Project: CDI Specification Issues
>          Issue Type: Bug
>          Components: Resolution
>            Reporter: arjan tijms
>             Fix For: 2.0 (discussion)
>
>
> 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.
> {code}
> @Stateless
> public class Foo {
>     @EJB
>     private Foo self;
>     // ...
> }
> {code}
> 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:
> {noformat}
> WELD-001443 Pseudo scoped bean has circular dependencies.
> {noformat}
> 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).



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the cdi-dev mailing list