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 11:13:07 GMT


Hello,

You mean in order to use DI you should add a custom runtime class extending CayenneRuntime.
I think it is too much work just to use DI. DI should not be an add-on feature. It should
be more integrated into the cayenne stack. Anyway, I found a way to use DI. 
One more thing; I want to inject beans into the cayenne entity beans. In order to do this,
I added a listener class;

public class CayenneListener {

 public void onPostLoad(Object entity) {

       if ( !(entity instanceof Injectable) ) {
             return;
       }
       inject((Injectable)entity);
 };
 
 public void onPostAdd(Object entity) {

     if ( !(entity instanceof Injectable) ) {
          return;
     }
  
  Injectable injectable = (Injectable) entity;
  inject(injectable);
  injectable.onPostAdd();
 }
 
 private void inject(Injectable entity) {
  ServerRuntime.getThreadInjector().injectMembers(entity);
 }
}


In this class I injected bean into an entity object which is injectable. I think this is
a right way to do injection??. Again, I wish this entity injection mechanism was more integrated
into Cayenne stack.

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

Hi, 

Actually if you don't want to extend Cayenne, you shouldn't even care about DI. Once you obtain
an ObjectContext, you use it as before. 

If you do need to extend/configure Cayenne, then you'll create a custom module and pass it
to ServerRuntime in constructor. If you have a specific scenario, I can provide a more detailed
example.

Andrus


On Mar 7, 2011, at 1:45 PM, Erdinc wrote:

> Hi,
>  
> I want try to use DI feature of Cayenne but having difficulty to find a good way to use.
My application is a standalone application.
> I created runtime with the command;
> ServerRuntime = new ServerRuntime("cayenne-X.xml");
> I think I have to implement the "configure" method of a Module object and use the Binder
class. ServerRuntime creates a default module,
> but I cant extend it. Do I need to add additional modules or inherit from CayenneRuntime
instead of ServerRuntime or is there any better way to do this simple task??
> An example in docs would be greatly appreciated.
>  
> Thanks,
>  
> ---------------------------------------------------
> http://www.nofailtime.com 
> Application monitoring
> ---------------------------------------------------
> 
> 
> 


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