UNPKG

power-di

Version:

A lightweight Dependency Injection library. Using es6 and other features, remove unnecessary concepts, easy and convenient to use.

28 lines 1.17 kB
"use strict"; 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, always = _b.always, optional = _b.optional, _d = _b.singleton, singleton = _d === void 0 ? true : _d; 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