You can also create an injection listener which allows you to modify any
object that gets created by Guice.

Here is an example in scala that adds every object to a guava event bus:
     bindListener(Matchers.any, new TypeListener {
       def hear[I](typeLiteral: TypeLiteral[I], typeEncounter:
TypeEncounter[I]) {
         val eventBus = typeEncounter.getProvider(classOf[EventBus])

         typeEncounter.register(new InjectionListener[I] {
           def afterInjection(instance: I) {
             eventBus.get().register(instance)
           }
         })
       }
     })

You can use different type matchers if you want to narrow the scope of what
types are found.

Please note that the injection will only occur on public objects for that
module only. So if you have a private module A and a public module B and
this is defined in B. Then only the publicly exposed objects in A can be
found by the listener. Thus, it can be tricky if you want to do something
to every object, even those that may not be public.

On Tue, Apr 1, 2014 at 3:09 AM, Stephan Classen <[email protected]> wrote:

>  You could use setter injection and have the properties injected into the
> bean.
>
>
>
>
> On 04/01/2014 10:03 AM, Jochen Wiedmann wrote:
>
>
> Hi,
>
> I'd like to be able to set certain properties when (or immediately after)
> a bean is created by Guice. Is that possible? How?
>
> Thanks,
>
> Jochen
>
>  --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/google-guice.
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/google-guice.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.

Reply via email to