Konteiner is implemented as a class providing following API.
- all dependencies are stored/retrieved by name of its class or function creator, i.e. 'function testDependency() {}' => 'testDependency'
- function dependencies factories are invoked upon first
.get
method call, ie. lazy initialization
- new instance of Konteiner
options
optional Objectexclude
(aliasskipFiles
) - optional string[]- sets default for
.registerPath
- when registering dependency, files can be excluded by matching pattern over the path.
- sets default for
dirSearchDepth
- optional number- sets default for
.registerPath
- maximum dir depth to search for dependencies
1
(default) - only specified directory>0
- registers whole subtree
- sets default for
supportedExtensions
- optional string[]- sets default for
.registerPath
- if provided path is not found, provided extensions will be appended and tested
['.js']
(default)
- sets default for
-
Registers dependency factory (if function/class) or dependency
-
dependencyCreator
- class or function- if function - stored as uninitialized, instance will be initialized upon
.get
- otherwise - stored as initialized, provided as-is
- if function - stored as uninitialized, instance will be initialized upon
-
option
- optional Objecttags
- optional string[]- dependency will be stored with given tag for retrieval using
.getByTag
- dependency will be stored with given tag for retrieval using
-
Loads dependencies from filesystem
-
Some options may have set defaults using constructor
-
path
- string- path to load
- if file
options.supportedExtensions
may apply - if directory
options.dirSearchDepth
may apply
-
options
- optional Objectexclude
(aliasskipFiles
) - optional string[]- when registering dependency, files can be excluded by matching pattern over the path.
- usage overrides default from constructor
dirSearchDepth
- optional number- maximum dir depth to search for dependencies
1
(default) - only specified directory>0
- registers whole subtree
- usage overrides default from constructor
- maximum dir depth to search for dependencies
supportedExtensions
- optional string[]- if provided path is not found, provided extensions will be appended and tested
['.js']
(default)
- usage overrides default from constructor
- if provided path is not found, provided extensions will be appended and tested
tags
- optional string[]- dependency will be stored with given tag for retrieval using
.getByTag
- dependency will be stored with given tag for retrieval using
- retrieves dependency
- initializes if applicable
- provides initialized instance
- retrieves dependencies with tag
- initializes if applicable
- provides initialized instances
Provides Map<dependencyCreator, SimpleRef>, that can be used to custom investigation of dependencies, or printing out dependencies map after some post processing.
- key - dependencyCreator - dependency creator which is provided
- value - SimpleRef wrapping information about given creator and its dependencies
name
- string - dependencyCreator name,{anonymous Fn}
if anonymouspath
- string - from while file was dependency loaded (if applicable)type
- string -Callable
orConstructible
initialized
- boolean -.initialized
dependencyCreator
- creator for initializing dependency instanceinstance
- any - set once initialized,.getInstance()
dependenciesRefs
- Set - set of references to used dependencies
- Ref can be converted to SimpleRef via
new SimpleRef(ref)
name
- string - dependency name retrieved from dependencyCreatorpath
- string - from while file was dependencyloaded (if applicable)type
- string -Callable
orConstructible
initialized
- booleaninstance
- any - set once initialized,.getInstance()
dependencies
- Array - array of simple references to used dependencies
- user attempted to register anonymous function directly (not done via registerPath)
- this scenario does not make sense, since there would be no way to retrieve
message
- string - "Anonymous dependencies wo/path not supported - now way of retrieving them"
- attempted get operation for not registered dependency
message
- string - e.g. 'Dependency "dependencyName" is not registered'dependencyCreator
- any - item by which was attempted the get instance operation
- attempted get operation for tag not used in any register operation
message
- string - e.g. 'No dependency with tag "routes" is registered'tag
- any - tag used for get by tag operation
- during initialization of dependency found dependency loop
message
- string - e.g. 'Cyclic dependency found! ["dependencyA"->"dependencyB"->"dependencyA"]'dependencies
- string[] - e.g. ["dependencyA", "dependencyB", "dependencyA"]