On Fri, Feb 18, 2011 at 8:07 AM, deanhiller <[email protected]>wrote:

> Last night, I tried doing creating a CustomProvider BUT then Guice is
> not injecting my CustomProvider with fields that have @Inject in my
> objects that get created(I was hoping Guice intercepted them and
> created them on-demand).  Is there a way to make this work....
>

How do you choose which implementation to ask for? I'd probably use a
binding annotation instead of setting a thread local.

To make your code work:

public class ListenerProvider implements Provider<OurCacheListener> {

  private static ThreadLocal<Class<?>> clazzThreadLocal =
        new ThreadLocal<Class<?>>();

  @Inject private Injector injector;

  @Override
  public OurCacheListener get() {
*     return (OurCacheListener)
injector.getInstance(clazzThreadLocal.get());*
  }

  public static void setType(Class<?> clazz2) {
     clazzThreadLocal.set(clazz2);
  }
}

-- 
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.

Reply via email to