Package com.itextpdf.commons.utils
Class DIContainer
java.lang.Object
com.itextpdf.commons.utils.DIContainer
A simple dependency injection container.
The container is thread-safe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionT getInstance(Class clazz) Gets an instance of a class.booleanisRegistered(Class> clazz) Checks if an instance is registered for a class.voidRegisters an instance for a class.static voidregisterDefault(Class> clazz, Supplier<Object> supplier) Registers a default instance for a class.
-
Constructor Details
-
DIContainer
public DIContainer()Creates a new instance ofDIContainer.
-
-
Method Details
-
registerDefault
Registers a default instance for a class.- Parameters:
-
clazz- the class -
supplier- supplier of the instance
-
register
Registers an instance for a class.- Parameters:
-
clazz- the class -
inst- the instance
-
getInstance
Gets an instance of a class.- Type Parameters:
-
T- the type of the class - Parameters:
-
clazz- the class - Returns:
- the instance
-
isRegistered
Checks if an instance is registered for a class. If the class is registered but the value is null, it will still returntrue.- Parameters:
-
clazz- the class - Returns:
-
trueif an instance is registered,falseotherwise
-