@absolunet/ioc2.1.0

View on GitHub

Application

The main Node IoC application class that does all the bootstrapping over core providers and allow module registration.

Extends

Members

version :string

Source:
Get current application version.

booted :boolean

Source:
Booted accessor.

environment :string

Source:
Current environment accessor.

environment

Source:
Current environment mutator.

Methods

register(provider)

Source:
Register a service provider.
Parameters:
Name Type Description
provider foundation.ServiceProvider The service provider class to register.

getProviderModel(provider)

Source:
Get provider model object.
Parameters:
Name Type Description
provider foundation.ServiceProvider The service provider class.
Returns:
The provider model.
Type
Object

ensureProviderCanBeRegistered()

Source:
Ensure that a provider can be properly registered, either before or after booting, but not during providers booting phase.
Throws:
Indicates that the provider was register during booting process.
Type
TypeError

pushProvider(provider)

Source:
Insert service provider in the application at the end of the list.
Parameters:
Name Type Description
provider foundation.ServiceProvider The service provider class.
Returns:
The provider model.
Type
Object

unshiftProvider(provider)

Source:
Insert service provider in the application at the beginning of the list.
Parameters:
Name Type Description
provider foundation.ServiceProvider The service provider class.
Returns:
The provider model.
Type
Object

boot()

Source:
Boot the application.
Throws:
Indicates that the application was already booted.
Type
TypeError
Returns:
The current application instance.
Type
foundation.Application

bootCoreProviders()

Source:
Boot core service providers.

registerProvider(model)

Source:
Register the given service provider.
Parameters:
Name Type Description
model Object The provider model.

isRegistered(provider)

Source:
Check if a given provider is registered.
Parameters:
Name Type Description
provider foundation.ServiceProvider The service provider class.
Returns:
Indicates that the service provider was already registered.
Type
boolean

bootProvider(model)

Source:
Boot the given service provider.
Parameters:
Name Type Description
model Object The provider model.

bootIfNotBooted()

Source:
Boot the container if it was not booted yet.
Returns:
The current application instance.
Type
foundation.Application

configurePaths(paths)

Source:
Configure application paths.
Parameters:
Name Type Default Description
paths object.<string, string> | string | null null The paths to configure into the application.
Throws:
Indicates that the base path was never defined.
Type
TypeError
Returns:
The current application instance.
Type
foundation.Application

configureNamespaces(namespaces)

Source:
Configure application namespaces.
Parameters:
Name Type Description
namespaces object.<string, string> The namespaces to configure into the application.
Returns:
The current application instance.
Type
foundation.Application

configureDefaultPaths()

Source:
Configure default paths within the container.
Returns:
The current application instance.
Type
foundation.Application

replacePaths(from, to, isSource)

Source:
Replace bound paths that matches the given original one by a new one.
Example
this.bind('app.foo', '/base/foo/path');
this.bind('app.bar', '/base/bar/path');
this.bind('app.baz', '/some/baz/path');
this.replacePaths('/base/', '/new/');
this.make('app.foo'); // "/new/foo/path"
this.make('app.bar'); // "/new/bar/path"
this.make('app.baz'); // "/some/baz/path" (hasn't changed since not matching)
Parameters:
Name Type Default Description
from string The original path to replace.
to string The new path that replaces the older.
isSource boolean false Indicates that the replacement must affect.
Returns:
The current application instance.
Type
foundation.Application

useHomePath(homePath)

Source:
Use specific home path.
Parameters:
Name Type Description
homePath string The new home path.
Returns:
The current application instance.
Type
foundation.Application

useBasePath(basePath)

Source:
Use base path for all registered paths.
Parameters:
Name Type Description
basePath string The new base path.
Returns:
The current application instance.
Type
foundation.Application

useAppPath(appPath)

Source:
Use application path for all application-related registered paths.
Parameters:
Name Type Description
appPath string The new application relative path.
Returns:
The current application instance.
Type
foundation.Application

useSourcePath(sourcePath)

Source:
Use source path for all application-related registered paths.
Parameters:
Name Type Description
sourcePath string The new source path.
Returns:
The current application instance.
Type
foundation.Application

useDistributionPath(distributionPath)

Source:
Use source path for all application-related registered paths.
Parameters:
Name Type Description
distributionPath string The new distribution path.
Returns:
The current application instance.
Type
foundation.Application

formatPath(…segments)

Source:
Format given path or path segments.
Parameters:
Name Type Attributes Description
segments string <repeatable>
The segments to join when formatting.
Returns:
The formatted path.
Type
string

path(type, relativePathopt)

Source:
Get full path from given base path type.
Parameters:
Name Type Attributes Description
type string The path type to use.
relativePath string | Array.<string> <optional>
The relative path or path segments from the path type.
Returns:
The formatted path from the path type.
Type
string

homePath(relativePathopt)

Source:
Get full path from home path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from home path.
Returns:
The formatted path from home path.
Type
string

appPath(relativePathopt)

Source:
Get full path from app path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from app path.
Returns:
The formatted path from app path.
Type
string

basePath(relativePathopt)

Source:
Get full path from base path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from base path.
Returns:
The formatted path from base path.
Type
string

configPath(relativePathopt)

Source:
Get full path from config path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from config path.
Returns:
The formatted path from config path.
Type
string

controllerPath(relativePathopt)

Source:
Get full path from controller path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from controller path.
Returns:
The formatted path from controller path.
Type
string

commandPath(relativePathopt)

Source:
Get full path from command path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from command path.
Returns:
The formatted path from command path.
Type
string

databasePath(relativePathopt)

Source:
Get full path from database path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from database path.
Returns:
The formatted path from database path.
Type
string

distributionPath(typeopt, relativePathopt)

Source:
Get full path from distribution path. If a type is provided first, the relative path to the source folder type will be returned. Otherwise, the full path from the source folder will be returned.
Parameters:
Name Type Attributes Description
type string <optional>
Either the source type name, or the relative path.
relativePath string <optional>
The relative path from the given source folder type.
Returns:
The formatted path from distribution path.
Type
string

langPath(relativePathopt)

Source:
Get full path from lang path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from lang path.
Returns:
The formatted path from lang path.
Type
string

policyPath(relativePathopt)

Source:
Get full path from policies path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from policies path.
Returns:
The formatted path from policies path.
Type
string

providerPath(relativePathopt)

Source:
Get full path from provider path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from provider path.
Returns:
The formatted path from provider path.
Type
string

publicPath(relativePathopt)

Source:
Get full path from public path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from public path.
Returns:
The formatted path from public path.
Type
string

resourcesPath(relativePathopt)

Source:
Get full path from resources path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from resources path.
Returns:
The formatted path from resources path.
Type
string

routesPath(relativePathopt)

Source:
Get full path from routes path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from resources path.
Returns:
The formatted path from resources path.
Type
string

sourcePath(typeopt, relativePathopt)

Source:
Get full path from source path. If a type is provided first, the relative path to the source folder type will be returned. Otherwise, the full path from the source folder will be returned.
Parameters:
Name Type Attributes Description
type string <optional>
Either the source type name, or the relative path.
relativePath string <optional>
The relative path from the given source folder type.
Returns:
The formatted path from source path.
Type
string

storagePath(relativePathopt)

Source:
Get full path from storage path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from storage path.
Returns:
The formatted path from storage path.
Type
string

testPath(relativePathopt)

Source:
Get full path from test path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from test path.
Returns:
The formatted path from test path.
Type
string

uploadPath(relativePathopt)

Source:
Get full path from upload path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from upload path.
Returns:
The formatted path from upload path.
Type
string

viewPath(relativePathopt)

Source:
Get full path from view path.
Parameters:
Name Type Attributes Description
relativePath string | Array.<string> <optional>
The relative path from view path.
Returns:
The formatted path from view path.
Type
string

onBooting(callback)

Source:
Register 'application.booting' callback.
Parameters:
Name Type Description
callback function The listener.
Returns:
The current application instance.
Type
foundation.Application

onBooted(callback)

Source:
Register 'application.booted' callback. Will be instantly called if already booted.
Parameters:
Name Type Description
callback function The listener.
Returns:
The current application instance.
Type
foundation.Application

setVersion(versionopt)

Source:
Set current application version.
Parameters:
Name Type Attributes Description
version string | number <optional>
The application version.
Returns:
The current application instance.
Type
foundation.Application

getIocVersion()

Source:
Current Node IoC version.
Returns:
The current Node IoC version.
Type
string

setEnvironment(environment)

Source:
Set the current environment.
Parameters:
Name Type Description
environment string The environment.
Returns:
The current application instance.
Type
foundation.Application

setContext(context)

Source:
Inherited From:
Set JavaScript module context.
Parameters:
Name Type Description
context module The Node.js module that represents the current context.
Returns:
The current container instance.
Type
container.Container

getContext()

Source:
Inherited From:
Get current JavaScript module context.
Returns:
The Node.js module that represents the current context.
Type
module

bind(abstract, concrete, shared)

Source:
Inherited From:
Bind abstract to the container.
Parameters:
Name Type Default Description
abstract string Abstract representation of a concrete. Should be treated as an interface.
concrete function | * Concrete reflecting the abstract. Can be either a class, a factory closure, an instance or even a primitive value, such as a string or a boolean.
shared boolean false Indicates that the concrete should be treated as a singleton and be shared through all the other instances when requested.
Returns:
The current container instance.
Type
container.Container

singleton(abstract, concrete)

Source:
Inherited From:
Bind abstract as a singleton to the container.
Parameters:
Name Type Description
abstract string Abstract representation of a concrete. Should be treated as an interface.
concrete function | * Concrete reflecting the abstract. Can be either a class, a factory closure, an instance or even a primitive value, such as a string or a boolean.
Returns:
The current container instance.
Type
container.Container

make(abstract, parametersopt)

Source:
Inherited From:
Resolve a given argument with either its singleton, a new instance based on bindings or a new instance with resolved dependencies.
Parameters:
Name Type Attributes Default Description
abstract * An abstract that was bound to the container, or a class, closure or instance that can be built by the container.
parameters object.<string, *> <optional>
{} Additional arguments to inject into the concrete when instantiating.
Returns:
The instantiated or the singleton concrete.
Type
*

resolve(abstract, parametersopt)

Source:
Inherited From:
Resolve a given abstract to build a new instance.
Parameters:
Name Type Attributes Default Description
abstract * An abstract that was bound to the container, or a class, closure or instance that can be built by the container.
parameters object.<string, *> <optional>
{} Additional arguments to inject into the concrete when instantiating.
Returns:
The instantiated concrete.
Type
*

isBound(abstract)

Source:
Inherited From:
Check if the given abstract is bound to the container.
Parameters:
Name Type Description
abstract string The abstract to check.
Returns:
Indicates if the abstract is bound in the container.
Type
boolean

getBounds()

Source:
Inherited From:
Get all bindings.
Returns:
List of abstracts bound into the container.
Type
Array.<string>

getSingleton(abstract)

Source:
Inherited From:
Get singleton from its abstract.
Parameters:
Name Type Description
abstract string The abstract name that reflects a singleton already instantiated.
Returns:
The singleton instance.
Type
*

isSingleton(abstract)

Source:
Inherited From:
Check if a given abstract has a resolved singleton.
Parameters:
Name Type Description
abstract string The abstract name that may reflect an instantiated singleton.
Returns:
Indicates that the singleton exists and was already instantiated.
Type
boolean

instantiate(Concrete, parametersopt)

Source:
Inherited From:
Instantiate a given class and resolve its dependencies.
Parameters:
Name Type Attributes Default Description
Concrete function A class that can be instantiated.
parameters object.<string, *> <optional>
{} Additional arguments to inject into the class instance when instantiating.
Returns:
The newly created instance.
Type
*

call(factory, parametersopt)

Source:
Inherited From:
Call a given function with the given arguments.
Parameters:
Name Type Attributes Default Description
factory function A closure that factories a concrete.
parameters object.<string, *> <optional>
{} Additional arguments to inject into the factory when calling it.
Returns:
The factoried concrete.
Type
*

assign(object, parametersopt)

Source:
Inherited From:
Make a mass assignment to a given object.
Parameters:
Name Type Attributes Default Description
object * An instance that can receive parameters by assignation.
parameters object.<string, *> <optional>
{} Additional arguments to associate to the instance.
Returns:
The instance.
Type
*

build(concrete, parametersopt)

Source:
Inherited From:
Build a given concrete, either a factory, a class or an object.
Parameters:
Name Type Attributes Default Description
concrete function | * A concrete that can be either instantiated, called or assigned.
parameters object.<string, *> <optional>
{} Additional arguments to inject into the concrete when instantiating.
Returns:
The built concrete.
Type
*

decorate(abstract, decorator)

Source:
Inherited From:
Decorate a given abstract with a callback.
Parameters:
Name Type Description
abstract string The abstract to decorate.
decorator function The decorator function.
Returns:
The current container instance.
Type
container.Container

tag(abstract, tag)

Source:
Inherited From:
Tag a given abstract.
Parameters:
Name Type Description
abstract string | Array.<string> The abstract(s) to tag.
tag string The tag to give to the abstract(s).
Returns:
The current container instance.
Type
container.Container

alias(alias, abstract)

Source:
Inherited From:
Alias an abstract.
Parameters:
Name Type Description
alias string The alias to given.
abstract string The abstract to associate to the alias.
Returns:
The current container instance.
Type
container.Container

isTag(tag)

Source:
Inherited From:
Check if the given string was used as a tag.
Parameters:
Name Type Description
tag string The tag name.
Returns:
Indicates if the tag exists.
Type
boolean

getTagged(tag)

Source:
Inherited From:
Get tagged dependencies from the tag name.
Parameters:
Name Type Description
tag string The tag name.
Returns:
The instances associated to the given tag, in a dictionary, mapping the abstract name to the concrete.
Type
object.<string, *>

flush()

Source:
Overrides:
Flush container from attached abstracts and concretes.
Returns:
The current container instance.
Type
container.Container

bindingNotFound(abstract)

Source:
Inherited From:
Throw an error announcing that the given abstract was not found.
Parameters:
Name Type Description
abstract string The abstract that was not found.
Throws:
Indicates that the given abstract was not found in the container.
Type
TypeError

getModule(filePath)

Source:
Inherited From:
Check if the given file is a valid and existing JavaScript file with a valid extension.
Parameters:
Name Type Description
filePath string The file path to load.
Throws:
Indicates that an error occurred during file loading or parsing.
Type
Error
Returns:
The file parsed value, or null if not found.
Type
*