Class: ServiceContainer

ServiceContainer

Service container class.


new ServiceContainer(name [, options])

Parameters:
Name Type Argument Description
name string

The name of the container instance.

options object <optional>

Container options

Properties:
Name Type Argument Default Description
options.env string <optional>

Environment, default to process.env.NODE_ENV

options.workingPath string <optional>

App's working path, default to process.cwd()

options.configPath string <optional>

App's config path, default to "conf" under workingPath

options.configName string <optional>

App's config basename, default to "app"

options.disableEnvAwareConfig string <optional>
false

Don't use environment-aware config

options.allowedFeatures array <optional>

A list of enabled feature names

options.loadConfigFromOptions boolean <optional>
false

Whether to load config from passed-in options

options.config object <optional>

Config in options, used only when loadConfigFromOptions

Source:
ServiceContainer.js

Extends

  • EventEmitter

Members


config :object

App configuration

Type:
  • object
Source:
ServiceContainer.js

configLoader :ConfigLoader

Configuration loader instance

Type:
  • ConfigLoader
Source:
ServiceContainer.js

configName :string

Config basename

Type:
  • string
Source:
ServiceContainer.js

configPath :string

Config path

Type:
  • string
Source:
ServiceContainer.js

env :string

Environment flag

Type:
  • string
Source:
ServiceContainer.js

features :object

Loaded features, name => feature object

Type:
  • object
Source:
ServiceContainer.js

name :object

Name of the app

Type:
  • object
Source:
ServiceContainer.js

options :object

App options

Type:
  • object
Source:
ServiceContainer.js

services :object

Loaded services

Type:
  • object
Source:
ServiceContainer.js

started :bool

Flag showing the app is started or not.

Type:
  • bool
Source:
ServiceContainer.js

workingPath :string

Working directory of this cli app

Type:
  • string
Source:
ServiceContainer.js

Methods


addFeatureRegistry(registry)

Add more or overide current feature registry

Parameters:
Name Type Description
registry object
Source:
ServiceContainer.js

enabled(feature)

Check whether a feature is enabled in the app.

Parameters:
Name Type Description
feature string
Source:
ServiceContainer.js
Returns:
Type
bool

getService(name)

Get a service from module hierarchy

Parameters:
Name Type Description
name
Source:
ServiceContainer.js
Returns:
Type
object

hasService(name)

Check whether a service exists

Parameters:
Name Type Description
name *
Source:
ServiceContainer.js
Returns:
Type
boolean

<async> loadConfig_()

Source:
ServiceContainer.js
Returns:
Type
ServiceContainer

log(level, message, rest)

Default log method, may be override by loggers feature

Parameters:
Name Type Argument Description
level string

Log level

message string

Log message

rest object <repeatable>

Extra meta data

Source:
ServiceContainer.js
Returns:
Type
ServiceContainer

logException(level, error, summary)

Helper method to log an exception

Parameters:
Name Type Description
level *
error *
summary *
Source:
ServiceContainer.js
Returns:
Type
ServiceContainer

registerService(name, serviceObject, override)

Register a service

Parameters:
Name Type Description
name string
serviceObject object
override boolean
Source:
ServiceContainer.js

replaceLogger(logger)

Replace the default logger set on creation of the app.

Parameters:
Name Type Description
logger Logger
Source:
ServiceContainer.js

<async> start_()

Start the container.

Source:
ServiceContainer.js
Fires:
Returns:
Type
Promise.<ServiceContainer>

<async> stop_()

Stop the container

Source:
ServiceContainer.js
Fires:
Returns:
Type
Promise.<ServiceContainer>

toAbsolutePath(args)

Translate a relative path of this app module to an absolute path

Parameters:
Name Type Argument Description
args array <repeatable>

Array of path parts

Source:
ServiceContainer.js
Returns:
Type
string

Events


configLoaded

Config loaded event.

Source:
ServiceContainer.js

ready

App ready

Source:
ServiceContainer.js

stopping

App stopping

Source:
ServiceContainer.js