Something is amiss with the ThreadLocal scope implementation below.
Can someone please explain what am I missing? I am seeing the Scope
applied only the first time I request the instance of a Entity
decorated entity.
Thanks in advance,
Rahul
-------------- code snippet below -------------
public class ThreadLocalScope implements Scope {
public static final ThreadLocal<Provider<?>> threadlocal = new
ThreadLocal<Provider<?>>();
@Override
public <T> Provider<T> scope(Key<T> key, final Provider<T> unscoped)
{
System.out.println("Scoping " + key.toString());
Provider<T> retVal = null;
if (null != threadlocal.get()) {
retVal = (Provider<T>) threadlocal.get();
} else {
retVal = new Provider<T>() {
@Override
public T get() {
return unscoped.get();
}
};
threadlocal.set(retVal);
}
return retVal;
}
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---