UNPKG

tachijs

Version:

Highly testable dead simple web server written in Typescript

27 lines 952 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const decorators_1 = require("./decorators"); class Injector { constructor(container) { this.containerMap = new Map(Object.entries(container)); } instantiate(Constructor) { const injectMetaList = decorators_1.getInjectMetaList(Constructor); const args = injectMetaList.map(injectMeta => { try { return this.inject(injectMeta.key); } catch (error) { throw new Error(`${error.message} (While instantiating "${Constructor.name}")`); } }); return new Constructor(...args); } inject(key) { if (!this.containerMap.has(key)) throw new Error(`No service is registered for "${key}" key.`); return this.instantiate(this.containerMap.get(key)); } } exports.Injector = Injector; //# sourceMappingURL=Injector.js.map