Namespace: ioc

system. ioc

The system.ioc library provides a simple and strong implementation of the Inversion of Control (IoC) principle.

IoC is also known as dependency injection (DI). It is a process whereby objects define their dependencies, that is, the other objects they work with, only through constructor arguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method.

The container then injects those dependencies when it creates the object definitions. This process is fundamentally the inverse, hence the name Inversion of Control (IoC), of the object definition itself controlling the instantiation or location of its dependencies by using direct construction of classes, or a more complex mechanism.

Author:
License:

Example

var Point = function( x , y )
{
    this.x = x ;
    this.y = y ;
    console.log("constructor:" + this.toString() ) ;
};

Point.prototype.test = function( message = null )
{
    console.log( 'test:' + this.toString() + " message:" + message ) ;
}

Point.prototype.toString = function()
{
    return "[Point x:" + this.x + " y:" + this.y + "]" ;
} ;

var ObjectFactory = system.ioc.ObjectFactory ;

var factory = new ObjectFactory();
var config  = factory.config ;

config.setConfigTarget
({
    origin : { x : 10 , y : 20 }
})

config.setLocaleTarget
({
    messages :
    {
        test : 'test'
    }
})

var objects =
[
    {
        id   : "position" ,
        type : "Point" ,
        args : [ { value : 2 } , { ref : 'origin.y' }],
        properties :
        [
            { name : "x" , ref   :'origin.x' } ,
            { name : "y" , value : 100       }
        ]
    },
    {
        id         : "origin" ,
        type       : "Point" ,
        singleton  : true ,
        args       : [ { config : 'origin.x' } , { value : 20 }] ,
        properties :
        [
            { name : 'test' , args : [ { locale : 'messages.test' } ] }
        ]
    }
];

factory.run( objects );

trace( factory.getObject('position') ) ;

Classes

ObjectArgument
ObjectConfig
ObjectDefinition
ObjectDefinitionContainer
ObjectFactory
ObjectListener
ObjectMethod
ObjectProperty
ObjectReceiver
ObjectStrategy
Parameters

Namespaces

MagicReference
ObjectAttribute
ObjectOrder
ObjectScope
ObjectStrategies
TypePolicy

Members


<static> logger :system.logging.Logger

The system.ioc internal logger singleton with the channel "system.ioc.logger".

Type: