private Optional<Node> lookupGlobalComponent(Key<?> key) {
        if (!(key.getTypeLiteral().getType() instanceof Class)) {
            throw new RuntimeException("Type not supported " + key.getTypeLiteral());
        }
        Class<?> clazz = key.getTypeLiteral().getRawType();

        Collection<ComponentNode> components = matchingComponentNodes(nodes(), key);
        if (components.isEmpty()) {
            return Optional.empty();
        } else if (components.size() == 1) {
            return Optional.ofNullable(Iterables.get(components, 0));
        } else {

            var nonProviderComponents = components.stream().filter(c -> !Provider.class.isAssignableFrom(c.instanceType())).toList();
            if (nonProviderComponents.isEmpty()) {
                throw new IllegalStateException("Multiple global component providers for class '" + clazz.getName() + "' found :" + components);
            } else if (nonProviderComponents.size() == 1) {
                return Optional.of(nonProviderComponents.get(0));
            } else {
                throw new IllegalStateException("Multiple global components with class '" + clazz.getName() + "' found : " + nonProviderComponents);
            }
        }
    }
@author Tony Vaagenes
@author gjoranv
@author ollivir

Not thread safe.
container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentGraph.java