@versionzero/module-manager / ModuleManager
Class: ModuleManager
Defined in: module-manager.js:28
Configuration, dependency injection, and lifecycle management for modular applications.
Provides services based on lightweight coding conventions or sidecar information rather than requiring all participating systems to integrate with a framework.
Constructors
Constructor
new ModuleManager(
options?):ModuleManager
Defined in: module-manager.js:70
Create a new ModuleManager instance.
You can provide your own Configurator or Schema (but not both), or use accessors after
construction to tweak their behavior.
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | { schema?: Schema; configurator?: Configurator; } | - |
options.schema? | Schema | optional existing Schema that should be augmented |
options.configurator? | Configurator | optional existing Configurator to use |
Returns
ModuleManager
Properties
Accessors
moduleInfo
Get Signature
get
staticmoduleInfo():ModuleOptions
Defined in: module-manager.js:33
Returns
ModuleOptions
configurator
Get Signature
get configurator():
Configurator
Defined in: module-manager.js:107
Get the Configurator in use by the ModuleManager.
Only getter access is provided; cannot be changed after construction.
Returns
Configurator
resolver
Get Signature
get resolver():
SchemaResolver
Defined in: module-manager.js:118
Get the SchemaResolver that is being used to hold module schemas and reference schemas.
Only getter access is provided; cannot be changed after construction.
Returns
SchemaResolver
schema
Get Signature
get schema():
Schema
Defined in: module-manager.js:129
Get the top-level Schema being built and managed by ModuleManager.
Only getter access is provided; cannot be changed after construction.
Returns
Schema
Methods
register()
register(
ModuleClass,options?):ModuleManager
Defined in: module-manager.js:147
Register a module with a ModuleClass that can be instantiated via a no-arguments constructor
A well-formed ModuleClass will either provide a moduleInfo static property containing multiple module
settings, or individual static properties for each setting. For example, .moduleInfo.name or .moduleName.
Modules are stored internally keyed by the pascal-cased version of their name.
Parameters
| Parameter | Type | Description |
|---|---|---|
ModuleClass | ModuleConstructable | Class or factory function with static metadata. |
options? | ModuleOptions | Optional module properties |
Returns
ModuleManager
registerInstance()
registerInstance(
instance,options?):ModuleManager
Defined in: module-manager.js:160
Register a pre-instantiated module instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
instance | any | Pre-created module instance. |
options? | ModuleOptions | Optional overrides (e.g. name) |
Returns
ModuleManager
getModule()
getModule(
moduleRequest):Module|undefined
Defined in: module-manager.js:171
Get a previously registered module by name or ModuleClass.
Parameters
| Parameter | Type | Description |
|---|---|---|
moduleRequest | string | ModuleConstructable | - |
Returns
Module | undefined
getModuleInstance()
getModuleInstance(
moduleRequest):any
Defined in: module-manager.js:180
Get the instantiated value of a previously registered module by name or ModuleClass.
Parameters
| Parameter | Type | Description |
|---|---|---|
moduleRequest | string | - |
Returns
any
findInstanceModule()
findInstanceModule(
instance):Module|undefined
Defined in: module-manager.js:192
Find the module that has the provided instance (if any).
Parameters
| Parameter | Type | Description |
|---|---|---|
instance | any | - |
Returns
Module | undefined
getInstantiatedModules()
getInstantiatedModules():
Module[]
Defined in: module-manager.js:200
Get all instantiated modules in dependency order.
Returns
Module[]
reference()
reference(
referenceRequest,options):ModuleManager
Defined in: module-manager.js:210
Register a module reference
Parameters
| Parameter | Type | Description |
|---|---|---|
referenceRequest | string | ModuleConstructable | - |
options | any | - |
Returns
ModuleManager
getReference()
getReference(
referenceRequest):ModuleReference|undefined
Defined in: module-manager.js:228
Get the named ModuleReference.
Parameters
| Parameter | Type | Description |
|---|---|---|
referenceRequest | string | ModuleConstructable | - |
Returns
ModuleReference | undefined
hasReference()
hasReference(
referenceRequest):boolean
Defined in: module-manager.js:238
Check if the named ModuleReference already exists.
Parameters
| Parameter | Type | Description |
|---|---|---|
referenceRequest | string | ModuleConstructable | - |
Returns
boolean
invokeLifecycleMethod()
invokeLifecycleMethod(
methodName,options?):Promise<void>
Defined in: module-manager.js:262
Parameters
| Parameter | Type | Description |
|---|---|---|
methodName | string | - |
options? | any | - |
Returns
Promise<void>
invokeMainMethod()
invokeMainMethod(
methodName,options?):Promise<void>
Defined in: module-manager.js:289
Parameters
| Parameter | Type | Description |
|---|---|---|
methodName | string | - |
options? | any | - |
Returns
Promise<void>
configure()
configure(
context):Promise<any>
Defined in: module-manager.js:323
Configure modules
Loads configuration per the top-level aggregated module schema. Each module schema is gated by a condition that causes it to be skipped if there is no corresponding module instance, so initially all configuration is skipped except pre-instantiated modules (like the main module).
However, named references to modules within the active part of the configuration causes them to be instantiated, which has a cascading effect, activating new schemas, which contain new references, which trigger new instances...
(You normally want to use .run(context) to both configure and run lifecycle methods.)
Parameters
| Parameter | Type | Description |
|---|---|---|
context | any | - |
Returns
Promise<any>
initModules()
initModules(
config,reload?):Promise<void>
Defined in: module-manager.js:341
Initialize all instantiated modules
Runs the init lifecycle method and/or does dependency injection if the inject flag is set.
If the reload flag is set, only modules that support hot reloading will be re-initialized.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
config | any | undefined | - |
reload? | boolean | false | - |
Returns
Promise<void>
run()
run(
context?):Promise<void>
Defined in: module-manager.js:377
Main call that choreographs the entire module graph lifecycle.
- Uses
Configuratorto create configuration based on the aggregated moduleSchemadefinitions. - Initializes and starts all referenced modules in dependency order.
- Awaits the
mainmodule (if any). - Stops and terminates the modules.
- Exits.
Parameters
| Parameter | Type | Description |
|---|---|---|
context | any | - |
Returns
Promise<void>