{"size": 1457, "ext": "js", "max_stars_repo_path": "lib/decorators/inject.decorator.js", "max_stars_repo_name": "CircularFramework/injection", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/decorators/inject.decorator.js", "max_issues_repo_name": "CircularFramework/injection", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/decorators/inject.decorator.js", "max_forks_repo_name": "CircularFramework/injection", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.6739130435, "max_line_length": 108, "alphanum_fraction": 0.6842827728}
'use strict';

Object.defineProperty(exports, "__esModule", {
	value: true
});
exports.Inject = Inject;

var _index = require('../index');

/**
 * Inject
 * A decorator that will find the dependency and return it to be injected in the class
 * @param {string} token The token name to use for injection
 * @returns {function} A function executed to decorate the Injectable
 */
function Inject(token) {
	/** return the function that injects the dependency */
	return function () {
		/** check the token */
		if (token === undefined || typeof token !== 'string') {
			/** check the arguments */
			if (arguments[0] !== undefined && typeof arguments[0] === 'string') token = arguments[0];else {
				/** throw exception that no token was passed */
				throw 'No token given for injection.';
			}
		}

		/** get the dependency */
		var dependencyRef = _index.Injector.get(token);
		if (dependencyRef === undefined) throw 'Dependency could not be found: ' + token;

		/** check for singleton and instance */
		var instance = dependencyRef.instance();
		if (instance === null) {
			/** construct the dependency */
			instance = _index.Injector.construct(dependencyRef.item, dependencyRef.dependencies, dependencyRef.args);

			/** set the dependencyRef instance */
			if (dependencyRef.isSingleton()) dependencyRef.instance(instance);
		}

		/** return the instance */
		return instance;
	};
} /** import dependencies */
//# sourceMappingURL=inject.decorator.js.map