Do something like (I assume you are using spring-boot or something comparable for your CDI)
public class ClassWhereIWantToInject{ private MyService myService; @Inject public ClassWhereIWantToInject(MyService mySerivce){ this.myService = myService; } }
There are some valid arguments in this related question , why use injection through the constructor instead of injection through the field. This boils down to the fact that you can use initialization through the constructor also in an environment without CDI, that is, Unit Test, without the need to add more complex logic.
source share