@d3vtool/ex-frame
Version:
This library enhances Express.js by providing a more organized structure for web API projects, along with improved control and error handling capabilities.
20 lines (19 loc) • 873 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InjectSingleton = exports.InjectScoped = exports.InjectTransient = void 0;
const ex_helpers_1 = require("./ex-helpers");
function Injector(lifetime) {
return function (_targetFn, _propertyKey, descriptor) {
if (!descriptor?.value) {
throw new Error("Decorator can only be applied to methods.");
}
const serviceNameInArg = (0, ex_helpers_1.getFunctionArgs)(descriptor.value)[0];
descriptor.value[`${lifetime}ServiceName`] = serviceNameInArg.toLowerCase();
};
}
const InjectTransient = () => Injector("transient");
exports.InjectTransient = InjectTransient;
const InjectScoped = () => Injector("scoped");
exports.InjectScoped = InjectScoped;
const InjectSingleton = () => Injector("singleton");
exports.InjectSingleton = InjectSingleton;