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.

45 lines (44 loc) 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var behaviorSyntax_1 = require("./behaviorSyntax"); var buildInArgumentsNamesProvider_1 = require("../buildInArgumentsNamesProvider"); /** * Represents an syntax extention that allow relate aliases to targets and specify containers. */ var RelationSyntax = /** @class */ (function () { /** * Creates a new relation syntax that allow relates aliases to targets with the given kernel. * @param kernel Reprersents the kernel where the binding is happening. */ function RelationSyntax(containerizedKernel) { // Resolving it with poors man constructor. :( this._argumentsNamesProvider = new buildInArgumentsNamesProvider_1.BuildInArgumentsNamesProvider(); this._containerizedKernel = containerizedKernel; } /** * Creates a bind for the alias and allow fluently configure it. * @param alias Represents the alias to bind. * @return A syntax extension to associate the target or setup a container. */ RelationSyntax.prototype.bind = function (alias) { this._alias = alias; return this; }; /** * Associate the given target to the current bind. * @param reference Represets the target that will be associated to the current bind. * @return A syntax extension to setup the dependencies, servicing, delivery and conditions. */ RelationSyntax.prototype.to = function (reference) { var isArgumentable = this._argumentsNamesProvider.isArgumetable(reference); var dependencyMetadata = { activationReference: reference, isArgumentable: isArgumentable, argumentsNames: isArgumentable ? this._argumentsNamesProvider.getArgumentsNames(reference) : [] }; var identifier = this._containerizedKernel.registerDependencyMetadata(this._alias, dependencyMetadata); return new behaviorSyntax_1.BehaviorSyntax(dependencyMetadata); }; return RelationSyntax; }()); exports.RelationSyntax = RelationSyntax;