UNPKG

node-web-mvc

Version:
44 lines (43 loc) 2.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const RuntimeAnnotation_1 = __importDefault(require("../../servlets/annotations/annotation/RuntimeAnnotation")); const Bean_1 = __importDefault(require("../annotations/Bean")); const Configuration_1 = __importDefault(require("../annotations/Configuration")); const DefaultListableBeanFactory_1 = require("../factory/DefaultListableBeanFactory"); const InstantiationAwareBeanPostProcessor_1 = __importDefault(require("./InstantiationAwareBeanPostProcessor")); class ConfigurationBeanPostProcessor extends InstantiationAwareBeanPostProcessor_1.default { constructor(beanFactory) { super(); this.beanFactory = beanFactory; } postProcessBeforeInitialization(beanType, beanName) { return null; } postProcessAfterInitialization(beanInstance, beanName) { const beanType = beanInstance === null || beanInstance === void 0 ? void 0 : beanInstance.constructor; if (beanInstance && RuntimeAnnotation_1.default.hasClassAnnotation(beanType, Configuration_1.default)) { // 代理配置实例方法 this.proxyConfigurationInstance(beanInstance, beanType); } return beanInstance; } postProcessProperties(pvs, beanInstance, beanName) { return pvs; } proxyConfigurationInstance(proto, beanType) { const annotations = RuntimeAnnotation_1.default.getAnnotations(Bean_1.default, beanType); const beanFactory = this.beanFactory; annotations.forEach((anno) => { const name = anno.method[DefaultListableBeanFactory_1.methodBeanNameSymbol]; proto[anno.methodName] = new Proxy(anno.method, { apply() { return beanFactory.getBean(name); }, }); }); } } exports.default = ConfigurationBeanPostProcessor;