Allows the application to dynamically obtain instances of beans with a specified combination of required type and qualifiers.
In certain situations, injection is not the most convenient way to obtain a contextual reference. For example, it may not be used when:
In these situations, an instance of the Instance may be injected:
@Inject Instance<PaymentProcessor> paymentProcessor;
Any combination of qualifiers may be specified at the injection point:
@Inject @PayBy(CHEQUE) Instance<PaymentProcessor> chequePaymentProcessor;
Or, the @Any qualifier may be used, allowing the application to specify qualifiers
dynamically:
@Inject @Any Instance<PaymentProcessor> anyPaymentProcessor;
For an injected Instance:
The inherited jakarta.inject.Provider#get() method returns a contextual references for the unique bean that matches the
required type and required qualifiers and is eligible for injection into the class into which the parent Instance
was injected, or throws an UnsatisfiedResolutionException or
AmbiguousResolutionException.
PaymentProcessor pp = chequePaymentProcessor.get();
The inherited java.lang.Iterable#iterator() method returns an iterator over contextual references for beans that
match the required type and required qualifiers and are eligible for injection into the class into which the parent
Instance was injected.
for (PaymentProcessor pp : anyPaymentProcessor)
pp.test();
jakarta.inject.Provider#get(), java.lang.Iterable#iterator(), AnnotationLiteral, TypeLiteral
| Modifier and Type | Class and Description |
|---|---|
| public static interface |
| Modifier and Type | Method and Description |
|---|---|
| public void | destroy(T
the instance to destroy instance)When called, the container destroys the instance if the active context object for the scope type of the bean supports destroying bean instances. |
| public Instance. | |
| public Iterable | Returns: a new iterableAllows iterating over contextual reference handles for all beans that have the required type and required qualifiers and are eligible for injection. |
| public default Stream | Returns: a new stream of contextual reference handlesReturns stream of |
| public boolean | Returns: true if there is more than one bean that matches the required type and qualifiers and is eligible for
injection into the class into which the parent Instance was injected, or false otherwise.
Determines if there is more than one bean that matches the required type and qualifiers and is eligible for injection
into the class into which the parent |
| public default boolean | Returns: true if there is exactly one bean that matches the required type and qualifiers and is eligible for
injection into the class into which the parent Instance was injected, or false otherwise.
Determines if there is exactly one bean that matches the required type and qualifiers and is eligible for injection
into the class into which the parent |
| public boolean | Returns: true if there is no bean that matches the required type and qualifiers and is eligible for injection
into the class into which the parent Instance was injected, or false otherwise.
Determines if there is no bean that matches the required type and qualifiers and is eligible for injection into the class
into which the parent |
| public Instance | Returns: the childInstancethe additional required qualifiers qualifiers)
Obtains a child |
| public < the required type U extends T> Instance | Returns: the childInstancea subtype, Annotation... java.lang.Class representing the required typethe additional required qualifiers qualifiers)
Obtains a child |
| public < the required type U extends T> Instance | Returns: the childInstancea subtype, Annotation... TypeLiteral representing the required typethe additional required qualifiers qualifiers)
Obtains a child |
| public default Stream |
| destroy | back to summary |
|---|---|
| public void destroy(T instance) When called, the container destroys the instance if the active context object for the scope type of the bean supports destroying bean instances. All normal scoped built-in contexts support destroying bean instances.
The instance passed should either be a dependent scoped bean instance obtained from the same
| |
| getHandle | back to summary |
|---|---|
| public Instance. Obtains an initialized contextual reference handle for a bean that has the required type and qualifiers and is eligible for injection. Throws exceptions if there is no such bean or more than one. The contextual reference is obtained lazily, i.e. when first needed.
| |
| handles | back to summary |
|---|---|
| public Iterable Allows iterating over contextual reference handles for all beans that have the required type and required qualifiers and are eligible for injection.
Note that the returned | |
| handlesStream | back to summary |
|---|---|
| public default Stream Returns stream of | |
| isAmbiguous | back to summary |
|---|---|
| public boolean isAmbiguous()
Determines if there is more than one bean that matches the required type and qualifiers and is eligible for injection
into the class into which the parent
| |
| isResolvable | back to summary |
|---|---|
| public default boolean isResolvable()
Determines if there is exactly one bean that matches the required type and qualifiers and is eligible for injection
into the class into which the parent
| |
| isUnsatisfied | back to summary |
|---|---|
| public boolean isUnsatisfied()
Determines if there is no bean that matches the required type and qualifiers and is eligible for injection into the class
into which the parent
| |
| select | back to summary |
|---|---|
| public Instance
Obtains a child
| |
| select | back to summary |
|---|---|
| public <U extends T> Instance
Obtains a child
| |
| select | back to summary |
|---|---|
| public <U extends T> Instance
Obtains a child
| |
| stream | back to summary |
|---|---|
| public default Stream When called, provides back a Stream of the beans available in this Instance. If no beans are found, it returns an empty stream. | |
Allows to inspect the metadata of the relevant bean before resolving its contextual reference and also to destroy the underlying contextual instance.
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public T | Returns: the contextual referenceThe contextual reference is obtained lazily, i.e. when first needed. |
| public Bean |
| close | back to summary |
|---|---|
| public void close() Redeclares java. Delegates to
| |
| destroy | back to summary |
|---|---|
| public void destroy() Destroy the contextual instance. It's a no-op if:
| |
| get | back to summary |
|---|---|
| public T get() The contextual reference is obtained lazily, i.e. when first needed.
| |
| getBean | back to summary |
|---|---|
public Bean
| |