You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Eric Chatellier <ch...@codelutin.com> on 2012/05/09 12:52:17 UTC
Injection of objet created by interceptor (per request)
Hi,
I'm currently using openejb 4.0 as embedded ejb container.
I'm also trying to find a proper way to create object
in interceptor and getting access to them in EJB.
Is there any way to:
- create an object (in this case a transaction to a custum persistence framefork)
- put it somewhere
- inject it on EJB using @Inject or @Resource
Note: the created object must be unique per transaction, so can't be
defined in container configuration.
Thanks in advance.
--
Éric Chatellier <ch...@codelutin.com>
Tel: 02.40.50.29.28
http://www.codelutin.com
Re: Injection of objet created by interceptor (per request)
Posted by David Blevins <da...@gmail.com>.
On May 9, 2012, at 3:52 AM, Eric Chatellier wrote:
> Hi,
>
> I'm currently using openejb 4.0 as embedded ejb container.
>
> I'm also trying to find a proper way to create object
> in interceptor and getting access to them in EJB.
>
> Is there any way to:
> - create an object (in this case a transaction to a custum persistence framefork)
> - put it somewhere
> - inject it on EJB using @Inject or @Resource
>
> Note: the created object must be unique per transaction, so can't be
> defined in container configuration.
Some usage of CDI @RequestScoped is probably what is in order here.
http://openejb.apache.org/examples-trunk/cdi-request-scope
Depending on what the interceptor is doing, you might not even need it. Everything in RequestScoped is created automatically the first time it is used in the request, so if the interceptor is just creating things in the request you probably won't even need it.
-David
Re: Injection of objet created by interceptor (per request)
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Why isn't it elegant? If you don't use async mecanism and/or start new
thread that's common. Moreover
in the interceptor you can clean the thread local (in a finally) so no
memory leak.
That's the way commonly used for security if i'm not mistaken.
- Romain
2012/5/9 Eric Chatellier <ch...@codelutin.com>
> Le 09/05/2012 12:54, Romain Manni-Bucau a écrit :
> > Hi,
> >
> > isn't ThreadLocal adapted?
> It's working.
> It was my first working solution.
>
> But i'm wondering, if it's really safe ?
>
> And it doesn't seems to be an elegant solution :D
> >
> > if you really want to use @Inject because that's fancy or because that's
> > the API you want to expose you can @Produces a proxy looking in your
> > threadlocal.
> I will chech @Produces... but still threadlocal :-(
>
> Thanks.
>
> --
> Éric Chatellier <ch...@codelutin.com>
> Tel: 02.40.50.29.28
> http://www.codelutin.com
>
>
Re: Injection of objet created by interceptor (per request)
Posted by Eric Chatellier <ch...@codelutin.com>.
Le 09/05/2012 12:54, Romain Manni-Bucau a écrit :
> Hi,
>
> isn't ThreadLocal adapted?
It's working.
It was my first working solution.
But i'm wondering, if it's really safe ?
And it doesn't seems to be an elegant solution :D
>
> if you really want to use @Inject because that's fancy or because that's
> the API you want to expose you can @Produces a proxy looking in your
> threadlocal.
I will chech @Produces... but still threadlocal :-(
Thanks.
--
Éric Chatellier <ch...@codelutin.com>
Tel: 02.40.50.29.28
http://www.codelutin.com
Re: Injection of objet created by interceptor (per request)
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,
isn't ThreadLocal adapted?
if you really want to use @Inject because that's fancy or because that's
the API you want to expose you can @Produces a proxy looking in your
threadlocal.
- Romain
2012/5/9 Eric Chatellier <ch...@codelutin.com>
> Hi,
>
> I'm currently using openejb 4.0 as embedded ejb container.
>
> I'm also trying to find a proper way to create object
> in interceptor and getting access to them in EJB.
>
> Is there any way to:
> - create an object (in this case a transaction to a custum persistence
> framefork)
> - put it somewhere
> - inject it on EJB using @Inject or @Resource
>
> Note: the created object must be unique per transaction, so can't be
> defined in container configuration.
>
> Thanks in advance.
>
> --
> Éric Chatellier <ch...@codelutin.com>
> Tel: 02.40.50.29.28
> http://www.codelutin.com
>
>