I know there are a lot of articles out there that explain how to use CDI in Java EE but I\'m having trouble figuring out what advantage this actually brings. For example, su
At a high level, as with most things on CompSci, it offers a level of indirection (or abstraction) that would otherwise be hardcoded in your application as Foo myFoo = new Foo();
. That indirection brings about loosely coupled code, which makes things modular, which makes it easy to replace, service, test etc classes or sub-systems in a simpler manner.
Note that there are many designs and patterns for indirection/abstraction - dependency injection is just one.
The other aspect of your question is "Why CDI?" - well, because someone has already done the work for you. You can always build your own stuff, but it's usually a waste of time when the objective is to build a real world system that must perform under budget and on time. Why bother with groceries and cooking when there is a Michelin starred chef who's willing to do that work for you?