Class SeContainerInitializer
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();
- Since:
- 2.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract SeContainerInitializeraddBeanClasses(Class<?>... classes) Add provided bean classes to the synthetic bean archive.abstract SeContainerInitializeraddExtensions(Extension... extensions) Add extensions to the set of extensions.abstract SeContainerInitializeraddExtensions(Class<? extends Extension>... extensions) Add extensions to the set of extensions.abstract SeContainerInitializeraddPackages(boolean scanRecursively, Class<?>... packageClasses) Packages of the specified classes will be scanned and found classes will be added to the set of bean classes for the synthetic bean archive.*abstract SeContainerInitializeraddPackages(boolean scanRecursively, Package... packages) All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.abstract SeContainerInitializeraddPackages(Class<?>... packageClasses) All classes from the packages of the specified classes will be added to the set of bean classes for the synthetic bean archive.abstract SeContainerInitializeraddPackages(Package... packages) All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.abstract SeContainerInitializeraddProperty(String key, Object value) Add a configuration property to the containerabstract SeContainerInitializerBy default, the discovery is enabled.abstract SeContainerInitializerenableDecorators(Class<?>... decoratorClasses) Add decorator classes to the list of enabled decorators for the synthetic bean archive.abstract SeContainerInitializerenableInterceptors(Class<?>... interceptorClasses) Add interceptor classes to the list of enabled interceptors for the synthetic bean archive.abstract SeContainerInitializes a CDI SeContainerInitializer.static SeContainerInitializerReturns an instance ofSeContainerInitializerEach call returns a new instanceabstract SeContainerInitializerselectAlternatives(Class<?>... alternativeClasses) Add alternatives classes to the list of selected alternatives for the synthetic bean archive.abstract SeContainerInitializerselectAlternativeStereotypes(Class<? extends Annotation>... alternativeStereotypeClasses) Add alternative stereotype classes to the list of selected alternative stereotypes for the synthetic bean archive.abstract SeContainerInitializersetClassLoader(ClassLoader classLoader) Set aClassLoader.abstract SeContainerInitializersetProperties(Map<String, Object> properties) Set all the configuration properties.
-
Constructor Details
-
SeContainerInitializer
public SeContainerInitializer()
-
-
Method Details
-
newInstance
Returns an instance ofSeContainerInitializerEach call returns a new instance- Returns:
- a new SeContainerInitializer instance.
- Throws:
IllegalStateException- if called in a Java EE container
-
addBeanClasses
Add provided bean classes to the synthetic bean archive.- Parameters:
classes- classes to add to the synthetic bean archive- Returns:
- self
-
addPackages
All classes from the packages of the specified classes will be added to the set of bean classes for the synthetic bean archive.Note that the scanning possibilities are limited. Therefore, only directories and jar files from the filesystem are supported.
Scanning may also have negative impact on SE performance.
- Parameters:
packageClasses- classes whose packages will be added to the synthetic bean archive- Returns:
- self
-
addPackages
public abstract SeContainerInitializer addPackages(boolean scanRecursively, Class<?>... packageClasses) Packages of the specified classes will be scanned and found classes will be added to the set of bean classes for the synthetic bean archive.*Note that the scanning possibilities are limited. Therefore, only directories and jar files from the filesystem are supported.
Scanning may also have negative impact on SE performance.
- Parameters:
scanRecursively- should subpackages be scanned or notpackageClasses- classes whose packages will be scanned- Returns:
- self
-
addPackages
All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.Note that the scanning possibilities are limited. Therefore, only directories and jar files from the filesystem are supported.
Scanning may also have negative impact on SE performance.
- Parameters:
packages- packages that will be added to the synthetic bean archive- Returns:
- self
-
addPackages
All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.Note that the scanning possibilities are limited. Therefore, only directories and jar files from the filesystem are supported.
Scanning may also have negative impact on SE performance.
- Parameters:
scanRecursively- should subpackages be scanned or notpackages- packages that will be added to the synthetic bean archive- Returns:
- self
-
addExtensions
Add extensions to the set of extensions.- Parameters:
extensions- extensions to use in the container- Returns:
- self
-
addExtensions
Add extensions to the set of extensions.- Parameters:
extensions- extensions class to use in the container- Returns:
- self
-
enableInterceptors
Add interceptor classes to the list of enabled interceptors for the synthetic bean archive.This method does not add any class to the set of bean classes of the synthetic bean archive.
- Parameters:
interceptorClasses- classes of the interceptors to enable.- Returns:
- self
-
enableDecorators
Add decorator classes to the list of enabled decorators for the synthetic bean archive.This method does not add any class to the set of bean classes of the synthetic bean archive.
- Parameters:
decoratorClasses- classes of the decorators to enable.- Returns:
- self
-
selectAlternatives
Add alternatives classes to the list of selected alternatives for the synthetic bean archive.This method does not add any class to the set of bean classes of the synthetic bean archive.
- Parameters:
alternativeClasses- classes of the alternatives to select- Returns:
- self
-
selectAlternativeStereotypes
public abstract SeContainerInitializer selectAlternativeStereotypes(Class<? extends Annotation>... alternativeStereotypeClasses) Add alternative stereotype classes to the list of selected alternative stereotypes for the synthetic bean archive.This method does not add any class to the set of bean classes of the synthetic bean archive.
- Parameters:
alternativeStereotypeClasses- alternatives stereotypes to select- Returns:
- self
-
addProperty
Add a configuration property to the container- Parameters:
key- property namevalue- property value- Returns:
- self
-
setProperties
Set all the configuration properties. Erase previous properties set- Parameters:
properties- a map containing properties to add- Returns:
- self
-
disableDiscovery
By default, the discovery is enabled. However, it's possible to disable the discovery completely so that only the "synthetic" bean archive is considered.- Returns:
- self
-
setClassLoader
Set aClassLoader. The givenClassLoaderwill be scanned automatically for bean archives if scanning is enabled.- Parameters:
classLoader- the class loader to use- Returns:
- self
-
initialize
Initializes a CDI SeContainerInitializer.
Cannot be called within an application server.
- Returns:
- the
SeContainerinstance associated with the container. - Throws:
UnsupportedOperationException- if called within an application server
-