Invoker,
but does not necessarily have to be an Invoker instance directly
Invokers. Allows configuring additional behaviors on top of a plain
method invocation.
withInstanceLookup()) and for each target method
parameter (withArgumentLookup(int)), it is possible to specify that the corresponding
value passed to Invoker.invoke() shall be ignored and a value shall be looked up
from the CDI container instead.
For example, assume the following managed bean exists:
@Dependent
public class MyService {
public String hello(String name) {
return "Hello " + name + "!";
}
}
A CDI-based framework may want to build an invoker for the hello() method that
automatically looks up MyService from the CDI container, instead of having to
obtain a contextual reference manually.
Assuming that builder is an InvokerBuilder for MyService.hello(),
such invoker can be built:
builder.withInstanceLookup().build();Later, to invoke the
hello() method, a framework could pass null as the instance:
invoker.invoke(null, new Object[] { "world" })
The invoker would look up the instance of the target bean automatically, so the method would be
invoked correctly and the return value would be "Hello world!".
| Modifier and Type | Method and Description |
|---|---|
| public T | |
| public InvokerBuilder | Returns: this builderzero-based position of the target method parameter for which lookup should be enabled position)Enables lookup of the argument on given |
| public InvokerBuilder |
| build | back to summary |
|---|---|
| public T build() Returns the built
| |
| withArgumentLookup | back to summary |
|---|---|
| public InvokerBuilder Enables lookup of the argument on given
| |
| withInstanceLookup | back to summary |
|---|---|
| public InvokerBuilder Enables lookup of the target bean instance.
| |