Lifecycle
Complete module lifecycle from discovery through registration, activation, and deactivation
BoxLang modules follow a well-defined lifecycle with distinct phases, each firing events that your module can listen to.
Lifecycle Overview
Phase 1: Discovery
When the runtime starts, the ModuleService scans configured paths for directories containing ModuleConfig.bx or box.json, and for *.jar files, which are modules in their own right.
What happens:
Each discovered module becomes a
ModuleRecordin the registryDuplicates are resolved first-come-first-served
Module name is determined from
box.jsonboxlang.moduleName, a JAR's@BoxModule( name ), or the directory / JAR base nameEach discovered module is then scanned for a
modules/folder of its own, recursively — see Module Inception
No events fire during discovery.
Phase 2: Registration
Each module is registered in the order discovered. Registration loads the descriptor and prepares the module but does not make it active.
After all modules are registered, the AFTER_MODULE_REGISTRATIONS event fires.
Phase 3: Activation
Activation makes the module "live" in the runtime. Dependencies are activated first (recursively).
After all modules are activated, the AFTER_MODULE_ACTIVATIONS event fires, followed by ON_MODULE_SERVICE_STARTUP.
Phase 4: Running
The module is active and all its capabilities are available to the runtime:
BIFs are callable from BoxLang code
Components are usable as
bx:tagsInterceptors are listening for events
Services are available via
BoxRuntime
Phase 5: Deactivation (Shutdown)
When the runtime shuts down or a module is explicitly unloaded:
Lifecycle Events Reference
PRE_MODULE_REGISTRATION
Registration
moduleRecord, moduleName
POST_MODULE_REGISTRATION
Registration
moduleRecord, moduleName
AFTER_MODULE_REGISTRATIONS
Registration
moduleRegistry
PRE_MODULE_LOAD
Activation
moduleRecord, moduleName
POST_MODULE_LOAD
Activation
moduleRecord, moduleName
AFTER_MODULE_ACTIVATIONS
Activation
moduleRegistry
ON_MODULE_SERVICE_STARTUP
Activation
moduleService
ON_MODULE_SERVICE_SHUTDOWN
Deactivation
moduleService
PRE_MODULE_UNLOAD
Deactivation
moduleRecord, moduleName
POST_MODULE_UNLOAD
Deactivation
moduleRecord, moduleName
Listening to Events
Your ModuleConfig.bx can listen to any lifecycle event by defining a matching method:
Version Compatibility
During registration, the module's minimumVersion (from box.json) is checked against the running BoxLang version using semver:
Major version lower → Module is rejected with an error
Minor/patch version lower → Module loads but logs a warning
Next Steps
Capabilities — Learn what modules can provide
Configuration — Settings and runtime overrides
Advanced Collaboration — System settings providers and class resolvers
Last updated
Was this helpful?
