deepin
v1.0.6
Published
A Nodejs DI container
Downloads
55
Readme
Manage objects creation and dependencies using a descriptive way. It's a simple approach to inversion of control.
It currently only supports constructor injection by order, not by name
Install
$ yarn add deepin
Usage
/* importing UserController, UserService & UserRepository... */
import {Dependency, Injector} from 'deepin'
const injector = Injector.createAndResolve([
new Dependency('UserController', {useClass: UserController}, ['UserService']),
new Dependency('UserService', {useClass: UserService}, ['UserRepository']),
new Dependency('UserRepository', {useClass: UserRepository})
])
/**
* Create a brand new instance of the UserController
* on each call
*/
const userController = injector.get('UserController')
/**
* Always retrieve the SAME instance of a UserController
*/
const userController = injector.getUnique('UserController')
Shortcut usage for useClass :
/* importing UserController, UserService & UserRepository... */
import {give, Injector} from 'deepin'
const injector = Injector.createAndResolve([
give(UserController, ['UserService']),
give(UserService, ['UserRepository']),
give(UserRepository)
])
See also
License
Copyright (c) 2017 Marvin Frachet
Licensed under the MIT license.