@ticatec/node-common-library
Version:
A comprehensive Node.js database access framework providing robust abstractions for database connection management, SQL execution, transaction handling, pagination, and dynamic query building.
51 lines • 1.63 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const log4js_1 = __importDefault(require("log4js"));
const BeanFactory_1 = __importDefault(require("./BeanFactory"));
const Scope_1 = require("./Scope");
class Beans {
constructor() {
this._types = {};
this.logger = log4js_1.default.getLogger('Beans');
}
/**
* 获取Beans的单例实例
* @static
* @returns Beans单例对象
*/
static getInstance() {
if (Beans.instance == null) {
Beans.instance = new Beans();
}
return Beans.instance;
}
/**
* 注册一个Bean类型
* @param name - Bean的名称
* @param loader - Bean的加载器函数
* @param scope - Bean的作用域,默认为单例模式
*/
register(name, loader, scope = Scope_1.Scope.Singleton) {
this.logger.debug(`注册类型${name}`);
this._types[name] = { loader, scope };
}
/**
* 加载所有注册的Bean类型到BeanFactory中
* @returns Promise完成加载操作
*/
async load() {
this.logger.debug('引入注册类型', this._types);
for (let t in this._types) {
let v = this._types[t];
if (v.loader != null) {
let classLoader = (await v.loader()).default;
BeanFactory_1.default.register(t, classLoader, v.scope);
}
}
}
}
exports.default = Beans;
//# sourceMappingURL=Beans.js.map
;