[JBoss JIRA] (CDI-414) Support for "self" injection
by arjan tijms (JIRA)
arjan tijms created CDI-414:
-------------------------------
Summary: 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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years
Re: [cdi-dev] Having an official CDI tutorial and user forum
by Antoine Sabot-Durand
Hi Radim,
Allow me to post my answer on the list so every body will benefit of your contribution.
> first of all I would like to let you know that I very appreciate your effort to promote my favourite technology :)
Thanks. I hope we’ll achieve to pursue this promotion effort. It’s always hard to mix highly conceptual technical activity like a spec and promotion / communication at the same time. My feeling is CDI is very overlooked and deserve a bigger community. Community that could help us making it better. Note that I’m not very objective on that topic ;).
> >> I think it would be useful to provide an official CDI 1.1 tutorial on cdi-spec site
> I agree with you a cdi tutorial with a plenty of quickstarts is desperately missing
> something like jboss way quickstarts would be a great addition to cdi-spec.org site
Yes JDF quick starts are nice (and also deal with Deltaspike) but need documentation to introduced them. [1]
Apache team have nice example for CDI as well on TomEE examples [2]
I also remember seeing interesting content on IBM developerworks. I can find them right now.
> >> I have the feeling such content is already nearly written by people in this ML
> recently I tried to find some details on how to properly use @ThreadScoped in java se environment and the only place where I found a working sample was this ML (http://lists.jboss.org/pipermail/weld-dev/2009-December/002016.html)
You may know threadscope is not in the spec, Its specific to Weld, I don’t know if OWB has something like that. Anyway, writing a tutorial on building a thread scope for all imll, could be interesting. Great to show how to add a new scope and promote CDI for SE at the same time.
>
> >> so if you have written introduction tutorial to CDI and agree to be reused on official site it would be great and time saving for me
> I have already written some CDI samples for my colleagues including the one mentioned above
> I would be pleased to supply these samples…
Great. We surely could benefit from them
>
> Sincerely,
> Radim Hanus
>
Thanks again for your commitment
Antoine
[1] http://www.jboss.org/jdf/quickstarts/get-started/
[2] http://tomee.apache.org/examples-trunk/index.html
>
>
>
> 2013/11/18 Antoine Sabot-Durand <antoine(a)sabot-durand.net>
> Hi all,
>
> First excuse my french in previous meeting invites. Obviously Google can speak english to you and keep sending french invitation ;).
>
> I launch this thread in reaction to the FUD or inaccuracies about CDI one can find on the web like this post [1]).
>
> As the spec is quite long to read and very theoretic, I think it would be useful to provide an official CDI 1.1 tutorial on cdi-spec site. It could allows us to be sure that people have an official overview of the spec and could be enhanced with use cases we would encounter on the web (stack overflow or other).
> I have the feeling such content is already nearly written by people in this ML, so if you have written introduction tutorial to CDI and agree to be reused on official site it would be great and time saving for me.
>
> In the same idea of community federation, I think it could be useful to launch a forum (Google group or other) to allow people to ask informal question about CDI and its eco system. People starting using CDI or casual users won’t use this mailing list and all of them think to use site like Stack Overflow. It would also a good mean to enhance our FAQ.
>
> What do you think ?
>
>
> Antoine
>
>
>
> [1] http://blog.frankel.ch/my-case-against-autowiring
> _______________________________________________
> cdi-dev mailing list
> cdi-dev(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/cdi-dev
>
11 years