Oh and if you are on java 8 you can probably use a lambda, so I haven’t tried
myself yet:
new ServerRuntime(“cayenne-mydomain.xml”,
binder -> binder.bind(DataSourceFactory.class).toInstance(myFactory));
Andrus
On Aug 18, 2014, at 5:25 PM, Andrus Adamchik <[email protected]> wrote:
> 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 <[email protected]> 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.
>
>