@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"); } }; }
@Override public void close() { if (isClosed()) { throw new ClosedInjectorException(this); } for (Key<?> key : delegate.getAllBindings().keySet()) { try { com.google.inject.Binding<?> binding = delegate.getExistingBinding(key); if (!Scopes.isSingleton(binding)) { continue; } invokeAnnotatedMethod(binding.getProvider().get(), PreDestroy.class); } catch (ProvisionException pe) { if (!(pe.getCause() instanceof TypeNotFoundException)) { pe.printStackTrace(); } } } synchronized (lock) { closed = true; } }