pang
TypeScript icon, indicating that this package has built-in type declarations

0.6.0 • Public • Published

pang

A simple dependency injection library for node

npm install pang

example

The following example illustates setting up a pang domain/kernel.

 
var pang = require('pang')
 
var domain = pang.domain()
 
domain.factory('http', require('http'))
 
domain.factory('configuration', {
 
    server: {
 
        port: 8080
    }
})
 
domain.factory('repository', function(configuration) {
 
    return new Repository(configuration)
})
 
domain.factory('server', function(configuration, http, repository) {
    
    return new Server(configuration, http, repository)
})

domain.start()

Boots all instances in this domain and caches within the domain.

domain.start()

domain.singleton()

Returns a singleton instance from the domain. Will automatically start() the domain if not already started.

var instance = domain.singleton('repository')

domain.transient()

Returns a transient (new) instance from the domain.

var instance = domain.transient('repository')

/pang/

    Package Sidebar

    Install

    npm i pang

    Weekly Downloads

    1

    Version

    0.6.0

    License

    mit

    Last publish

    Collaborators

    • sinclair