@Override public <T> Provider<T> scope(Key<T> key, Provider<T> unscoped) { return () -> { Context context = contextRef.get(); if (null != context) { @SuppressWarnings("unchecked") T t = (T) context.objectsMap.get(key); if (t == null) { t = unscoped.get(); if (!Scopes.isCircularProxy(t)) { context.objectsMap.put(key, t); } } return t; } else { throw new OutOfScopeException("Not currently in a document scope"); } }; }