Skip to content

Commit

Permalink
Update docs/src/main/asciidoc/cdi-reference.adoc
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Smet <[email protected]>
  • Loading branch information
rmanibus and gsmet committed Sep 17, 2024
1 parent d2c4625 commit 1870f6c
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions docs/src/main/asciidoc/cdi-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -957,26 +957,50 @@ Alternatively, you can use the `@LookupIfProperty` and `@LookupUnlessProperty` a
}
----

if there is more than one bean that matches the required type and qualifiers and is eligible for injection, it is possible to iterate (or stream) available bean instances.
=== Sorting beans obtained with programmatic lookup

If there is more than one bean that matches the required type and qualifiers and is eligible for injection, it is possible to iterate (or stream) available bean instances.
Beans returned by both stream and iterator methods are sorted by priority as defined by `io.quarkus.arc.InjectableBean#getPriority()`. Higher priority goes first.

Check warning on line 963 in docs/src/main/asciidoc/cdi-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/cdi-reference.adoc", "range": {"start": {"line": 963, "column": 57}}}, "severity": "INFO"}
If no priority is explicitly declared, 0 is assumed.

[source,java]
----
@ApplicationScoped
class Client {
interface Service {
@Inject
Instance<Service> serviceInstance;
}
void printServiceName() {
if(service.isAmbiguous()){
for (Service service : serviceInstance) {
@Priority(100)
@ApplicationScoped
class FirstService implements Service {
}
}
}
}
----
}
@Priority(10)
@ApplicationScoped
class SecondService implements Service {
}
@ApplicationScoped
class ThirdService implements Service {
}
@ApplicationScoped
class Client {
@Inject
Instance<Service> serviceInstance;
void printServiceName() {
if(service.isAmbiguous()){
for (Service service : serviceInstance) {
// FirstService, SecondService, ThirdService
}
}
}
}
----

[[injecting-multiple-bean-instances-intuitively]]

Check warning on line 1005 in docs/src/main/asciidoc/cdi-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.HeadingPunctuation] Do not use end punctuation in headings. Raw Output: {"message": "[Quarkus.HeadingPunctuation] Do not use end punctuation in headings.", "location": {"path": "docs/src/main/asciidoc/cdi-reference.adoc", "range": {"start": {"line": 1005, "column": 33}}}, "severity": "INFO"}

Check warning on line 1005 in docs/src/main/asciidoc/cdi-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Headings] Use sentence-style capitalization in '4.18. Injecting Multiple Bean Instances Intuitively'. Raw Output: {"message": "[Quarkus.Headings] Use sentence-style capitalization in '4.18. Injecting Multiple Bean Instances Intuitively'.", "location": {"path": "docs/src/main/asciidoc/cdi-reference.adoc", "range": {"start": {"line": 1005, "column": 33}}}, "severity": "INFO"}
=== Injecting Multiple Bean Instances Intuitively
Expand Down

0 comments on commit 1870f6c

Please sign in to comment.