Sometimes you need an instance of an object with a type that might be changed or determined at runtime, and you need a reliable mechanism to perform that task. Luckily, Java EE 8 comes with Contexts and Dependency Injection (CDI), which can solve the problem.
From new() to CDI
If you write a class that needs access to an underlying object-oriented service, you need to obtain an instance of this service and call its methods. One simple approach is to create a new object of the service class:
That approach has ...