Ebean and CDI

99 views
Skip to first unread message

Pavel Arnošt

unread,
May 6, 2012, 6:01:34 PM5/6/12
to eb...@googlegroups.com
Hi,

would it be difficult to add Contexts and Dependency Injection (CDI - JSR 299) support to Ebean? I looked at Struts2 CDI plugin and it seems quite simple:


Process is described at http://docs.jboss.org/weld/reference/latest/en-US/html/extend.html, in sections 16.4 there is an short example.

Is there some type of factory in Ebean that can be extended?

Regards,
Pavel Arnost

Josh Kamau

unread,
May 6, 2012, 6:10:44 PM5/6/12
to eb...@googlegroups.com
Am already using Ebean in a CDI environment ... I just call Ebean.someMethod() ... And it just works.  

Josh.

Rob Bygrave

unread,
May 6, 2012, 9:58:20 PM5/6/12
to eb...@googlegroups.com
I'm pretty sure he wants to inject a EbeanServer instance rather than use the Ebean singleton.

Pavel, have a look at the Ebean spring integration. Yes there is a EbeanServerFactory that creates EbeanServer instances.


Cheers, Rob.

Pavel Arnošt

unread,
May 7, 2012, 4:04:56 AM5/7/12
to eb...@googlegroups.com
Hi,

thanks for replies. I have meant injecting domain/entity beans that EbeanServer returns, e.g. I would like to inject instances of class User with MailService ApplicationScoped bean.

Regards,
Pavel

Rob Bygrave

unread,
May 7, 2012, 4:21:11 AM5/7/12
to eb...@googlegroups.com
To clarify,  do you mean injecting an application scoped bean (MailService) into a domain/entity bean (User)  ... so mailService is a transient field of the User entity bean?

Pavel Arnošt

unread,
May 7, 2012, 6:31:57 AM5/7/12
to eb...@googlegroups.com
Yes, exactly.

edge

unread,
May 7, 2012, 6:41:45 AM5/7/12
to eb...@googlegroups.com
I wouldn't recommend injecting application beans into entities - rather use services to manipulate your beans.
There is no really nice way of injecting beans into you entities as Ebean is creating them - you can of course use an AOP (e.g. AspectJ) to do this but again from experience I wouldn't recommend it.


On Monday, May 7, 2012 12:31:57 PM UTC+2, Pavel Arnošt wrote:
Yes, exactly.

Pavel Arnošt

unread,
May 10, 2012, 10:46:28 AM5/10/12
to eb...@googlegroups.com
I used AspectJ weaving with Spring's @Configurable annotation in the past occasionally and I would like to try CDI as more "standard" approach. Because I have found more discouraging posts about injecting entities with application beans, I will not go against the flow and I will use other objects for injections. Thanks for making it more clear to me.

Regards,
Pavel
Reply all
Reply to author
Forward
0 new messages