Skip to content

Commit

Permalink
Ensure bindings must not fail if no descriptor discovered, as there m…
Browse files Browse the repository at this point in the history
…ay be a service that requires a dependency, but itself is not required by any injection point.
  • Loading branch information
tomas-langer committed Dec 17, 2024
1 parent 59eaa0f commit 5f8f56c
Showing 1 changed file with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private DependencyBinding(CoreServiceRegistry registry, ServiceInfo serviceInfo,
.build();
}

public List<ServiceInfo> descriptors() {
List<ServiceInfo> descriptors() {
return serviceInfos;
}

Expand Down Expand Up @@ -269,19 +269,12 @@ private List managers(List<ServiceInfo> serviceInfos) {

private void discoverBinding() {
// lookup services, exclude ourselves (when doing chained injection, we lookup by weight)
List<ServiceInfo> found = registry.lookupServices(lookup)
// we need all service descriptors, as a service may not yield a service
// (such as optional suppliers, ServicesFactory etc.), so we use the next one
this.serviceInfos = registry.lookupServices(lookup)
.stream()
.filter(it -> it != serviceInfo)
.collect(Collectors.toList());
if (found.isEmpty() && (dependency.cardinality() == DependencyCardinality.REQUIRED)) {
throw new ServiceRegistryException("There is no service in registry that satisfied this dependency: "
+ dependency);
}

// we need all service descriptors, as a service may not yield a service
// (such as optional suppliers, ServicesFactory etc.), so we use the next one

this.serviceInfos = found;
}

private static class DependencySupplier implements Supplier<Object> {
Expand Down

0 comments on commit 5f8f56c

Please sign in to comment.