UNPKG

container-ioc

Version:

Dependency Injection and Inversion of Control (IoC) container

26 lines (25 loc) 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const keys_1 = require("./metadata/keys"); const index_1 = require("./metadata/index"); const MetadataAnnotator = index_1.AnnotatorProvider.get(); function Injectable(injections) { return (target) => { MetadataAnnotator.defineMetadata(keys_1.INJECTABLE_MD_KEY, true, target); if (injections && Array.isArray(injections)) { const injectionsMd = MetadataAnnotator.getMetadata(keys_1.INJECTIONS_MD_KEY, target) || []; injections.forEach(token => injectionsMd.push(token)); MetadataAnnotator.defineMetadata(keys_1.INJECTIONS_MD_KEY, injectionsMd, target); } }; } exports.Injectable = Injectable; exports.Component = Injectable; function Inject(token) { return (target, propertyKey, parameterIndex) => { const injections = MetadataAnnotator.getMetadata(keys_1.INJECTIONS_MD_KEY, target) || []; injections[parameterIndex] = token; MetadataAnnotator.defineMetadata(keys_1.INJECTIONS_MD_KEY, injections, target); }; } exports.Inject = Inject;