Thanks very much, Nate. Have to admit, however, that I don't really get how 
to apply that to my case.

Asssuming, I;ve got these classes:

public interface IFoo {
    void setBar(String pValue;
    String getBar();
}
public class FooImpl implements IFoo {
   private String bar;  // Setter and Getter for bar
}

And my Module contains, in particular:

   binder.bind(IFoo.class).to(FooImpl.class).in(Scopes.SINGLETON);

How would I ensure that my singleton contains a particular value for "bar"?



On Tuesday, April 1, 2014 6:34:53 PM UTC+2, Nate Bauernfeind wrote:
>
> 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 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] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> 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] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> 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