CDI injection into an existing object

Let's say I have the following class:

public class MyRequestPayload implements RequestPayload {

    protected MyRequestPayload() {}

    @Override
    public ResponsePayload process() {
        String result = someService.doSomething(foo, bar);
        return new MyResponsePayload(result);
    }

    public final String foo;

    public final Integer bar;

    @Inject
    private SomeService someService;
}

      

Is there some CDI service that I can call that will process all annotations @Inject

on an instance of this class by injecting all the relevant services currently available? This is necessary for the case when the objects are not single and are not created by CDI. In the above hypothetical example, the object is created by deserialization.

+1


source to share


1 answer


I don't think this is possible with standard CDI. But if you are using the DeltaSpike extension you can use BeanProvider .injectFields ... does what you want. Note that of course your Pojo is not controlled by (scope) CDI, only field injections are allowed ...



+1


source







All Articles