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

Antonio Goncalves (JIRA) issues at jboss.org
Mon Sep 15 08:12:03 EDT 2014


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

Antonio Goncalves commented on CDI-414:
---------------------------------------

BTW, nowhere in the Interceptor 1.2 spec we find the word "proxy" or "public vs private method" interception. Interceptor 1.2 does not really specify that only private methods should not be intercepted. On the other hand, the specification uses the term *business method*. No definition of what a *business method* is in the Interceptor spec. But because interceptors come from the EJB world, if we look at the EJB spec, we can read : 

{quote}
3.2 - Local, Remote, and Web Service Client Views

The term business method is used to refer to a method of an enterprise bean that is available for client execution. It may be a method exposed by the local or remote business interface, by the no-interface view, by the local component interface, by the remote component interface, or by the web service client view.
{quote}

So, in the EJB 3.2 spec it is clearly said that private method are not intercepted, but it's not clear in Interceptor 1.2

> Support for "self" injection
> ----------------------------
>
>                 Key: CDI-414
>                 URL: https://issues.jboss.org/browse/CDI-414
>             Project: CDI Specification Issues
>          Issue Type: Bug
>          Components: Resolution
>            Reporter: arjan tijms
>
> 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.3.1#6329)


More information about the cdi-dev mailing list