power-di
Version:
A lightweight Dependency Injection library. Using es6 and other features, remove unnecessary concepts, easy and convenient to use.
28 lines • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.inject = void 0;
var utils_1 = require("../utils");
var metadata_1 = require("../class/metadata");
/**
* inject
*/
function inject(_a) {
var _b = _a === void 0 ? {} : _a, type = _b.type, _c = _b.lazy, lazy = _c === void 0 ? true : _c, _d = _b.always, always = _d === void 0 ? false : _d, _e = _b.optional, optional = _e === void 0 ? false : _e, _f = _b.singleton, singleton = _f === void 0 ? true : _f;
return function (target, key) {
var typeCls = (0, utils_1.getClsTypeByDecorator)(type, target, key);
if (typeCls === undefined || typeCls === Object) {
throw new Error("CANNOT inject undefined! source: ".concat(target.constructor.name, ".").concat(key.toString()));
}
(0, metadata_1.getMetadata)(target.constructor).injects.push({
key: key,
globalType: (0, utils_1.getGlobalTypeByDecorator)(type, target, key),
type: lazy ? 'lazyInject' : 'inject',
always: always,
typeCls: typeCls,
optional: optional,
singleton: singleton,
});
};
}
exports.inject = inject;
//# sourceMappingURL=inject.js.map