You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Hugi Thordarson <hu...@karlmenn.is> on 2017/02/09 09:44:37 UTC

Using my own ObjectContext class

Hi all,
what is the proper way to have ServerRuntime.newContext() return my own implementation of ObjectContext? (inheriting from DataContext). Any reason why that would be discouraged?

Cheers,
- hugi

Re: Using my own ObjectContext class

Posted by Hugi Thordarson <hu...@karlmenn.is>.
Thanks Nikita!

- hugi


> On 9. feb. 2017, at 10:21, Nikita Timofeev <nt...@objectstyle.com> wrote:
> 
> Hi Hugi,
> 
> The "official" way to override newContext() result is to implement
> your own ObjectContextFactory and inject it via custom Module.
> 
> You can do it like this:
> 
> ServerRuntime cayenneRuntime = ServerRuntime.builder("cayenne-project.xml")
>        .addModule(binder ->
> binder.bind(ObjectContextFactory.class).to(MyObjectContextFactory.class))
>        .build();
> 
> You may also want to extend your ObjectContextFactory implementation
> from DataContextFactory and just override newInstance(...) method.
> 
> Hope this helps!
> 
> On Thu, Feb 9, 2017 at 12:44 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>> Hi all,
>> what is the proper way to have ServerRuntime.newContext() return my own implementation of ObjectContext? (inheriting from DataContext). Any reason why that would be discouraged?
>> 
>> Cheers,
>> - hugi
> 
> -- 
> Best regards,
> Nikita Timofeev


Re: Using my own ObjectContext class

Posted by Nikita Timofeev <nt...@objectstyle.com>.
Hi Hugi,

The "official" way to override newContext() result is to implement
your own ObjectContextFactory and inject it via custom Module.

You can do it like this:

ServerRuntime cayenneRuntime = ServerRuntime.builder("cayenne-project.xml")
        .addModule(binder ->
binder.bind(ObjectContextFactory.class).to(MyObjectContextFactory.class))
        .build();

You may also want to extend your ObjectContextFactory implementation
from DataContextFactory and just override newInstance(...) method.

Hope this helps!

On Thu, Feb 9, 2017 at 12:44 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> Hi all,
> what is the proper way to have ServerRuntime.newContext() return my own implementation of ObjectContext? (inheriting from DataContext). Any reason why that would be discouraged?
>
> Cheers,
> - hugi

-- 
Best regards,
Nikita Timofeev