1.0.0 • Published 6 years ago

konteiner v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

konteiner - simple zero-dependencies DI container for node.js apps

Build Status Coverage Status

This module provides you means to:

  • register desired modules (objects, functions, classes) to DI container
  • use the initialized dependencies in modules by obtaining them from constructor/parent function
  • having the modules initialized in lazy manner, ie. on first konteiner.get call

Usage

  • Install the dependency npm i --save konteiner@latest
  • In JS code
const Konteiner = require('konteiner')

const konteiner = new Konteiner()
// following lines will just register dependencies, init is made upon first get for affected dependencies
konteiner.register('logger', () => console)
konteiner.register('demoMessenger', (logger) => {
	return {
		sendMessage(text) { logger.log(text) }
	}
})

const messenger = konteiner.get('demoMessenger') // this will actually invoke the constructor of demoMessenger (and logger, since it is a dependency of demoMessenger)
messenger.sendMessage('Hello world!') // console.log will print out 'Hello world!'

If you want to load all dependencies in an directory, you can also do following.

const Konteiner = require('konteiner')
const konteiner = new Konteiner({exclude: [
	'\\.test\\.' // all test files will be omitted from batch loading using .registerPath
]})

konteiner.registerPath('./src', {exclude: [
	'\\.test\\.',
	'index\\.js'
]}) // all but tests and index.js will be loaded. Overrides exclude from constructor for this call only

const someService = konteiner.get('someService') // all dependencies bound to someService will be now initialized
...

For more details, see API section.

1.0.0

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago