pod.js
const inject = require('injectinto')
inject('pod', () => {
const db = inject.one('db')
db.key = 'value'
})index.js
const inject = require('injectinto')
const db = {}
inject('db', db)
for (let pod of inject.many('pod')) pod()I'd like to build systems that can easily be extended, enhanced, or replaced.
- One or more objects are bound to string keys, for example 'db'
- Other parts of the code can request objects by providing in the key, for example 'db'
inject(key, value)inject.bind(key, value)inject.unbind(key, value)inject.one(key)inject.oneornone(key)inject.many(key)inject.clear(key)inject.reset()
Register a value to a string key for retrieval later. Multiple calls will register multiple objects and be accessed via inject.many(key)
Remove a registered value for a key. Does not error if value is not found.
Return a single registered value for a given key. Will error if no value is found or if more than one value is found.
Return a single registered value or null for a given key. Will error if more than one value is found.
Return all registered values for a given key. Will return an empty array if no values are registered.
Clears all registered values for a given key.
Clears all registered values for all keys.