final InternalFactory<? extends T> factory = getInternalFactory(key, errors);
final Dependency<T> dependency = Dependency.get(key);
return new Provider<T>() {
public T get() {
final Errors errors = new Errors(dependency);
try {
T t = callInContext(new ContextualCallable<T>() {
public T call(InternalContext context) throws ErrorsException {
context.setDependency(dependency);
try {
return factory.get(errors, context, dependency);
} finally {
context.setDependency(null);
}
}
});
errors.throwIfNewErrors(0);
return t;
} catch (ErrorsException e) {
throw new ProvisionException(errors.merge(e.getErrors()).getMessages());
}
}
@Override public String toString() {
return factory.toString();