Interface Dependency
- All Known Implementing Classes:
AbstractDependency, IndependentDependency, InjectionPointDependency
public interface Dependency
Defines a
TypeUsage for Dependency Injection with an Injector.- Since:
- Jan-2025
- Author:
- brian.oliver
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V> Optional<V> resolve(Dependency requested, Map<Dependency, V> candidates, build.codemodel.jdk.JDKCodeModel codeModel) Obtains the unique signature for theDependency, consisting of theTypeNameand anyAnnotationTypeUsages that have been annotated with theQualifiermeta-annotation.static StringsignatureOf(build.codemodel.foundation.usage.TypeUsage typeUsage, Stream<? extends build.codemodel.foundation.usage.AnnotationTypeUsage> qualifierAnnotations) Computes the canonical signature for aTypeUsageand a set of qualifierAnnotationTypeUsages, consisting of theTypeUsage'sTypeUsage.canonicalName()(recursively including any generic parameters) followed by the qualifier annotations, sorted and rendered so that the signature is stable regardless of the order in which the qualifiers were declared.build.codemodel.foundation.usage.TypeUsageObtains theTypeUsagefor theDependency.
-
Method Details
-
typeUsage
build.codemodel.foundation.usage.TypeUsage typeUsage()Obtains theTypeUsagefor theDependency.- Returns:
- the
TypeUsage
-
signature
String signature()Obtains the unique signature for theDependency, consisting of theTypeNameand anyAnnotationTypeUsages that have been annotated with theQualifiermeta-annotation.- Returns:
- the Signature for the
Dependency
-
signatureOf
static String signatureOf(build.codemodel.foundation.usage.TypeUsage typeUsage, Stream<? extends build.codemodel.foundation.usage.AnnotationTypeUsage> qualifierAnnotations) Computes the canonical signature for aTypeUsageand a set of qualifierAnnotationTypeUsages, consisting of theTypeUsage'sTypeUsage.canonicalName()(recursively including any generic parameters) followed by the qualifier annotations, sorted and rendered so that the signature is stable regardless of the order in which the qualifiers were declared.Anywhere two things must be recognized as the "same qualified type" (an
IndependentDependencyand aProvidesmethod it may resolve to, for example) must derive their signature from this method, so the two stay comparable.- Parameters:
typeUsage- theTypeUsagequalifierAnnotations- theQualifierAnnotationTypeUsages- Returns:
- the canonical signature
- Throws:
DuplicateQualifierException- if more than oneAnnotationTypeUsageof the same qualifier annotation type is present, making the signature ambiguous
-
resolve
static <V> Optional<V> resolve(Dependency requested, Map<Dependency, V> candidates, build.codemodel.jdk.JDKCodeModel codeModel) Looks up the value registered forrequestedincandidates, keyed byDependency. An exact key match (samesignature()) always wins outright. On a miss,candidatesis searched for theDependencywhose qualifiers matchrequested's exactly and whosetypeUsage()iscompatible- this is what lets a wildcard-bearing request (e.g.Class<? extends Base>orSet<? extends Base>) be satisfied by a registered candidate that doesn't match it exactly (e.g.Class<Impl>), without ever letting a wildcard-fallback candidate override an exact match, and without letting a differently-qualified (or unqualified) candidate silently satisfy a qualified request (e.g. an unqualifiedJDKVersionmust never satisfy a request for@System JDKVersion).- Type Parameters:
V- the type of value- Parameters:
requested- the requestedDependencycandidates- the candidates, keyed byDependencycodeModel- theJDKCodeModelused to check bound assignability- Returns:
- the resolved value, or
Optional.empty()if no candidate is compatible - Throws:
InjectionException- if more than one candidate is wildcard-compatible withrequested
-