T
- public interface WeldInstance<T> extends Instance<T>
Instance
.
In the following example we filter out beans which are not Dependent
then sort the beans by priority and use the handler whose bean has the highest
priority (according to getPriorityComparator()
) to obtain the hello string. Note that contextual references for beans with lower priority are not
created at all.
@ApplicationScoped class Hello { @Inject WeldInstance<HelloProvider> instance; String hello() { HelloProvider helloProvider = instance.handlersStream().filter(h -> h.getBean().getScope().equals(Dependent.class)) .sorted(instance.getPriorityComparator()).findFirst().map(Handler::get).orElse(null); if (helloProvider != null) return helloProvider.getHello(); return "No hello provider found!"; } }
Modifier and Type | Interface and Description |
---|---|
static interface |
WeldInstance.Handler<T>
This interface represents a contextual reference handler.
|
Modifier and Type | Method and Description |
---|---|
WeldInstance.Handler<T> |
getHandler()
Obtains an initialized contextual reference handler for the bean that has the required type and required qualifiers and is eligible for injection.
|
Comparator<WeldInstance.Handler<?>> |
getPriorityComparator()
The returned comparator sorts handlers by priority in descending order.
|
Iterable<WeldInstance.Handler<T>> |
handlers()
Allows to iterate over contextual reference handlers for all the beans that have the required type and required qualifiers and are eligible
for injection.
|
default Stream<WeldInstance.Handler<T>> |
handlersStream() |
WeldInstance<T> |
select(Annotation... qualifiers)
Obtains a child Instance for the given additional required qualifiers.
|
<U extends T> |
select(Class<U> subtype,
Annotation... qualifiers)
Obtains a child Instance for the given required type and additional required qualifiers.
|
<X> WeldInstance<X> |
select(Type subtype,
Annotation... qualifiers)
Obtains a child
Instance for the given required type and additional required qualifiers. |
<U extends T> |
select(TypeLiteral<U> subtype,
Annotation... qualifiers)
Obtains a child Instance for the given required type and additional required qualifiers.
|
destroy, isAmbiguous, isResolvable, isUnsatisfied, stream
forEach, iterator, spliterator
WeldInstance.Handler<T> getHandler()
The contextual reference is obtained lazily, i.e. when first needed.
UnsatisfiedResolutionException
AmbiguousResolutionException
Iterable<WeldInstance.Handler<T>> handlers()
Note that the returned Iterable
is stateless and so each Iterable.iterator()
produces a new set of handlers.
default Stream<WeldInstance.Handler<T>> handlersStream()
Comparator<WeldInstance.Handler<?>> getPriorityComparator()
javax.annotation.Priority
has the priority of value javax.annotation.Priority#value()
Prioritized
has the priority of value Prioritized.getPriority()
WeldInstance<T> select(Annotation... qualifiers)
Instance
Obtains a child Instance for the given additional required qualifiers.
<U extends T> WeldInstance<U> select(Class<U> subtype, Annotation... qualifiers)
Instance
Obtains a child Instance for the given required type and additional required qualifiers.
<U extends T> WeldInstance<U> select(TypeLiteral<U> subtype, Annotation... qualifiers)
Instance
Obtains a child Instance for the given required type and additional required qualifiers.
select
in interface Instance<T>
U
- the required typesubtype
- a TypeLiteral
representing the required typequalifiers
- the additional required qualifiers<X> WeldInstance<X> select(Type subtype, Annotation... qualifiers)
Obtains a child Instance
for the given required type and additional required qualifiers.
Must be invoked on Instance<T>
where T is Object
.
X
- the required typesubtype
- a Type
representing the required typequalifiers
- the additional required qualifiersIllegalArgumentException
- if passed two instances of the same non repeating qualifier type, or an instance of an
annotation that is not a qualifier typeIllegalStateException
- if the container is already shutdownIllegalStateException
- if invoked on Instance<T>
where T is of any other type than Object
Copyright © 2019 JBoss by Red Hat. All rights reserved.