createContainer
createContainer
is a function that creates and returns a container to manage modules in the application. Containers specify dependencies, define initialization conditions, and control the order of module startup.
Syntax
Parameters
-
config:
ContainerConfig
— configuration object for the container- id (
string
) - Required. Unique identifier of the container. - start (
(deps?: DepsApi, optDeps?: OptionalDepsApi) => { api: {} }
) - Required. Initialization function of the container, invoked upon activation. Accepts strict (dependsOn
) and optional (optionalDependsOn
) dependencies and returns an object{ api: {} }
. - enable (
() => boolean | Promise<boolean>
) - Optional. Function that determines if the container will be activated. Returnstrue
to activate the container, andfalse
to set the container tooff
. - dependsOn (
Container[]
) - Optional. List of strict dependencies. These containers must be in thedone
status for the current container to transition topending
. - optionalDependsOn (
Container[]
) - Optional. List of optional dependencies. These containers can be in thedone
,fail
, oroff
status for the current container to activate.
- id (
Example
Features and Notes
- Optional enable parameter: If
enable
is not specified, the container is considered activated by default. - Dependency handling:
dependsOn
andoptionalDependsOn
control the activation order and conditions, referring to other containers.