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 {@link javax.enterprise.inject.Any @Any} qualifier may be used, allowing the application to specify qualifiersdynamically:
@Inject @Any Instance<PaymentProcessor> anyPaymentProcessor;
Finally, the {@link javax.enterprise.inject.New @New} qualifier may be used, allowing the application to obtain a{@link javax.enterprise.inject.New @New} qualified bean:
@Inject @New(ChequePaymentProcessor.class) Instance<PaymentProcessor> chequePaymentProcessor;
For an injected Instance:
The inherited {@link javax.inject.Provider#get()} method returns a contextual references for the unique bean that matches therequired type and required qualifiers and is eligible for injection into the class into which the parent Instance was injected, or throws an {@link javax.enterprise.inject.UnsatisfiedResolutionException} or{@link javax.enterprise.inject.AmbiguousResolutionException}.
PaymentProcessor pp = chequePaymentProcessor.get();
The inherited {@link java.lang.Iterable#iterator()} method returns an iterator over contextual references for beans thatmatch 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();@see javax.inject.Provider#get() @see java.lang.Iterable#iterator() @see javax.enterprise.util.AnnotationLiteral @see javax.enterprise.util.TypeLiteral @author Gavin King @param < T> the required bean type
|
|
|
|