Cloud Native, Container First Java framework for building efficient Java applications with fast startup times and low memory usage
—
Quarkus uses ArC, a build-time optimized CDI container that provides dependency injection, context management, and lifecycle handling with full native image support.
public final class Arc {
public static ArcContainer initialize();
public static ArcContainer initialize(ArcInitConfig config);
public static void setExecutor(ExecutorService executor);
public static ArcContainer container();
public static void shutdown();
}Main access point to the ArC CDI container. Use container() to access container services programmatically.
Usage Example:
import io.quarkus.arc.Arc;
import io.quarkus.arc.InstanceHandle;
// Get a bean instance programmatically
InstanceHandle<MyService> handle = Arc.container().instance(MyService.class);
MyService service = handle.get();
// Use the service
service.doSomething();
// Clean up when done
handle.destroy();public interface ArcContainer {
// Bean instance access
<T> InstanceHandle<T> instance(Class<T> type, Annotation... qualifiers);
<T> InstanceHandle<T> instance(TypeLiteral<T> type, Annotation... qualifiers);
<X> InstanceHandle<X> instance(Type type, Annotation... qualifiers);
<T> InstanceHandle<T> instance(String name);
<T> InstanceHandle<T> instance(InjectableBean<T> bean);
// Programmatic selection
<T> InjectableInstance<T> select(Class<T> type, Annotation... qualifiers);
<T> InjectableInstance<T> select(TypeLiteral<T> type, Annotation... qualifiers);
// Bean listing and suppliers
<T> List<InstanceHandle<T>> listAll(Class<T> type, Annotation... qualifiers);
<T> List<InstanceHandle<T>> listAll(TypeLiteral<T> type, Annotation... qualifiers);
<X> List<InstanceHandle<X>> listAll(Type type, Annotation... qualifiers);
<T> Supplier<InstanceHandle<T>> beanInstanceSupplier(Class<T> type, Annotation... qualifiers);
// Bean access
<T> InjectableBean<T> bean(String beanIdentifier);
InjectableBean<?> namedBean(String name);
// Context management
InjectableContext getActiveContext(Class<? extends Annotation> scopeType);
List<InjectableContext> getContexts(Class<? extends Annotation> scopeType);
Set<Class<? extends Annotation>> getScopes();
ManagedContext requestContext();
ManagedContext sessionContext();
// Container state and services
boolean isRunning();
BeanManager beanManager();
ExecutorService getExecutorService();
CurrentContextFactory getCurrentContextFactory();
boolean strictCompatibility();
// Event observers
<T> List<InjectableObserverMethod<? super T>> resolveObserverMethods(Type eventType, Annotation... eventQualifiers);
}The main container interface providing bean access and lifecycle management.
public interface InstanceHandle<T> extends AutoCloseable, Instance.Handle<T> {
T get();
default boolean isAvailable();
default T orElse(T other);
default void destroy();
default InjectableBean<T> getBean();
@Override
default void close();
}Handle for managed bean instances with automatic lifecycle management.
public interface InjectableInstance<T> extends Instance<T> {
@Override
InjectableInstance<T> select(Annotation... qualifiers);
@Override
<U extends T> InjectableInstance<U> select(Class<U> subtype, Annotation... qualifiers);
@Override
<U extends T> InjectableInstance<U> select(TypeLiteral<U> subtype, Annotation... qualifiers);
@Override
InstanceHandle<T> getHandle();
@Override
Iterable<InstanceHandle<T>> handles();
@Override
default Stream<InstanceHandle<T>> handlesStream();
void clearCache();
@Override
Iterator<T> iterator();
default T orElse(T other);
default T orNull();
default T getActive();
default List<T> listActive();
}CDI Instance wrapper providing programmatic bean access with ArC-specific enhancements.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Scope
public @interface ApplicationScoped {
}Application-scoped beans (singleton per application).
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Scope
public @interface RequestScoped {
}Request-scoped beans (one instance per request).
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Scope
public @interface SessionScoped {
}Session-scoped beans (one instance per HTTP session).
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Scope
public @interface Singleton {
}Singleton-scoped beans (eager instantiation).
Usage Example:
@ApplicationScoped
public class UserService {
@Inject
UserRepository repository;
public User findById(Long id) {
return repository.findById(id);
}
}@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Inject {
}Standard CDI injection annotation.
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface Named {
String value() default "";
}Named qualifier for disambiguation.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface DefaultBean {
}Marks beans as default implementations that can be overridden by other beans.
Usage Example:
@DefaultBean
@ApplicationScoped
public class DefaultEmailService implements EmailService {
// Default implementation
}
@ApplicationScoped // This will override the default
public class CustomEmailService implements EmailService {
// Custom implementation
}@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Unremovable {
}Prevents bean removal during build-time optimization.
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface All {
}Qualifier for injecting all instances of a particular type.
Usage Example:
@ApplicationScoped
public class NotificationService {
@Inject
@All
List<NotificationHandler> handlers; // Injects all NotificationHandler implementations
public void notify(String message) {
handlers.forEach(handler -> handler.handle(message));
}
}@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface VetoedProducer {
}Excludes producer methods from CDI processing.
public abstract class BeanCreator<T> {
public static <T> BeanCreator<T> create(Class<T> beanClass);
public BeanCreator<T> scope(Class<? extends Annotation> scope);
public BeanCreator<T> addQualifier(Annotation qualifier);
public BeanCreator<T> creator(CreationalContext<T> creationalContext);
public void done();
}Programmatic API for creating beans at runtime.
public interface BeanDestroyer<T> {
void destroy(T instance, CreationalContext<T> creationalContext);
}Interface for custom bean destruction logic.
public interface ManagedContext extends InjectableContext {
void activate();
void deactivate();
void terminate();
boolean isActive();
}Interface for programmatically managed contexts.
Usage Example:
@ApplicationScoped
public class RequestContextService {
@Inject
ManagedContext requestContext;
public void executeInRequestContext(Runnable task) {
requestContext.activate();
try {
task.run();
} finally {
requestContext.terminate();
}
}
}public interface InjectableContext extends Context {
void destroy();
void destroy(Contextual<?> contextual);
ContextState getState();
}Enhanced context interface with destruction capabilities.
public class CurrentContext {
public static boolean isActive(Class<? extends Annotation> scopeType);
public static <T> T get(Class<T> beanClass);
public static <T> T get(Class<T> beanClass, Annotation... qualifiers);
}Utility class for accessing current context state.
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Observes {
Reception notifyObserver() default Reception.ALWAYS;
TransactionPhase during() default TransactionPhase.IN_PROGRESS;
}Standard CDI event observation annotation.
public interface Event<T> {
void fire(T event);
<U extends T> void fireAsync(U event);
Event<T> select(Annotation... qualifiers);
}Interface for firing CDI events.
Usage Example:
@ApplicationScoped
public class OrderService {
@Inject
Event<OrderPlaced> orderEvent;
public void placeOrder(Order order) {
// Process order
orderEvent.fire(new OrderPlaced(order));
}
}
@ApplicationScoped
public class OrderEventHandler {
void onOrderPlaced(@Observes OrderPlaced event) {
System.out.println("Order placed: " + event.getOrder().getId());
}
}@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@InterceptorBinding
public @interface Transactional {
TxType value() default TxType.REQUIRED;
Class[] rollbackOn() default {};
Class[] dontRollbackOn() default {};
}Transaction interceptor binding (example of interceptor usage).
public final class InvocationContextImpl {
public static final int PLATFORM_BEFORE = 0;
public static final int LIBRARY_BEFORE = 1000;
public static final int APPLICATION = 2000;
public static final int LIBRARY_AFTER = 3000;
public static final int PLATFORM_AFTER = 4000;
}Priority constants for ordering interceptors and observers.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ConfigProperties {
String prefix() default "";
NamingStrategy namingStrategy() default NamingStrategy.KEBAB_CASE;
}Integration between CDI and MicroProfile Config for configuration properties binding.
Usage Example:
@ConfigProperties(prefix = "app.database")
@ApplicationScoped
public class DatabaseConfig {
public String host;
public int port;
public String username;
public String password;
}Install with Tessl CLI
npx tessl i tessl/maven-io-quarkus--quarkus-bom