Repository: quarkusio/quarkus
Issue: Can't inject ManagedExecutor since quarkus 1.6.0

**Describe the bug**
I'm trying to inject a ManagedExecutor (using Kotlin and injecting into `@Singleton` bean that extends `MutinyExampleServiceGrpc.ExampleServiceImplBase` if that matters) and get 
```
Parameter specified as non-null is null: method com.example.Example.<init>, parameter managedExecutor"
```
I tried both constructor injection as well as field injection via `lateinit var`

**Expected behavior**
ManagedExecutor is injected

**Actual behavior**
ManagedExecutor is not injected to my bean (both 1.6.0.Final and 1.6.1.Final)
But it's injected successfully if I change the version to 1.5.2.Final


Changed files:
extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/caffeine/CaffeineCacheBuildRecorder.java
extensions/smallrye-context-propagation/deployment/src/main/java/io/quarkus/smallrye/context/deployment/SmallRyeContextPropagationProcessor.java
extensions/smallrye-context-propagation/runtime/src/main/java/io/quarkus/smallrye/context/runtime/SmallRyeContextPropagationRecorder.java
extensions/cache/deployment/src/main/java/io/quarkus/cache/deployment/CacheProcessor.java
extensions/smallrye-context-propagation/runtime/src/main/java/io/quarkus/smallrye/context/runtime/SmallRyeContextPropagationProvider.java
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/InstanceHandle.java
core/deployment/src/main/java/io/quarkus/deployment/builditem/ManagedExecutorInitializedBuildItem.java

diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/ManagedExecutorInitializedBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/ManagedExecutorInitializedBuildItem.java
index 702b54664a0..420a78500f7 100644
--- a/core/deployment/src/main/java/io/quarkus/deployment/builditem/ManagedExecutorInitializedBuildItem.java
+++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/ManagedExecutorInitializedBuildItem.java
@@ -37,6 +37,9 @@
  * }
  * </pre>
  * </p>
+ * 
+ * @deprecated This build item should not be needed anymore and will be removed at some point after Quarkus 1.7.
  */
+@Deprecated
 public final class ManagedExecutorInitializedBuildItem extends SimpleBuildItem {
 }
diff --git a/extensions/cache/deployment/src/main/java/io/quarkus/cache/deployment/CacheProcessor.java b/extensions/cache/deployment/src/main/java/io/quarkus/cache/deployment/CacheProcessor.java
index 355b1a9140d..4358b4d236b 100644
--- a/extensions/cache/deployment/src/main/java/io/quarkus/cache/deployment/CacheProcessor.java
+++ b/extensions/cache/deployment/src/main/java/io/quarkus/cache/deployment/CacheProcessor.java
@@ -10,7 +10,6 @@
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Optional;
 import java.util.Set;
 
 import javax.enterprise.inject.spi.DeploymentException;
@@ -38,7 +37,6 @@
 import io.quarkus.deployment.annotations.Record;
 import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
 import io.quarkus.deployment.builditem.FeatureBuildItem;
-import io.quarkus.deployment.builditem.ManagedExecutorInitializedBuildItem;
 
 class CacheProcessor {
 
@@ -80,8 +78,7 @@ ValidationErrorBuildItem validateBeanDeployment(ValidationPhaseBuildItem validat
     @Record(RUNTIME_INIT)
     void recordCachesBuild(CombinedIndexBuildItem combinedIndex, BeanContainerBuildItem beanContainer, CacheConfig config,
             CaffeineCacheBuildRecorder caffeineRecorder,
-            List<AdditionalCacheNameBuildItem> additionalCacheNames,
-            Optional<ManagedExecutorInitializedBuildItem> managedExecutorInitialized) {
+            List<AdditionalCacheNameBuildItem> additionalCacheNames) {
         Set<String> cacheNames = getCacheNames(combinedIndex.getIndex());
         for (AdditionalCacheNameBuildItem additionalCacheName : additionalCacheNames) {
             cacheNames.add(additionalCacheName.getName());
@@ -89,7 +86,7 @@ void recordCachesBuild(CombinedIndexBuildItem combinedIndex, BeanContainerBuildI
         switch (config.type) {
             case CacheDeploymentConstants.CAFFEINE_CACHE_TYPE:
                 Set<CaffeineCacheInfo> cacheInfos = CaffeineCacheInfoBuilder.build(cacheNames, config);
-                caffeineRecorder.buildCaches(managedExecutorInitialized.isPresent(), beanContainer.getValue(), cacheInfos);
+                caffeineRecorder.buildCaches(beanContainer.getValue(), cacheInfos);
                 break;
             default:
                 throw new DeploymentException("Unknown cache type: " + config.type);
diff --git a/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/caffeine/CaffeineCacheBuildRecorder.java b/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/caffeine/CaffeineCacheBuildRecorder.java
index 9910264a872..3c06dc89e71 100644
--- a/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/caffeine/CaffeineCacheBuildRecorder.java
+++ b/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/caffeine/CaffeineCacheBuildRecorder.java
@@ -7,6 +7,7 @@
 import org.eclipse.microprofile.context.ManagedExecutor;
 import org.jboss.logging.Logger;
 
+import io.quarkus.arc.Arc;
 import io.quarkus.arc.runtime.BeanContainer;
 import io.quarkus.cache.runtime.CacheRepository;
 import io.quarkus.runtime.annotations.Recorder;
@@ -16,15 +17,12 @@ public class CaffeineCacheBuildRecorder {
 
     private static final Logger LOGGER = Logger.getLogger(CaffeineCacheBuildRecorder.class);
 
-    public void buildCaches(boolean managedExecutorInitialized, BeanContainer beanContainer,
+    public void buildCaches(BeanContainer beanContainer,
             Set<CaffeineCacheInfo> cacheInfos) {
         // The number of caches is known at build time so we can use fixed initialCapacity and loadFactor for the caches map.
         Map<String, CaffeineCache> caches = new HashMap<>(cacheInfos.size() + 1, 1.0F);
 
-        ManagedExecutor managedExecutor = null;
-        if (managedExecutorInitialized) {
-            managedExecutor = beanContainer.instance(ManagedExecutor.class);
-        }
+        ManagedExecutor managedExecutor = Arc.container().instance(ManagedExecutor.class).orElse(null);
 
         for (CaffeineCacheInfo cacheInfo : cacheInfos) {
             if (LOGGER.isDebugEnabled()) {
diff --git a/extensions/smallrye-context-propagation/deployment/src/main/java/io/quarkus/smallrye/context/deployment/SmallRyeContextPropagationProcessor.java b/extensions/smallrye-context-propagation/deployment/src/main/java/io/quarkus/smallrye/context/deployment/SmallRyeContextPropagationProcessor.java
index b293b0f93df..6d59bfbb87e 100644
--- a/extensions/smallrye-context-propagation/deployment/src/main/java/io/quarkus/smallrye/context/deployment/SmallRyeContextPropagationProcessor.java
+++ b/extensions/smallrye-context-propagation/deployment/src/main/java/io/quarkus/smallrye/context/deployment/SmallRyeContextPropagationProcessor.java
@@ -4,12 +4,14 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.inject.Singleton;
+
+import org.eclipse.microprofile.context.ManagedExecutor;
 import org.eclipse.microprofile.context.spi.ContextManagerExtension;
 import org.eclipse.microprofile.context.spi.ThreadContextProvider;
-import org.jboss.logging.Logger;
 
 import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
-import io.quarkus.arc.deployment.BeanContainerBuildItem;
+import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
 import io.quarkus.deployment.Feature;
 import io.quarkus.deployment.annotations.BuildProducer;
 import io.quarkus.deployment.annotations.BuildStep;
@@ -26,7 +28,6 @@
  * The deployment processor for MP-CP applications
  */
 class SmallRyeContextPropagationProcessor {
-    private static final Logger log = Logger.getLogger(SmallRyeContextPropagationProcessor.class.getName());
 
     @BuildStep
     void registerBean(BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
@@ -65,13 +66,21 @@ void buildStatic(SmallRyeContextPropagationRecorder recorder)
     @BuildStep
     @Record(ExecutionTime.RUNTIME_INIT)
     void build(SmallRyeContextPropagationRecorder recorder,
-            BeanContainerBuildItem beanContainer,
             ExecutorBuildItem executorBuildItem,
             BuildProducer<FeatureBuildItem> feature,
-            BuildProducer<ManagedExecutorInitializedBuildItem> managedExecutorInitialized) {
+            BuildProducer<ManagedExecutorInitializedBuildItem> managedExecutorInitialized,
+            BuildProducer<SyntheticBeanBuildItem> syntheticBeans) {
         feature.produce(new FeatureBuildItem(Feature.SMALLRYE_CONTEXT_PROPAGATION));
 
-        recorder.configureRuntime(beanContainer.getValue(), executorBuildItem.getExecutorProxy());
+        recorder.configureRuntime(executorBuildItem.getExecutorProxy());
+
+        // Synthetic bean for ManagedExecutor
+        syntheticBeans.produce(
+                SyntheticBeanBuildItem.configure(ManagedExecutor.class).scope(Singleton.class).defaultBean().unremovable()
+                        .supplier(recorder.initializeManagedExecutor(executorBuildItem.getExecutorProxy()))
+                        .setRuntimeInit().done());
+
+        // This should be removed at some point after Quarkus 1.7
         managedExecutorInitialized.produce(new ManagedExecutorInitializedBuildItem());
     }
 }
diff --git a/extensions/smallrye-context-propagation/runtime/src/main/java/io/quarkus/smallrye/context/runtime/SmallRyeContextPropagationProvider.java b/extensions/smallrye-context-propagation/runtime/src/main/java/io/quarkus/smallrye/context/runtime/SmallRyeContextPropagationProvider.java
index 92b42cd539f..bdafe1a0d7b 100644
--- a/extensions/smallrye-context-propagation/runtime/src/main/java/io/quarkus/smallrye/context/runtime/SmallRyeContextPropagationProvider.java
+++ b/extensions/smallrye-context-propagation/runtime/src/main/java/io/quarkus/smallrye/context/runtime/SmallRyeContextPropagationProvider.java
@@ -1,40 +1,16 @@
 package io.quarkus.smallrye.context.runtime;
 
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-
-import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.Typed;
 import javax.inject.Singleton;
 
-import org.eclipse.microprofile.context.ManagedExecutor;
 import org.eclipse.microprofile.context.ThreadContext;
 
 import io.quarkus.arc.DefaultBean;
-import io.smallrye.context.SmallRyeManagedExecutor;
-import io.smallrye.context.SmallRyeThreadContext;
 
-@ApplicationScoped
+@Dependent
 public class SmallRyeContextPropagationProvider {
 
-    private volatile SmallRyeManagedExecutor managedExecutor;
-
-    void initialize(ExecutorService executorService) {
-        managedExecutor = new SmallRyeManagedExecutor(-1, -1, (SmallRyeThreadContext) getAllThreadContext(), executorService,
-                "no-ip") {
-            @Override
-            public void shutdown() {
-                throw new IllegalStateException("This executor is managed by the container and cannot be shut down.");
-            }
-
-            @Override
-            public List<Runnable> shutdownNow() {
-                throw new IllegalStateException("This executor is managed by the container and cannot be shut down.");
-            }
-        };
-    }
-
     @Produces
     @Singleton
     @DefaultBean
@@ -42,12 +18,4 @@ public ThreadContext getAllThreadContext() {
         return ThreadContext.builder().propagated(ThreadContext.ALL_REMAINING).cleared().unchanged().build();
     }
 
-    @Typed(ManagedExecutor.class)
-    @Produces
-    @Singleton
-    @DefaultBean
-    public ManagedExecutor getAllManagedExecutor() {
-        return managedExecutor;
-    }
-
 }
diff --git a/extensions/smallrye-context-propagation/runtime/src/main/java/io/quarkus/smallrye/context/runtime/SmallRyeContextPropagationRecorder.java b/extensions/smallrye-context-propagation/runtime/src/main/java/io/quarkus/smallrye/context/runtime/SmallRyeContextPropagationRecorder.java
index 9a56175b549..def1211fa46 100644
--- a/extensions/smallrye-context-propagation/runtime/src/main/java/io/quarkus/smallrye/context/runtime/SmallRyeContextPropagationRecorder.java
+++ b/extensions/smallrye-context-propagation/runtime/src/main/java/io/quarkus/smallrye/context/runtime/SmallRyeContextPropagationRecorder.java
@@ -2,15 +2,19 @@
 
 import java.util.List;
 import java.util.concurrent.ExecutorService;
+import java.util.function.Supplier;
 
+import org.eclipse.microprofile.context.ThreadContext;
 import org.eclipse.microprofile.context.spi.ContextManagerExtension;
 import org.eclipse.microprofile.context.spi.ContextManagerProvider;
 import org.eclipse.microprofile.context.spi.ThreadContextProvider;
 
-import io.quarkus.arc.runtime.BeanContainer;
+import io.quarkus.arc.Arc;
 import io.quarkus.runtime.annotations.Recorder;
 import io.smallrye.context.SmallRyeContextManager;
 import io.smallrye.context.SmallRyeContextManagerProvider;
+import io.smallrye.context.SmallRyeManagedExecutor;
+import io.smallrye.context.SmallRyeThreadContext;
 
 /**
  * The runtime value service used to create values related to the MP-JWT services
@@ -36,7 +40,7 @@ public void configureStaticInit(List<ThreadContextProvider> discoveredProviders,
         builder.withContextManagerExtensions(discoveredExtensions.toArray(new ContextManagerExtension[0]));
     }
 
-    public void configureRuntime(BeanContainer container, ExecutorService executorService) {
+    public void configureRuntime(ExecutorService executorService) {
         // associate the static init manager to the runtime CL
         ContextManagerProvider contextManagerProvider = ContextManagerProvider.instance();
         // finish building our manager
@@ -45,9 +49,26 @@ public void configureRuntime(BeanContainer container, ExecutorService executorSe
         SmallRyeContextManager contextManager = builder.build();
 
         contextManagerProvider.registerContextManager(contextManager, Thread.currentThread().getContextClassLoader());
+    }
+
+    public Supplier<Object> initializeManagedExecutor(ExecutorService executorService) {
+        return new Supplier<Object>() {
+            @Override
+            public Object get() {
+                ThreadContext threadContext = Arc.container().instance(ThreadContext.class).get();
+                return new SmallRyeManagedExecutor(-1, -1, (SmallRyeThreadContext) threadContext, executorService,
+                        "no-ip") {
+                    @Override
+                    public void shutdown() {
+                        throw new IllegalStateException("This executor is managed by the container and cannot be shut down.");
+                    }
 
-        // initialise injection
-        SmallRyeContextPropagationProvider cpProvider = container.instance(SmallRyeContextPropagationProvider.class);
-        cpProvider.initialize(executorService);
+                    @Override
+                    public List<Runnable> shutdownNow() {
+                        throw new IllegalStateException("This executor is managed by the container and cannot be shut down.");
+                    }
+                };
+            }
+        };
     }
 }
diff --git a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/InstanceHandle.java b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/InstanceHandle.java
index ed421f38ee2..abcfd67f37a 100644
--- a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/InstanceHandle.java
+++ b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/InstanceHandle.java
@@ -26,6 +26,18 @@ default boolean isAvailable() {
         return get() != null;
     }
 
+    /**
+     * If an instance is available, returns the value, otherwise returns
+     * {@code other}.
+     * 
+     * @param other
+     * @return the instance if available, otherwise {@code other}
+     */
+    default T orElse(T other) {
+        T val = get();
+        return val != null ? val : other;
+    }
+
     /**
      * Destroy the instance as defined by
      * {@link javax.enterprise.context.spi.Contextual#destroy(Object, javax.enterprise.context.spi.CreationalContext)}. If this