Top Description Fields Constructors Methods
jakarta.enterprise.inject.spi

public abstract Class CDI<T>

extends Object
implements Instance<T>
Class Inheritance
All Implemented Interfaces
jakarta.enterprise.inject.Instance, jakarta.inject.Provider, java.lang.Iterable
Type Parameters
<T>
type inherited from Instance. Always Object for CDI
Imports
java.util.Collections, .Comparator, .ServiceConfigurationError, .ServiceLoader, .Set, .TreeSet, jakarta.enterprise.inject.Instance

Provides access to the current container.

CDI implements Instance and therefore might be used to perform programmatic lookup. If no qualifier is passed to select method, the @Default qualifier is assumed.

Authors
Pete Muir, Antoine Sabot-Durand, John D. Ament
Since
1.1

Field Summary

Modifier and TypeField and Description
protected static volatile CDIProvider
configuredProvider

CDIProvider set by user or retrieved by service loader

protected static volatile Set<CDIProvider>
discoveredProviders

The set of discovered CDIProviders

private static final Object
private static volatile boolean

Constructor Summary

AccessConstructor and Description
public
CDI()

Method Summary

Modifier and TypeMethod and Description
private static boolean
public static CDI<Object>

Returns:

the CDI instance
current
()

Get the CDI instance that provides access to the current container.

private static void
public BeanContainer

Returns:

the BeanContainer
getBeanContainer
()

Get the CDI BeanContainer for the current context.

public abstract BeanManager

Returns:

the BeanManager
getBeanManager
()

Get the CDI BeanManager for the current context

private static CDIProvider

Returns:

the CDIProvider set by user or retrieved by serviceloader
getCDIProvider
()

Obtain the CDIProvider the user set with setCDIProvider(CDIProvider) or the last returned CDIProvider if it returns valid CDI container.

public static void
setCDIProvider(CDIProvider
the provider to use
provider
)

Set the CDIProvider to use.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configuredProviderback to summary
protected static volatile CDIProvider configuredProvider

CDIProvider set by user or retrieved by service loader

discoveredProvidersback to summary
protected static volatile Set<CDIProvider> discoveredProviders

The set of discovered CDIProviders

lockback to summary
private static final Object lock
providerSetManuallyback to summary
private static volatile boolean providerSetManually

Constructor Detail

CDIback to summary
public CDI()

Method Detail

checkProviderback to summary
private static boolean checkProvider(CDIProvider c)
currentback to summary
public static CDI<Object> current()

Get the CDI instance that provides access to the current container.

If there are no providers available, an IllegalStateException is thrown, otherwise the first provider which can access the container is used.

Returns:CDI<Object>

the CDI instance

Exceptions
IllegalStateException:
if no CDIProvider is available
findAllProvidersback to summary
private static void findAllProviders()
getBeanContainerback to summary
public BeanContainer getBeanContainer()

Get the CDI BeanContainer for the current context. Default implementation just forwards the call to getBeanManager().

Returns:BeanContainer

the BeanContainer

getBeanManagerback to summary
public abstract BeanManager getBeanManager()

Get the CDI BeanManager for the current context

Returns:BeanManager

the BeanManager

getCDIProviderback to summary
private static CDIProvider getCDIProvider()

Obtain the CDIProvider the user set with setCDIProvider(CDIProvider) or the last returned CDIProvider if it returns valid CDI container. Otherwise, use service loader mechanism to retrieve the CDIProvider with the highest priority.

Returns:CDIProvider

the CDIProvider set by user or retrieved by serviceloader

setCDIProviderback to summary
public static void setCDIProvider(CDIProvider provider)

Set the CDIProvider to use.

If a CDIProvider is set using this method, any provider specified as a service provider will not be used.

Parameters
provider:CDIProvider

the provider to use

Exceptions
IllegalArgumentException:
if the provided argument is null