or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

bean-container.mdbean-invocation.mdbuild-profiles.mdbuild-properties.mdindex.mdinterceptor-integration.mdlogger-injection.mdruntime-lookup.md
tile.json

tessl/maven-io-quarkus--quarkus-arc

Build time CDI dependency injection framework for Quarkus applications with conditional bean support and context management

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.quarkus/quarkus-arc@3.23.x

To install, run

npx @tessl/cli install tessl/maven-io-quarkus--quarkus-arc@3.23.0

index.mddocs/

Quarkus Arc

Quarkus Arc is a build-time CDI (Contexts and Dependency Injection) dependency injection framework that is part of the Quarkus ecosystem. This extension provides compile-time dependency injection capabilities optimized for cloud-native and containerized Java applications. Arc processes CDI annotations at build time rather than runtime, enabling faster startup times and reduced memory footprint typical of traditional CDI implementations.

Package Information

  • Package Name: quarkus-arc
  • Package Type: maven
  • Language: Java
  • Installation: Add dependency to pom.xml:
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-arc</artifactId>
    <version>3.23.0</version>
</dependency>

Core Imports

import io.quarkus.arc.profile.IfBuildProfile;
import io.quarkus.arc.profile.UnlessBuildProfile;
import io.quarkus.arc.properties.IfBuildProperty;
import io.quarkus.arc.properties.UnlessBuildProperty;
import io.quarkus.arc.lookup.LookupIfProperty;
import io.quarkus.arc.lookup.LookupUnlessProperty;
import io.quarkus.arc.log.LoggerName;
import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.arc.runtime.BeanContainerListener;
import io.quarkus.arc.runtime.BeanInvoker;
import io.quarkus.arc.runtime.BeanLookupSupplier;
import io.quarkus.arc.runtime.InterceptorBindings;

For accessing the Arc container at runtime:

import io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;

Basic Usage

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import io.quarkus.arc.profile.IfBuildProfile;
import io.quarkus.arc.log.LoggerName;
import org.jboss.logging.Logger;

// Conditional bean based on build profile
@ApplicationScoped
@IfBuildProfile("dev")
public class DevService {
    
    @Inject
    @LoggerName("dev.service")
    Logger logger;
    
    public void process() {
        logger.info("Processing in development mode");
    }
}

// Property-based conditional bean
@ApplicationScoped
@IfBuildProperty(name = "feature.enabled", stringValue = "true")
public class FeatureService {
    
    public void execute() {
        // Feature implementation
    }
}

// Runtime bean container access
@ApplicationScoped
public class ContainerManager {
    
    public void demonstrateContainerAccess() {
        // Access the bean container
        BeanContainer container = Arc.container();
        DevService service = container.beanInstance(DevService.class);
        service.process();
    }
}

Architecture

Quarkus Arc is built around several key components:

  • Build-Time Processing: CDI bean discovery and dependency resolution happens at build time, creating optimized dependency injection code
  • Conditional Bean Support: Rich annotation system for enabling/disabling beans based on build profiles, properties, and runtime conditions
  • Context Management: Automatic management of CDI contexts (request, application scopes) with manual control capabilities
  • Runtime Container: Lightweight runtime container providing programmatic bean access and lifecycle management
  • Integration Layer: Deep integration with Quarkus configuration system and MicroProfile specifications

Capabilities

Build Profile Conditional Beans

Control bean activation based on Quarkus build profiles, enabling different implementations for development, testing, and production environments.

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE, ElementType.FIELD })
public @interface IfBuildProfile {
    String value() default "";
    String[] allOf() default {};
    String[] anyOf() default {};
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE, ElementType.FIELD })
public @interface UnlessBuildProfile {
    String value() default "";
    String[] allOf() default {};
    String[] anyOf() default {};
}

Build Profile Conditionals

Build Property Conditional Beans

Enable beans based on build-time configuration properties, allowing feature toggles and environment-specific configurations.

@Repeatable(IfBuildProperty.List.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE, ElementType.FIELD })
public @interface IfBuildProperty {
    String name();
    String stringValue();
    boolean enableIfMissing() default false;
}

@Repeatable(UnlessBuildProperty.List.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE, ElementType.FIELD })
public @interface UnlessBuildProperty {
    String name();
    String stringValue();
    boolean enableIfMissing() default false;
}

Build Property Conditionals

Runtime Lookup Conditionals

Control which beans are available for programmatic lookup based on runtime properties, enabling dynamic behavior without bean activation overhead.

@Repeatable(LookupIfProperty.List.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE, ElementType.FIELD })
public @interface LookupIfProperty {
    String name();
    String stringValue();
    boolean lookupIfMissing() default false;
}

@Repeatable(LookupUnlessProperty.List.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE, ElementType.FIELD })
public @interface LookupUnlessProperty {
    String name();
    String stringValue();
    boolean lookupIfMissing() default false;
}

Runtime Lookup Conditionals

Logger Injection

CDI-based logger injection with support for custom logger names and automatic bean-specific logger creation.

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
public @interface LoggerName {
    String value();
    
    public static final class Literal extends AnnotationLiteral<LoggerName> implements LoggerName {
        public Literal(String value);
        public String value();
    }
}

Logger Injection

Bean Container Management

Programmatic access to the CDI bean container for runtime bean resolution, context management, and lifecycle control.

public interface BeanContainer {
    <T> T beanInstance(Class<T> beanType, Annotation... beanQualifiers);
    <T> Factory<T> beanInstanceFactory(Class<T> type, Annotation... qualifiers);
    <T> Factory<T> beanInstanceFactory(Supplier<Factory<T>> fallbackSupplier, Class<T> type, Annotation... qualifiers);
    ManagedContext requestContext();
    
    interface Factory<T> {
        Instance<T> create();
    }
    
    interface Instance<T> extends AutoCloseable {
        T get();
        default void close();
    }
}

public interface BeanContainerListener {
    void created(BeanContainer container);
}

Bean Container Management

Bean Invocation Utilities

Utility interfaces for invoking bean methods with automatic context management and lookup operations.

public interface BeanInvoker<T> {
    default void invoke(T param) throws Exception;
    void invokeBean(T param) throws Exception;
}

public class BeanLookupSupplier implements Supplier<Object> {
    public BeanLookupSupplier();
    public BeanLookupSupplier(Class<?> type);
    public Class<?> getType();
    public BeanLookupSupplier setType(Class<?> type);
    public Object get();
}

Bean Invocation Utilities

Interceptor Integration

Utilities for working with interceptor bindings and context data within interceptor implementations.

public final class InterceptorBindings {
    public static Set<Annotation> getInterceptorBindings(InvocationContext invocationContext);
    public static Set<AbstractAnnotationLiteral> getInterceptorBindingLiterals(InvocationContext invocationContext);
}

Interceptor Integration