UNPKG

@jems/di

Version:

An implementation of IoC pattern based on dependency injection that allows you to granulate and decouple your libraries or applications. Wrote using SOLID principles and a variety OOP patterns implementations.

39 lines (38 loc) 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var servicingError_1 = require("../errors/servicingError"); /** * Represents a servicing strategy that transform and serve dependency metadata references as an instance. */ var InstanceServicingStrategy = /** @class */ (function () { function InstanceServicingStrategy() { } /** * Serve the result of the given reference target transformation. * @param resolutionContext Represents the resolution context of the servicing. * @param dependencyMetadata Represents the dependency metadata to transformed. * @return The transformed reference target. */ InstanceServicingStrategy.prototype.serve = function (resolutionContext, dependencyMetadata) { if (!dependencyMetadata.isArgumentable) { throw new servicingError_1.ServicingError("The provided metadata reference target of type [" + typeof dependencyMetadata.activationReference + "], is not argumentable."); } var argumets = [null]; dependencyMetadata.argumentsNames.forEach(function (argumentName) { var argument; if (resolutionContext && resolutionContext.resolutionOption && resolutionContext.resolutionOption.dependencies && resolutionContext.resolutionOption.dependencies[argumentName]) { argument = resolutionContext.resolutionOption.dependencies[argumentName]; } else { argument = resolutionContext.kernel.usingContainer(resolutionContext.originContainerAlias).resolveWithContext(argumentName, resolutionContext); } argumets.push(argument); }); return new (Function.prototype.bind.apply(dependencyMetadata.activationReference, argumets))(); }; return InstanceServicingStrategy; }()); exports.InstanceServicingStrategy = InstanceServicingStrategy;