From 9fd055c02ecba1fea846b30ee92e496ce129f65d Mon Sep 17 00:00:00 2001
From: Georgios Andrianakis <geoand@gmail.com>
Date: Fri, 1 Sep 2023 11:43:54 +0300
Subject: [PATCH] Make minor improvements to CDI handling of
 AsyncHealthCheckFactory

---
 .../deployment/SmallRyeHealthProcessor.java      |  4 ++++
 .../runtime/QuarkusAsyncHealthCheckFactory.java  | 16 +++++++---------
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java
index e26b0c7da8f33..616a4a3cfadc9 100644
--- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java
+++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java
@@ -29,6 +29,7 @@
 import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
 import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem;
 import io.quarkus.arc.deployment.BeanDefiningAnnotationBuildItem;
+import io.quarkus.arc.deployment.ExcludedTypeBuildItem;
 import io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem;
 import io.quarkus.arc.processor.BuiltinScope;
 import io.quarkus.deployment.Capabilities;
@@ -71,6 +72,7 @@
 import io.quarkus.vertx.http.deployment.webjar.WebJarResourcesFilter;
 import io.quarkus.vertx.http.deployment.webjar.WebJarResultsBuildItem;
 import io.quarkus.vertx.http.runtime.management.ManagementInterfaceBuildTimeConfig;
+import io.smallrye.health.AsyncHealthCheckFactory;
 import io.smallrye.health.SmallRyeHealthReporter;
 import io.smallrye.health.api.HealthGroup;
 import io.smallrye.health.api.HealthGroups;
@@ -154,6 +156,7 @@ void healthCheck(BuildProducer<AdditionalBeanBuildItem> buildItemBuildProducer,
     @SuppressWarnings("unchecked")
     void build(SmallRyeHealthRecorder recorder,
             BuildProducer<FeatureBuildItem> feature,
+            BuildProducer<ExcludedTypeBuildItem> excludedTypes,
             BuildProducer<AdditionalBeanBuildItem> additionalBean,
             BuildProducer<BeanDefiningAnnotationBuildItem> beanDefiningAnnotation)
             throws IOException, ClassNotFoundException {
@@ -171,6 +174,7 @@ void build(SmallRyeHealthRecorder recorder,
 
         // Add additional beans
         additionalBean.produce(new AdditionalBeanBuildItem(QuarkusAsyncHealthCheckFactory.class));
+        excludedTypes.produce(new ExcludedTypeBuildItem(AsyncHealthCheckFactory.class.getName()));
         additionalBean.produce(new AdditionalBeanBuildItem(SmallRyeHealthReporter.class));
 
         // Make ArC discover @HealthGroup as a qualifier
diff --git a/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/QuarkusAsyncHealthCheckFactory.java b/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/QuarkusAsyncHealthCheckFactory.java
index 31ebd6dda6afc..40ac4774701c7 100644
--- a/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/QuarkusAsyncHealthCheckFactory.java
+++ b/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/QuarkusAsyncHealthCheckFactory.java
@@ -1,9 +1,6 @@
 package io.quarkus.smallrye.health.runtime;
 
-import jakarta.annotation.Priority;
-import jakarta.enterprise.context.ApplicationScoped;
-import jakarta.enterprise.inject.Alternative;
-import jakarta.inject.Inject;
+import jakarta.inject.Singleton;
 
 import org.eclipse.microprofile.health.HealthCheck;
 import org.eclipse.microprofile.health.HealthCheckResponse;
@@ -19,13 +16,14 @@
  * Quarkus specific health check factory that runs blocking and reactive
  * health checks with different executors provided by {@link MutinyHelper}.
  */
-@ApplicationScoped
-@Alternative
-@Priority(1)
+@Singleton
 public class QuarkusAsyncHealthCheckFactory extends AsyncHealthCheckFactory {
 
-    @Inject
-    Vertx vertx;
+    private final Vertx vertx;
+
+    public QuarkusAsyncHealthCheckFactory(Vertx vertx) {
+        this.vertx = vertx;
+    }
 
     @Override
     public Uni<HealthCheckResponse> callSync(HealthCheck healthCheck) {