Module jakarta.cdi

Class SeContainerInitializer

java.lang.Object
jakarta.enterprise.inject.se.SeContainerInitializer

public abstract class SeContainerInitializer extends Object
A CDI container initializer for Java SE. An instance may be obtained by calling newInstance() static method.

Typical usage looks like this:

 SeContainer container = SeContainerInitializer.newInstance().initialize();
 container.select(Foo.class).get();
 container.close();
 

Since SeContainer interface implements AutoCloseable:

 try (SeContainer container = SeContainerInitializer.newInstance().initialize()) {
     container.select(Foo.class).get();
 }
 

By default, the discovery is enabled so that all beans from all discovered bean archives are considered. However, it's possible to define a "synthetic" bean archive, or the set of bean classes and enablement respectively:

 SeContainer container = SeContainerInitializer.newInstance().addBeanClasses(Foo.class, Bar.class).selectAlternatives(Bar.class).initialize());
 

Moreover, it's also possible to disable the discovery completely so that only the "synthetic" bean archive is considered:

 SeContainer container = SeContainerInitializer.newInstance().disableDiscovery().addBeanClasses(Foo.class, Bar.class).initialize());
 

In the same manner, it is possible to explicitly declare interceptors, decorators, extensions and implementation specific options using the builder.

 SeContainerInitializer containerInitializer = SeContainerInitializer.newInstance()
         .disableDiscovery()
         .addPackages(Main.class, Utils.class)
         .enableInterceptors(TransactionalInterceptor.class)
         .addProperty("property", true);
 SeContainer container = container.initialize();
 

CDI Lite implementations are not required to provide support for CDI in Java SE.

Since:
2.0