Guice does not do object lifecycle. It's a thing. AFAIK Guice (by
design) does not ship @AfterInjection/@PostConstruct or similar
things, but provides you the tools to implement that. I am not sure
of the restrictions imposed by GIN/GWT.
So, If injection listener & friends don't work for you then you have
other options.
(Option 1) Use a provider method to fake it. Bind the real instances
with an annotation and use a provider method to intercept the
constructed & injected class before it is delivered to your
application. You can also write your own provider which does the same
thing. Consider in your module
@Provides Foo provideFoo(@Named("module-internal) Foo foo) {
foo.init();
return foo;
}
(Option 2) Guice specifies the order that it does injection. I
believe it's constructor, member, method. So if you were comfortable
using member injection in your super class, then just mark your init
method with @Inject and you should be good to go. Something like
@Inject init(String s) // maybe the string is not required.
Of course this only guarantees that the superclass injection is done.
If you have methods in derived classes also annotated with @Inject, I
don't believe there is a defined order (although there may be).
-dg
On Feb 28, 12:53 am, David Nouls <[email protected]> wrote:
> Hi,
>
> That will not work with GIN/GWT.
>
> David
>
>
>
>
>
>
>
> On Monday, February 27, 2012 2:52:00 PM UTC+1, Marko Lavikainen wrote:
> > This is probably your answer:
>
> >http://code.google.com/p/mycila/wiki/MycilaGuice
>
> > On 27 helmi, 11:53, David Nouls <[email protected]> wrote:
> > > Hi,
>
> > > I'm looking for a feature in Guice (and GIN) that allows me to call a
> > > method after injection has been done on an object.
> > > I found a blogpost that gives me a solution, but is really a cludge for
> > > something that should be somehow part of Guice.
>
> > >http://cristianvrabie.blogspot.com/2009/11/simulate-bean-initializati...
>
> > > <http://cristianvrabie.blogspot.com/2009/11/simulate-bean-initializati...>
>
> > > What I need is some kind of way to mark a method that needs to be
> > invoked
> > > when construction, member and setter injections have been performed.
>
> > > I don't want to add some maybeInitialize method and call that from
> > > everywhere in the object since that will bring in multithreading issues.
>
> > > I can not/do not want to use constructor injection because in my case I
> > > have a baseclass that need injections but I don't want to polute the
> > > derived classes to also have to call super( ... ). This would basically
> > > expose the internals of the root class.
>
> > > David
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.