Hi Tore,

Wrap it in a Module, and use bind .. toInstance:

Module m = new Module() {
   @Override
   public void configure(Binder binder) {
      binder.bind(DataSourceFactory.class).toInstance(myFactory);
   }
}

runtime = new ServerRuntime(“cayenne-mydomain.xml”, m);

Or if you are not averse to using nightly builds, use ServerRuntimeBuilder from 
3.2 master, that has “dataSource(DataSource ds)” method to set the DataSource 
explicitly [1].

Cheers,
Andrus

[1] 
https://github.com/apache/cayenne/blob/master/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeBuilder.java

On Aug 18, 2014, at 5:15 PM, Tore Halset <hal...@pvv.ntnu.no> wrote:

> Hello.
> 
> How should I inject a custom DataSourceFactory? I have tried this, but it 
> still try to use the DataSourceFactory in the model. This is going to have 
> multiple ServerRuntimes - one for each database.
> 
> runtime = new ServerRuntime(“cayenne-mydomain.xml");
>        runtime.getInjector().injectMembers(new DataSourceFactory() {
>            @Override
>            public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) 
> throws Exception {
>                return mything.getDataSource();
>            }
>        });
> 
> Regards,
> Tore Halset.

Reply via email to