New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

tokioc

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tokioc

Another simple IOC

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

#Tokioc ##A very simple IOC container for NodeJS

Code ClimateIssue Count

###How to use ####Install tokioc npm install tokioc ####Get Tokioc container instance

var ioc = require('tokioc');

####Registration

Tokioc supports the registration of objects and constructors.

#####Object registration

var target = {
    propA: 'propA'
};
ioc.register('objByNameSingleInstance', target);

#####Constructor registration

var Target = function () {
    var self = this;
    self.now = new Date();
};
ioc.register('objByNameCtor', Target);

####Customizable lifetime manager Tokioc comes by default with a simple instance manager which caches resolved instances. Lifetime managers can be customized for different purposes. Lifetime managers must support setInstance and getInstance methods.

/**
 *  Container lifetime manager
 */
var ContainerLifetimeResolutionManager = function () {
    var _instances = {};
    function setInstance(name, target) {
        _instances[name] = target;
    }
    /**
     * Gets instance by name
     */
    function getInstance(name) {
        return _instances[name];
    }
    this.setInstance = setInstance;
    this.getInstance = getInstance;
};

Register a dependency with a custom lifetime manager:

ioc.register('objByNameCtor', Target, new CustomLifetimeManager());

####Dependencies

Dependencies can only be declared on constructor registrations. Declare dependencies this way:

var Obj1 = function (obj2) {
    var self = this;
    self.obj2 = obj2;
};
var Obj2 = function () {
    var self = this;
};
ioc.register('objByNameCtor', Obj1);
ioc.register('objByNameCtor2', Obj2);
Obj1.$dependencies = ['objByNameCtor2'];

Keep in mind that the constructor dependencies are applied in the order of the $dependencies array. ####Resolution

Resolve using the resolve method:

ioc.resolve('objByRef5', function (instance) { /* Do what you will with the resolution */ });

Keywords

simple

FAQs

Package last updated on 03 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts