nralcm
Version:
This is a framework based on NodeJs to manage rest api request lifecycle
33 lines (32 loc) • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata/Reflect");
const functions_1 = require("../../common/functions");
/**
* Resolves Dependency Of controller
*/
class DependencyInjection {
constructor(context, httpResponse) {
this.context = context;
this.httpResponse = httpResponse;
}
/**
* Method to inject depedency
* @param context HttpContext Object in case when resolving dependency of controller. undefined when resolving dependency of class
* @param target class object when HttpContext undefined
*/
inject() {
let targetObject = this.context.controller;
const constructorParameterTypes = Reflect.getMetadata("design:paramtypes", targetObject);
if (constructorParameterTypes && constructorParameterTypes.length > 0) {
const constructorParameters = functions_1.getConstructorParameters(targetObject);
constructorParameterTypes.forEach((val, index) => {
this.context.controllerObject[constructorParameters[index]] = new val();
functions_1.circularInjection(val, this.context.controllerObject[constructorParameters[index]]);
});
}
this.context.controllerObject["request"] = this.context.request;
this.context.controllerObject["response"] = this.httpResponse;
}
}
exports.DependencyInjection = DependencyInjection;