You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@onami.apache.org by Jochen Wiedmann <jo...@gmail.com> on 2014/04/09 15:46:15 UTC

[lifecycle] @PostConstruct invocation deferred

Hi,

after studying the sources of the LifecycleModule, I get the impression
that Onami suffers from the same problem than similar Guice extensions do:
They all work by registering a TypeListener (the LifecycleModule), which in
turn registers an InjectionListener. The injection listeners method
"afterInjection" is responsible for invocation of the annotated start
method.

The problem with that approach is that "afterInjection" is, by default,
invoked when Guice is actually creating the object. And Guice does so,
when, or even if, the injectors user requests the object. This may be
perfectly valid according to the specifications, but it is not what I'd
assume to be LifeCycle handling. I'd like to see that objects annotated
with @PostConstruct (or whatever other annotation) are started immediately.

What do others think?

Thanks,

Jochen


-- 
"That's what prayers are ... it's frightened people trying to make friends
with the bully!"

Terry Pratchett. The Last Hero

Re: [lifecycle] @PostConstruct invocation deferred

Posted by Jochen Wiedmann <jo...@gmail.com>.
On Thu, Apr 10, 2014 at 8:17 AM, Stephan Classen <st...@gmx.ch> wrote:

> What do you mean by started immediately?
> Right after the application is started and the injector has been built?
>

This one, of course.

Re: [lifecycle] @PostConstruct invocation deferred

Posted by Stephan Classen <st...@gmx.ch>.
What do you mean by started immediately?
Right after the application is started and the injector has been built?
Or right after the constructor, before field and setter injection?


On 04/09/2014 03:46 PM, Jochen Wiedmann wrote:
>
> Hi,
>
> after studying the sources of the LifecycleModule, I get the 
> impression that Onami suffers from the same problem than similar Guice 
> extensions do: They all work by registering a TypeListener (the 
> LifecycleModule), which in turn registers an InjectionListener. The 
> injection listeners method "afterInjection" is responsible for 
> invocation of the annotated start method.
>
> The problem with that approach is that "afterInjection" is, by 
> default, invoked when Guice is actually creating the object. And Guice 
> does so, when, or even if, the injectors user requests the object. 
> This may be perfectly valid according to the specifications, but it is 
> not what I'd assume to be LifeCycle handling. I'd like to see that 
> objects annotated with @PostConstruct (or whatever other annotation) 
> are started immediately.
>
> What do others think?
>
> Thanks,
>
> Jochen
>
>
> -- 
> "That's what prayers are ... it's frightened people trying to make 
> friends with the bully!"
>
> Terry Pratchett. The Last Hero
>