aspakh / google-gin

Automatically exported from code.google.com/p/google-gin
Apache License 2.0
0 stars 0 forks source link

Support for @PostConstruct #176

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Support for JSR250 @PostConstruct is missing.
Review submited.

Original issue reported on code.google.com by olivier....@gmail.com on 15 May 2012 at 3:29

GoogleCodeExporter commented 8 years ago
At https://groups.google.com/forum/?fromgroups=#!topic/google-gin/ZeS_9NeoJD0 
some time ago Peter said
"I think what you are looking for are features like injection listeners that 
allow GuiceyFruit to interact with Guice. We should be able to provide 
something like this (or at least something similar) for Gin and then you could 
build an extension that uses them to implement JSR250 annotations."

A guy also claimed having implemented something similar at 
https://groups.google.com/d/msg/google-guice/oguaN8gDwCo/m_a5OiMK9IsJ

So what's the best way to execute some initialization code on a few beans only 
after injected completed but before the application starts?

Original comment by davide.cavestro on 10 May 2013 at 4:03

GoogleCodeExporter commented 8 years ago
I don't see this being added without Guice chooses to do so:
  https://code.google.com/p/google-guice/issues/detail?id=62

In the trunk version of GIN, if you put @Inject on a method, that will be 
called after constructor and field injection.
Of course it will not be guaranteed to be executed last if you have multiple 
methods with @Inject but it can get you going with a convention to not use 
method injection other hand this purpose.

Original comment by gok...@google.com on 10 May 2013 at 5:58

GoogleCodeExporter commented 8 years ago
I see... I just left a comment on the guice issue you linked as a backref... 
and also to let them know GIN waits for that feature :-) see 
https://code.google.com/p/google-guice/issues/detail?id=62#c110

Cheers
Davide

Original comment by davide.cavestro on 10 May 2013 at 8:29

GoogleCodeExporter commented 8 years ago
One last question: is there any way for GNI to use guice extensions (like 
GuiceyFruit)?

Original comment by davide.cavestro on 11 May 2013 at 1:39

GoogleCodeExporter commented 8 years ago
At https://code.google.com/p/google-guice/issues/detail?id=62#c114 I got an 
interesting answer about GIN/guice extensions compatibility.
So - please correct me if I'm wrong - it seems it's only up to the GIN dev team 
deciding whether to support this feature or not (adapting lifecygle or other 
solutions).

Original comment by davide.cavestro on 14 May 2013 at 10:43

GoogleCodeExporter commented 8 years ago
Yes, it is up to us to add or not; but we usually keep Guice as a reference and 
try to keep compatible. That makes things easier.

@PostConstruct, @PreDestroy mostly makes sense with a higher level concept of 
life cycle and that is why Guice didn't add it as an extension and why it 
doesn't make sense for GIN to support it as a first class citizen.
It only make sense when a high level framework defines what the lifecycle means 
and then implement it on top GIN.

As I pointed earlier, you can use the constructor and field injection and then 
define init method with @Inject.

Original comment by gok...@google.com on 14 May 2013 at 11:26