UNPKG

node-web-mvc

Version:
47 lines (46 loc) 1.63 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Tracer_1 = __importDefault(require("../../servlets/annotations/annotation/Tracer")); class BeanDefinition { /** * 对应的类 */ get clazz() { return this.beanType; } static toBeanName(name) { if (typeof name === 'string' || name == null || name === undefined) { return name; } const beanName = String(name === null || name === void 0 ? void 0 : name.name); return beanName.slice(0, 1).toLowerCase() + beanName.slice(1, beanName.length); } /** * 构造一个bean定义 * @param clazz bean构造函数 * @param scope 作用域 */ constructor(clazz, method, scope) { var _a; // 表示是函数创建bean this.beanType = method ? null : clazz; this.methodClazz = method ? clazz : null; this.method = method; this.path = ((_a = Tracer_1.default.getTracer(clazz)) === null || _a === void 0 ? void 0 : _a.id) || clazz.name; this.scope = scope || 'singleton'; } /** * 如果是函数创建bean,由于typescript在函数没有显示指定返回类型时,无法获取返回值类型 * 为了补全clazz 在创建实例后会根据实例类设置clazz类型 * @param clazz */ fallbackBeanType(clazz) { if (!this.beanType) { this.beanType = clazz; } } } exports.default = BeanDefinition;