mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
`bottlejs` does what we need and is much more widely used. Also, `bottlejs` doesn't do all the magic name extraction that `yaioc` does. That means less logic to reproduce in this facade if we change the underlying dependency later.
35 lines
773 B
JavaScript
35 lines
773 B
JavaScript
const Bottle = require('bottlejs');
|
|
|
|
/**
|
|
* Container for JSDoc classes, objects, and values that can be injected into other modules.
|
|
*
|
|
* @alias module:@jsdoc/core.deps
|
|
*/
|
|
class Dependencies {
|
|
constructor() {
|
|
// This class provides a lightweight facade for the `bottlejs` package.
|
|
this._bottle = new Bottle();
|
|
this._container = this._bottle.container;
|
|
}
|
|
|
|
get(name) {
|
|
const dep = this._container[name];
|
|
|
|
if (dep === undefined) {
|
|
throw new Error(`No dependency registered for the name "${name}"`);
|
|
}
|
|
|
|
return dep;
|
|
}
|
|
|
|
registerClass(name, constructor, ...deps) {
|
|
this._bottle.service(name, constructor, ...deps);
|
|
}
|
|
|
|
registerValue(name, value) {
|
|
this._bottle.constant(name, value);
|
|
}
|
|
}
|
|
|
|
module.exports = Dependencies;
|