CDI
CDI @inject :
Bu su demek : INFERFACE ‘e uygun classi otomatik bulup, impelements edip, CONTROLLER OLUSTURUYOR.
NAMED dersen, senin ismini verdigin CLASSi impelements ediyor.

Ref : buraktas.com
Named is CALLED if there are “more than one implementation for an interface.”
Impelement edilebilir CLASS’larin basina, @Default. @Alternative koyabilirsin. !
From Another Person : buraktas.com/create-qualifiers-cdi-beans/
Java CDI Dependency Injection Example
CDI (Context and Dependency Injection) is a specification defined in JSR-299. Major aim is loose coupling by dependency injection.In this tutorial we will see how to use CDI Dependency Injection in java with three different ways;
- Field injection
- Constructor injection
- Setter method injection
We are going to use @Inject alongside @Named annotations from CDI of Java EE. @Named annotation is used for giving names for classes which implements the interface, and it is optional. Otherwise, we can specify alternatives and a default bean by @Alternative, and @Default annotations. However, I am going to show them in this tutorial. Moreover, these are the example interface and implementation classes we are going to use.
Notes:
@Namedannotation is commonly used if there are more than one implementation for an interface. Thus, it provides to give and inject by their names.- If there is only one implementation of an interface and
@Namedannotation is used, then the name of the bean is determined as camelCase style of class name. - We can use
@Defaultand@Alternativeannotations instead of giving names to them. - If there is only one implementation of an interface, compiler will inject it as the default one. So, there is no need to use
@Named,@Defaultor@Alternativeannotations.
Important
We have to create an empty beans.xml file in src/main/resources/META-INF if it is a jar application or src/main/webapp/WEB-INF if it is a war application.
[crayon-6ad9fdfd5cfd4715626473/]
AutoService.java
[crayon-6ad9fdfd5cfda235668021/]
BMWAutoService.java
[crayon-6ad9fdfd5cfdb904439688/]
FordAutoService.java
[crayon-6ad9fdfd5cfdc052799832/]
HondaAutoService.java
[crayon-6ad9fdfd5cfdd229843815/]
AutoServiceCaller.java
[crayon-6ad9fdfd5cfde019116037/]
1. Injection Through Fields
Beans are injected through fields.
[crayon-6ad9fdfd5cfdf498183825/]
2. Injection Through Setter Methods
We can also inject our beans via setters
[crayon-6ad9fdfd5cfe0867574009/]
3. Injection Through Constructor
Finally, beans can be injected through the constructor of the class.
[crayon-6ad9fdfd5cfe1051422921/]