cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erdinc <kocam...@yahoo.com>
Subject Re: DI example
Date Tue, 08 Mar 2011 12:11:47 GMT
I didn't have clear understanding of what runtime or module is. Thank you for your reply.


From: Andrus Adamchik <andrus@objectstyle.org>
To: user@cayenne.apache.org
Sent: Tuesday, March 8, 2011 1:30 PM
Subject: Re: DI example


On Mar 8, 2011, at 1:13 PM, Erdinc wrote:
> You mean in order to use DI you should add a custom runtime class extending CayenneRuntime.


No. Quite the contrary. There shouldn't be a need to extend CayenneRuntime (or ServerRuntime
for that matter). If you need to add new "services" or override the existing ones, you write
a custom module and pass it over to the runtime constructor. So extending Cayenne DI container
is trivial:

class MyModule implements Module {
  public void configure(Binder binder) { }
}

ServerRuntime r = new ServerRuntime("xyz-cayenne.xml", new MyModule());

> I want to inject beans into the cayenne entity beans. In order to do this, I added a
listener class;

Ok I see, Cayenne DI itself is not intended for that. I mean, you can use it for DataObject
injection, but this was not why we added it. So yeah, if you want to inject "services" in
your objects, use lifecycle callbacks. As a matter of fact 3.1M2 will help you a lot to implement
that. I am now writing a release announcement with some of this highlighted. But please take
a look at this page:

http://cayenne.apache.org/doc/guide-to-31-features.html#Guideto3.1Features-LifecycleExtensions


DataChannelFilter combined with @PostLoad/@PostAdd and a custom entity annotation should help
you with this. And maybe someday we'll add DataObject injection into cayenne-lifecycle extensions
module.

Andrus


      
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message