Package io.micronaut.inject.qualifiers
Class Qualifiers
java.lang.Object
io.micronaut.inject.qualifiers.Qualifiers
Factory for
Bean
qualifiers.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Qualifier<T>
any()
Allows looking up the first matching instance.static <T extends Annotation>
Qualifier<T>byAnnotation
(AnnotationMetadata metadata, AnnotationValue<T> annotationValue) Build a qualifier for the given annotation value.static <T> Qualifier<T>
byAnnotation
(AnnotationMetadata metadata, Class<? extends Annotation> type) Build a qualifier for the given annotation.static <T> Qualifier<T>
byAnnotation
(AnnotationMetadata metadata, String type) Build a qualifier for the given annotation.static <T> Qualifier<T>
byAnnotation
(Annotation annotation) Build a qualifier for the given annotation.static <T> Qualifier<T>
byAnnotationSimple
(AnnotationMetadata metadata, String type) Build a qualifier for the given annotation.byExactTypeArgumentName
(@NonNull String typeName) Build a qualifier for the given generic type argument name.byInterceptorBinding
(@NonNull AnnotationMetadata annotationMetadata) Reduces bean definitions by the given interceptor binding.byInterceptorBindingValues
(@NonNull Collection<AnnotationValue<?>> binding) Reduces bean definitions by the given interceptor binding.static <T> Qualifier<T>
Build a qualifier for the given name.static <T> Qualifier<T>
byNamePrefix
(String prefix) Qualify by a prefix.static <T> Qualifier<T>
byQualifiers
(Qualifier<T>... qualifiers) Build a qualifier from other qualifiers.static <T> Qualifier<T>
byRepeatableAnnotation
(AnnotationMetadata metadata, String repeatableType) Builds a qualifier that uses the given repeatable annotation.static <T> Qualifier<T>
byStereotype
(Class<? extends Annotation> stereotype) Build a qualifier for the given annotation.static <T> Qualifier<T>
byStereotype
(String stereotype) Build a qualifier for the given annotation.static <T> Qualifier<T>
Build a qualifier for the given generic type arguments.static <T> Qualifier<T>
byTypeArguments
(Class<?>... typeArguments) Build a qualifier for the given generic type arguments.static <T> Qualifier<T>
byTypeArgumentsClosest
(Class<?>... typeArguments) Build a qualifier for the given generic type arguments.Finds a name in the provided qualifier.forArgument
(@NonNull Argument<?> argument) Build a qualifier for the given argument.static <T> Qualifier<T>
none()
Allows looking up for beans without any qualifier.
-
Constructor Details
-
Qualifiers
public Qualifiers()
-
-
Method Details
-
any
Allows looking up the first matching instance.This qualifier results on
NonUniqueBeanException
never being thrown as the first matching instance will be returned.- Type Parameters:
T
- The generic type- Returns:
- The any qualifier.
- Since:
- 3.0.0
- See Also:
-
none
Allows looking up for beans without any qualifier.- Type Parameters:
T
- The generic type- Returns:
- The none qualifier.
- Since:
- 3.8.0
-
forArgument
@Nullable public static <T> @Nullable Qualifier<T> forArgument(@NonNull @NonNull Argument<?> argument) Build a qualifier for the given argument.- Type Parameters:
T
- The type- Parameters:
argument
- The argument- Returns:
- The resolved qualifier
-
byQualifiers
Build a qualifier from other qualifiers.- Type Parameters:
T
- The component type- Parameters:
qualifiers
- The qualifiers- Returns:
- The qualifier
-
byName
Build a qualifier for the given name.- Type Parameters:
T
- The component type- Parameters:
name
- The name- Returns:
- The qualifier
-
findName
Finds a name in the provided qualifier.- Returns:
- The qualifier
- Since:
- 4.0.0
-
byNamePrefix
Qualify by a prefix. Applies starting with logic to the name of the bean.- Type Parameters:
T
- The component type- Parameters:
prefix
- The name- Returns:
- The qualifier
- Since:
- 4.0.0
-
byAnnotation
Build a qualifier for the given annotation.- Type Parameters:
T
- The component type- Parameters:
annotation
- The annotation- Returns:
- The qualifier
-
byAnnotation
public static <T> Qualifier<T> byAnnotation(AnnotationMetadata metadata, Class<? extends Annotation> type) Build a qualifier for the given annotation.- Type Parameters:
T
- The component type- Parameters:
metadata
- The metadatatype
- The annotation type- Returns:
- The qualifier
-
byAnnotation
Build a qualifier for the given annotation. This qualifier will match a candidate under the following circumstances:
- Type Parameters:
T
- The component type- Parameters:
metadata
- The metadatatype
- The annotation type- Returns:
- The qualifier
-
byAnnotation
public static <T extends Annotation> Qualifier<T> byAnnotation(AnnotationMetadata metadata, AnnotationValue<T> annotationValue) Build a qualifier for the given annotation value.
- Type Parameters:
T
- The component type- Parameters:
metadata
- The metadataannotationValue
- The annotation value- Returns:
- The qualifier
-
byRepeatableAnnotation
public static <T> Qualifier<T> byRepeatableAnnotation(AnnotationMetadata metadata, String repeatableType) Builds a qualifier that uses the given repeatable annotation.
- Type Parameters:
T
- The component type- Parameters:
metadata
- The metadatarepeatableType
- The annotation repeatable type. That is the annotation specified toRepeatable.value()
- Returns:
- The qualifier
-
byAnnotationSimple
@Internal public static <T> Qualifier<T> byAnnotationSimple(AnnotationMetadata metadata, String type) Build a qualifier for the given annotation.
Unlike
byAnnotation(io.micronaut.core.annotation.AnnotationMetadata, String)
this method will not attempt to pick the qualifier strategy to use at runtime based on the passed annotation name.- Type Parameters:
T
- The component type- Parameters:
metadata
- The metadatatype
- The annotation type- Returns:
- The qualifier
- Since:
- 3.1.0
-
byStereotype
Build a qualifier for the given annotation.- Type Parameters:
T
- The component type- Parameters:
stereotype
- The stereotype- Returns:
- The qualifier
-
byStereotype
Build a qualifier for the given annotation.- Type Parameters:
T
- The component type- Parameters:
stereotype
- The stereotype- Returns:
- The qualifier
- Since:
- 3.0.0
-
byTypeArguments
Build a qualifier for the given generic type arguments.- Type Parameters:
T
- The component type- Parameters:
typeArguments
- The generic type arguments- Returns:
- The qualifier
-
byExactTypeArgumentName
@NonNull public static <T> @NonNull Qualifier<T> byExactTypeArgumentName(@NonNull @NonNull String typeName) Build a qualifier for the given generic type argument name.- Type Parameters:
T
- The component type- Parameters:
typeName
- The name of the generic type argument- Returns:
- The qualifier
- Since:
- 3.0.0
-
byTypeArgumentsClosest
Build a qualifier for the given generic type arguments. Only the closest matches will be returned.- Type Parameters:
T
- The component type- Parameters:
typeArguments
- The generic type arguments- Returns:
- The qualifier
-
byType
Build a qualifier for the given generic type arguments.- Type Parameters:
T
- The component type- Parameters:
typeArguments
- The generic type arguments- Returns:
- The qualifier
-
byInterceptorBinding
@NonNull public static <T> @NonNull Qualifier<T> byInterceptorBinding(@NonNull @NonNull AnnotationMetadata annotationMetadata) Reduces bean definitions by the given interceptor binding.- Type Parameters:
T
- The bean type- Parameters:
annotationMetadata
- The annotation metadata- Returns:
- The qualifier
-
byInterceptorBindingValues
@NonNull public static <T> @NonNull Qualifier<T> byInterceptorBindingValues(@NonNull @NonNull Collection<AnnotationValue<?>> binding) Reduces bean definitions by the given interceptor binding.- Type Parameters:
T
- The bean type- Parameters:
binding
- The binding values to use- Returns:
- The qualifier
- Since:
- 3.3.0
-