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;
Finally, the @New qualifier may be used, allowing the application to obtain a
@New qualified bean:
@Inject @New(ChequePaymentProcessor.class) Instance<PaymentProcessor> chequePaymentProcessor;
For an injected Instance:
The inherited javax.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 javax.enterprise.inject.UnsatisfiedResolutionException or
javax.enterprise.inject.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();
javax.inject.Provider#get(), java.lang.Iterable#iterator(), javax.enterprise.util.AnnotationLiteral, javax.enterprise.util.TypeLiteral
| 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 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 Instance was injected. |
| 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 Instance was injected. |
| 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 Instance was injected. |
| public Instance | Returns: the child Instancethe additional required qualifiers qualifiers)Obtains a child Instance for the given additional required qualifiers. |
| public < the required type U extends T> Instance | Returns: the child Instancea subtype, Annotation... java.lang.Class representing the required typethe additional required qualifiers qualifiers)Obtains a child Instance for the given required type and additional required qualifiers. |
| public < the required type U extends T> Instance | Returns: the child Instancea subtype, Annotation... javax.enterprise.util.TypeLiteral representing the required typethe additional required qualifiers qualifiers)Obtains a child Instance for the given required type and additional required qualifiers. |
| 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
| |
| 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 Instance was injected.
| |
| 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 Instance was injected.
| |
| 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 Instance was injected.
| |
| select | back to summary |
|---|---|
| public Instance Obtains a child Instance for the given additional required qualifiers.
| |
| select | back to summary |
|---|---|
| public <U extends T> Instance Obtains a child Instance for the given required type and additional required qualifiers.
| |
| select | back to summary |
|---|---|
| public <U extends T> Instance Obtains a child Instance for the given required type and additional required qualifiers.
| |
| 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. | |