Package org.int4.dirk.api
Interface InstanceResolver
-
- All Known Subinterfaces:
Injector
- All Known Implementing Classes:
StandardInjector
public interface InstanceResolverProvides methods to resolve types and classes to injected instances.All methods support filtering by qualifier annotation, by providing either an
Annotationinstance (obtainable viaAnnotations#of(Class)) or by providing an annotationClassdirectly (for marker annotations only). Annotations should be qualifier annotations or no matches will be found.Filtering by generic type is possible by creating a corresponding
TypeLiteral.Examples:
getInstance(Database.class)
would return aDatabaseinstance.getInstance(new TypeLiteral<Provider<Database>>() {})would return aProviderfor aDatabaseinstance.getInstances(Vehicle.class, Red.class)
orgetInstances(Vehicle.class, Annotations.of(Red.class))
would return allVehicles instances annotated with the@Redqualifier annotation.getInstance(String.class, Annotations.of(Named.class, Map.of("value", "config.url"))would return aStringinstance which was registered with aNamedannotation with value "config.url".
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> TgetInstance(java.lang.Class<T> cls, java.lang.Object... qualifiers)Returns an instance of the given class matching the given criteria (if any) in which all dependencies are injected.<T> TgetInstance(TypeLiteral<T> typeLiteral, java.lang.Object... qualifiers)Returns an instance of the type specified by the givenTypeLiteralmatching the given criteria (if any) in which all dependencies are injected.<T> java.util.List<T>getInstances(java.lang.Class<T> cls, java.lang.Object... qualifiers)Returns all instances of the given class matching the given criteria (if any) in which all dependencies are injected.<T> java.util.List<T>getInstances(TypeLiteral<T> typeLiteral, java.lang.Object... qualifiers)Returns all instances of the type specified by the givenTypeLiteralmatching the given criteria (if any) in which all dependencies are injected.
-
-
-
Method Detail
-
getInstance
<T> T getInstance(TypeLiteral<T> typeLiteral, java.lang.Object... qualifiers) throws UnsatisfiedResolutionException, AmbiguousResolutionException, CreationException, ScopeNotActiveException
Returns an instance of the type specified by the givenTypeLiteralmatching the given criteria (if any) in which all dependencies are injected. The instance returned can either be an existing instance or newly created depending on its scope.- Type Parameters:
T- the type of the instance- Parameters:
typeLiteral- specifies the type of the instance required, cannot benullqualifiers- optional list of qualifier annotations, eitherAnnotationorClass<? extends Annotation>- Returns:
- an instance of the given class matching the given criteria, never
null - Throws:
UnsatisfiedResolutionException- when no matching instance was available or could be createdAmbiguousResolutionException- when multiple matching instances were availableCreationException- when an error occurred during creation of a matching instanceScopeNotActiveException- when the scope for the produced type is not active
-
getInstance
<T> T getInstance(java.lang.Class<T> cls, java.lang.Object... qualifiers) throws UnsatisfiedResolutionException, AmbiguousResolutionException, CreationException, ScopeNotActiveExceptionReturns an instance of the given class matching the given criteria (if any) in which all dependencies are injected. The instance returned can either be an existing instance or newly created depending on its scope.- Type Parameters:
T- the type of the instance- Parameters:
cls- the class of the instance required, cannot benullqualifiers- optional list of qualifier annotations, eitherAnnotationorClass<? extends Annotation>- Returns:
- an instance of the given class matching the given criteria (if any)
- Throws:
UnsatisfiedResolutionException- when no matching instance was available or could be createdAmbiguousResolutionException- when multiple matching instances were availableCreationException- when an error occurred during creation of a matching instanceScopeNotActiveException- when the scope for the produced type is not active
-
getInstances
<T> java.util.List<T> getInstances(TypeLiteral<T> typeLiteral, java.lang.Object... qualifiers) throws CreationException
Returns all instances of the type specified by the givenTypeLiteralmatching the given criteria (if any) in which all dependencies are injected. When there are no matches, an empty set is returned. The instances returned can either be existing instances or newly created depending on their scope or a mix thereof.- Type Parameters:
T- the type of the instances- Parameters:
typeLiteral- specifies the type of the instances required, cannot benullqualifiers- optional list of qualifier annotations, eitherAnnotationorClass<? extends Annotation>- Returns:
- all instances of the given
Typematching the given criteria (if any), nevernull, can be empty - Throws:
CreationException- when an error occurred during creation of a matching instance
-
getInstances
<T> java.util.List<T> getInstances(java.lang.Class<T> cls, java.lang.Object... qualifiers) throws CreationExceptionReturns all instances of the given class matching the given criteria (if any) in which all dependencies are injected. When there are no matches, an empty set is returned. The instances returned can either be existing instances or newly created depending on their scope or a mix thereof.- Type Parameters:
T- the type of the instances- Parameters:
cls- the class of the instances required, cannot benullqualifiers- optional list of qualifier annotations, eitherAnnotationorClass<? extends Annotation>- Returns:
- all instances of the given class matching the given criteria (if any), never
null, can be empty - Throws:
CreationException- when an error occurred during creation of a matching instance
-
-