UNPKG

dino-core

Version:

A dependency injection framework for NodeJS applications

65 lines 2.19 kB
"use strict"; // Copyright 2018 Quirino Brizi [quirino.brizi@gmail.com] // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. Object.defineProperty(exports, "__esModule", { value: true }); exports.Resolver = void 0; const awilix_1 = require("awilix"); class Resolver { constructor(id, primitive) { this.id = id; this.primitive = primitive; } getId() { return this.id; } isClassOrFunction() { return this.id === 'CLASS' || this.id === 'FUNCTION'; } asPrimitive() { return this.primitive; } /** * Wrap the target component to an awilix resolver. * @param {object} target the target component to wrap * @returns {any} the awilix resolver */ wrap(target) { return this.primitive(target); } /** * Lookup a resolver from it name * @param {String} name the name of the resolver to lookup * * @returns {Scope} the {@link Resolver} retrieved from it name * * @default Scope.SINGLETON * * @public */ static fromName(name) { switch (name.toUpperCase()) { case 'VALUE': return new Resolver('VALUE', awilix_1.asValue); case 'FUNCTION': return new Resolver('FUNCTION', awilix_1.asFunction); default: return new Resolver('CLASS', awilix_1.asClass); } } } exports.Resolver = Resolver; Resolver.CLASS = new Resolver('CLASS', awilix_1.asClass); Resolver.VALUE = new Resolver('VALUE', awilix_1.asValue); Resolver.FUNCTION = new Resolver('FUNCTION', awilix_1.asFunction); //# sourceMappingURL=resolver.js.map