First you need to subclass the factory:

public class MyContextFactory extends DataContextFactory {
    @Override
    protected DataContext newInstance(DataChannel parent, ObjectStore
objectStore) {
    return new MyContext(parent, objectStore);
    }
}

Then, create a custom Dependency Injector module:

import org.apache.cayenne.configuration.ObjectContextFactory;
import org.apache.cayenne.di.Binder;
import org.apache.cayenne.di.Module;

public class AppModule implements Module {
public void configure(Binder binder) {
binder.bind(ObjectContextFactory.class).toInstance(new MyContextFactory());
}
}

Then reference your module when creating the CayenneRuntime:

 ServerRuntime localRuntime = new
ServerRuntime("cayenne-MyDomain.xml", newAppModule());

John
On Thu, Feb 23, 2012 at 11:28 AM, Bruno René Santos <[email protected]>wrote:

> Hello all,
>
> I am trying to migrate my web application from 3.0.1 to 3.1M3. My main
> problem now is that I usually use a custom DataContext in my Apps. In 3.0.1
> I would use the DataContextFactory (defined on the modeler) to configure
> the use of the custom class. How do I do that on 3.1?
>
> Regards
> Bruno
>

Reply via email to