How to pass parameters to instantiation of a CDI @Dependent bean?

168 Views Asked by At

How to pass runtime parameters to the instantiation of a @Dependent bean, obtained by Instance<T>.get() or equivalent in CDI?

For instance, consider the code:

@Inject
Instance<Person> instance;
...
var name = "Some One";
var bean = instance.get();
bean.setName(bean);

It may be desirable to pass the parameter in instantiation, to make the object immutable for example. Something like

@Inject
Instance<Person> instance;
...
var name = "Some One";
var bean = instance.get(name); // ?

Is there a syntax for that in current CDI?

0

There are 0 best solutions below