Yeah, one way is to reorg your code to make runtime accessible. An alternative
would be to register a custom ObjectContextFactory with DI that will provide
DataContext with access to runtime (or rather to org.apache.cayenne.di.Injector
that is the configuration engine inside Runtime):
class MyDataContextFactory extends DataContextFactory {
@Override
protected ObjectContext createdFromDataDomain(DataDomain parent) {
ObjectContext context = super. createdFromDataDomain(parent);
context.setUserProperty("injector", injector);
return context;
}
}
// create a peer ObjectContext:
Injector i = (Injector) context.getUserProperty("injector");
ObjectContext peerContext =
i.getInstance(ObjectContextFactory.class).createContext();
So that's an example of why DI is so cool (even in its current raw form) - you
can have direct access to any piece of configuration and can change its
behavior.
Andrus
On Feb 10, 2011, at 10:03 AM, Øyvind Harboe wrote:
> On Thu, Feb 10, 2011 at 3:57 PM, Andrus Adamchik <[email protected]>
> wrote:
>> Content is created by a "runtime" object (normally a ServerRuntime) :
>>
>> ObjectContext context = cayenneRuntime.getContext();
>>
>> See an example in tutorial's "Main" class.
>
> Can I get to the cayenneRuntime based on a datacontext
> class?
>
> Otherwise, I need to reorganize my program so as to push
> the cayenneRuntime to the far reaches of the code that needs
> it.
>
> --
> Øyvind Harboe
>
> Can Zylin Consulting help on your project?
>
> US toll free 1-866-980-3434 / International +47 51 87 40 27
>
> http://www.zylin.com/zy1000.html
> ARM7 ARM9 ARM11 XScale Cortex
> JTAG debugger and flash programmer
>