You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Ramiro Aparicio <ra...@prot-on.com> on 2012/10/04 20:16:41 UTC

DI in 3.1

Hi,
I am back again with some questions, after migrating to 3.1 it seems 
almost everything is working as it should except timed task, this kind 
of process is timed using spring and does not pass throught 
CayenneFilter and there is no context attached, so I need to be able to 
create context on demand for those cases and that is changed to DI in 
3.1 wich is undocummented afaik, I have tried with:
     @Inject
     private Injector injector;
  and then:
             DataContext context = (DataContext) 
injector.getInstance(ObjectContextFactory.class).createContext();
but injector is not injected, so right now I am out of options, can 
someone point me how Cayenne DI is working or how can I create a new 
context at 3.1?

Thanks in advance for the help.

Ramiro Aparicio


Re: DI in 3.1

Posted by Ramiro Aparicio <ra...@prot-on.com>.
Thank you!
Got it working without problems.

El 05/10/2012 8:50, Andrus Adamchik escribió:
> Hi,
>
> The entry point to Cayenne in 3.1 is ServerRuntime. If you already have CayenneFilter elsewhere in the application, it means ServerRuntime is already created and can be retrieved by your code outside of HttpRequest:
>
> ServletContext servletContext = // you can get this one during app initialization (or maybe Spring can inject it?)
> CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);
> ObjectContext newContext = runtime.getContext();
>
> Andrus
>
> On Oct 4, 2012, at 9:16 PM, Ramiro Aparicio <ra...@prot-on.com> wrote:
>
>> Hi,
>> I am back again with some questions, after migrating to 3.1 it seems almost everything is working as it should except timed task, this kind of process is timed using spring and does not pass throught CayenneFilter and there is no context attached, so I need to be able to create context on demand for those cases and that is changed to DI in 3.1 wich is undocummented afaik, I have tried with:
>>     @Inject
>>     private Injector injector;
>> and then:
>>             DataContext context = (DataContext) injector.getInstance(ObjectContextFactory.class).createContext();
>> but injector is not injected, so right now I am out of options, can someone point me how Cayenne DI is working or how can I create a new context at 3.1?
>>
>> Thanks in advance for the help.
>>
>> Ramiro Aparicio
>>
>>


Re: DI in 3.1

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi,

The entry point to Cayenne in 3.1 is ServerRuntime. If you already have CayenneFilter elsewhere in the application, it means ServerRuntime is already created and can be retrieved by your code outside of HttpRequest:

ServletContext servletContext = // you can get this one during app initialization (or maybe Spring can inject it?)
CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);
ObjectContext newContext = runtime.getContext();

Andrus

On Oct 4, 2012, at 9:16 PM, Ramiro Aparicio <ra...@prot-on.com> wrote:

> Hi,
> I am back again with some questions, after migrating to 3.1 it seems almost everything is working as it should except timed task, this kind of process is timed using spring and does not pass throught CayenneFilter and there is no context attached, so I need to be able to create context on demand for those cases and that is changed to DI in 3.1 wich is undocummented afaik, I have tried with:
>    @Inject
>    private Injector injector;
> and then:
>            DataContext context = (DataContext) injector.getInstance(ObjectContextFactory.class).createContext();
> but injector is not injected, so right now I am out of options, can someone point me how Cayenne DI is working or how can I create a new context at 3.1?
> 
> Thanks in advance for the help.
> 
> Ramiro Aparicio
> 
>