Module jakarta.cdi

Interface InvokerBuilder<T>

Type Parameters:
T - type of outcome of this builder; always represents an Invoker, but does not necessarily have to be an Invoker instance directly

public interface InvokerBuilder<T>
Builder of Invokers. Allows configuring additional behaviors on top of a plain method invocation.

Lookups

For the target bean instance (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!".
Since:
4.1