UNPKG

@zerooneit/expressive-tea

Version:
84 lines (83 loc) 3.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MultiInject = exports.InjectTagged = exports.InjectNamed = exports.Inject = void 0; const inversify_1 = require("inversify"); const inversify_inject_decorators_1 = require("inversify-inject-decorators"); const rootContainer = new inversify_1.Container({ autoBindInjectable: true }); const lazyDecorators = (0, inversify_inject_decorators_1.default)(rootContainer); /** * @module Services */ /** * This Class contain the helpers to add on the dynamically Dependency Injection Providers which will be used globally * by all the components. * @class DependencyInjection * @summary Define a Dependency Injection Provider */ class DependencyInjection { /** * This assign to the global inversify container Express Tea can set provider as user required to the global container * and shareable to all registered modules. This method is used if required to assign a provider depending on params * or data flow. * * @param {Class} ProviderFactory - Assign the Class to serve as factory. * @param {string | symbol |never } [providerName="ClassName"] - Provide the provider identification. * @summary Add Provider to Dependency Injection Providers */ static setProvider(ProviderFactory, providerName) { if (!rootContainer.isBound(providerName || ProviderFactory.name)) { rootContainer.bind(providerName || ProviderFactory.name).to(ProviderFactory); } } } /** * This is the implementation of a global inversify container that helps to contains every Dependency Injection. * @type {InversifyContainers} * @static * @readonly * @summary Inversify Container */ DependencyInjection.Container = rootContainer; /** * @module Decorators/DependencyInjection */ /** * This annotation allow inject directly into a class property an instance of the provider as is passed on the * provider declaration, checkout * {@link https://github.com/inversify/InversifyJS/blob/master/wiki/classes_as_id.md Classes as ID} * from Inversify Project. * @decorator {PropertyDecorator} Inject - Inject a dependency constructor defined as provider. * @summary Inject a instance of provider defined as Dependency Injection. * @function */ exports.Inject = lazyDecorators.lazyInject; /** * This implement the Tagged Bindings from Inversify to used on the contructors arguments of the injectable classes and * allow not create ambiguous match as named annotation, also check out * {@link https://github.com/inversify/InversifyJS/blob/master/wiki/named_bindings.md Named Bindings} * from Inversify Project. * @decorator {ConstructorParameter} InjectNamed - Inject a provider instance on costructor arguments. * @summary Bind provider as named annotation. * @function */ exports.InjectNamed = lazyDecorators.lazyInjectNamed; /** * This implement the Named Bindings from Inversify to used on the contructors arguments of the injectable classes and * allow not create ambiguous match as tagged annotation. * {@link https://github.com/inversify/InversifyJS/blob/master/wiki/tagged_bindings.md Tagged Bindings} * @decorator {ConstructorParameter} InjectTagged - Inject a provider instance on costructor arguments. * @summary Bind provider as tagged annotation. * @function */ exports.InjectTagged = lazyDecorators.lazyInjectTagged; /** * Bind an array of bind providers with the same name over the constructor parameter. * {@link https://github.com/inversify/InversifyJS/blob/master/wiki/multi_injection.md Multiple Injection} * @decorator {ConstructorParameter} MultiInject - Inject an array of providers under same name. * @summary Define multiple concretions for defined inject. * @function */ exports.MultiInject = lazyDecorators.lazyMultiInject; exports.default = DependencyInjection;