DefaultBootstrapContext class final
The default implementation of ConfigurableBootstrapContext in JetLeaf.
This class is responsible for managing instance suppliers, created instances, and event listeners during the bootstrap phase of the application. It provides a thread-safe, singleton-aware mechanism for instance creation, caching, and retrieval.
Responsibilities
-
Instance Supplier Registration
- Allows registering factories (BootstrapInstanceSupplier) for classes.
- Supports optional replacement of existing registrations while ensuring that already created instances cannot be overridden.
-
Instance Retrieval
- Returns instances for registered classes on demand.
- Supports singleton caching if the supplier’s scope is ScopeType.SINGLETON.
- Provides optional fallback values (orElse) or suppliers (
orSupply) when no registration exists.
-
Event Handling
- Allows adding listeners for bootstrap context events via ApplicationEventBus.
- Emits BootstrapContextClosedEvent when the context is closed.
-
Thread-Safety
- All access to internal maps (
_isps,_instances) is synchronized to avoid race conditions during concurrent access.
- All access to internal maps (
Usage
final context = DefaultBootstrapContext();
context.register(MyService.classType, BootstrapInstanceSupplier.singleton(() => MyService()));
final service = context.get(MyService.classType);
context.close(applicationContext);
- Implemented types
Constructors
- DefaultBootstrapContext()
- The default implementation of ConfigurableBootstrapContext in JetLeaf.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addCloseListener(
ApplicationEventListener< BootstrapContextClosedEvent> listener) → void -
Adds an ApplicationEventListener that is called when the BootstrapContext
is closed and the ApplicationContext has been fully prepared.
override
-
close(
ConfigurableApplicationContext applicationContext) → void -
Closes the bootstrap context by firing a BootstrapContextClosedEvent.
override
-
get<
T> (Class< T> type, {T? orElse, Supplier<T> ? orSupply}) → T -
Returns an instance of the given
typeif it has been registered in the context. The instance will be lazily created on first access.override -
getApplicationClass(
) → Class< Object> -
Returns the application class registered in this context.
override
-
getOrThrow<
T, X extends Throwable> (Class< T> type, Supplier<X> exceptionSupplier) → T -
Returns an instance of the given
typeif registered.override -
getSupplier<
T> (Class< T> type) → BootstrapInstanceSupplier<T> -
Returns the registered BootstrapInstanceSupplier for a type
T, ornullif not registered.override -
isClassRegistered<
T> (Class< T> type) → bool -
Checks whether a
typehas already been registered in this context.override -
isRegistered<
T> (Class< T> type) → bool -
Checks whether a supplier for type
Tis already registered.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
register<
T> (Class< T> type, BootstrapInstanceSupplier<T> supplier) → void -
Register a supplier for a type
Tinto the registry.override -
setApplicationClass(
Class< Object> applicationClass) → void -
Sets the application class in this context.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited