UNPKG

moleculer-ioc

Version:

IOC support for Moleculer via Inversify

34 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoggerType = exports.ServiceBrokerType = exports.IOCService = void 0; const inversify_1 = require("inversify"); const moleculer_1 = require("moleculer"); class IOCService extends moleculer_1.Service { constructor(broker) { super(broker); this.broker = broker; // Create the container for the service this.container = new inversify_1.Container(); // Bind the service broker this.container .bind(exports.ServiceBrokerType) .toConstantValue(this.broker); // Load the defined modules this.container.load(...this.modules()); } parseServiceSchema(schema) { // Hook into the created lifecycle event const mergedSchema = this.mergeSchemas({ created: () => { this.container .bind(exports.LoggerType) .toConstantValue(this.logger); }, }, schema); super.parseServiceSchema(mergedSchema); } } exports.IOCService = IOCService; exports.ServiceBrokerType = Symbol.for("ServiceBroker"); exports.LoggerType = Symbol.for("Logger"); //# sourceMappingURL=index.js.map