@injex/core
Advanced tools
Comparing version 3.0.0-alpha.1 to 3.0.0-alpha.2
import { ModuleName } from "./interfaces"; | ||
export declare class ModuleDependencyNotFoundError extends Error { | ||
constructor(moduleName: ModuleName, dependencyName: ModuleName); | ||
} | ||
export declare class InitializeMuduleError extends Error { | ||
@@ -6,0 +3,0 @@ constructor(moduleName: ModuleName); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InvalidPluginError = exports.DuplicateDefinitionError = exports.InitializeMuduleError = exports.ModuleDependencyNotFoundError = void 0; | ||
exports.InvalidPluginError = exports.DuplicateDefinitionError = exports.InitializeMuduleError = void 0; | ||
var tslib_1 = require("tslib"); | ||
var stdlib_1 = require("@injex/stdlib"); | ||
var ModuleDependencyNotFoundError = /** @class */ (function (_super) { | ||
tslib_1.__extends(ModuleDependencyNotFoundError, _super); | ||
function ModuleDependencyNotFoundError(moduleName, dependencyName) { | ||
return _super.call(this, "Dependency '" + String(dependencyName) + "' was not found for module '" + String(moduleName) + "'.") || this; | ||
} | ||
return ModuleDependencyNotFoundError; | ||
}(Error)); | ||
exports.ModuleDependencyNotFoundError = ModuleDependencyNotFoundError; | ||
var InitializeMuduleError = /** @class */ (function (_super) { | ||
@@ -15,0 +7,0 @@ tslib_1.__extends(InitializeMuduleError, _super); |
@@ -42,2 +42,8 @@ import { IConstructor, Logger } from "@injex/stdlib"; | ||
/** | ||
* Manually add module with metadata | ||
* | ||
* @param item - Module with metadata to add | ||
*/ | ||
addModule(item: IConstructor): InjexContainer<T>; | ||
/** | ||
* Manually add object to the container as singleton | ||
@@ -44,0 +50,0 @@ * |
@@ -171,3 +171,3 @@ "use strict"; | ||
lazyInstance = self._createInstance(Ctor, args); | ||
self._injectModuleDependencies(lazyInstance, lazyMetadata); | ||
self._injectModuleDependencies(lazyInstance); | ||
return [4 /*yield*/, self._invokeModuleInitMethod(lazyInstance, lazyMetadata)]; | ||
@@ -192,3 +192,3 @@ case 2: | ||
var instance = self._createInstance(construct, args); | ||
self._injectModuleDependencies(instance, metadata); | ||
self._injectModuleDependencies(instance); | ||
var initValue = self._invokeModuleInitMethod(instance, metadata); | ||
@@ -213,3 +213,3 @@ if (stdlib_1.isPromise(initValue)) { | ||
if (metadata && metadata.singleton) { | ||
_this._injectModuleDependencies(metadata.lazyLoader || module, metadata); | ||
_this._injectModuleDependencies(metadata.lazyLoader || module); | ||
} | ||
@@ -278,3 +278,3 @@ return { module: module, metadata: metadata }; | ||
}; | ||
InjexContainer.prototype._injectModuleDependencies = function (module, metadata) { | ||
InjexContainer.prototype._injectModuleDependencies = function (module) { | ||
var _this = this; | ||
@@ -284,13 +284,32 @@ metadataHandlers_1.default.forEachProtoMetadata(module, function (_, meta) { | ||
var aliasDependencies = meta.aliasDependencies || []; | ||
var self = _this; | ||
var _loop_1 = function (label, value) { | ||
Object.defineProperty(module, label, { | ||
configurable: true, | ||
set: function (val) { | ||
Object.defineProperty(module, label, { get: function () { return val; } }); | ||
}, | ||
get: function () { | ||
return self.get(value) || null; | ||
} | ||
}); | ||
}; | ||
for (var _i = 0, dependencies_1 = dependencies; _i < dependencies_1.length; _i++) { | ||
var _a = dependencies_1[_i], label = _a.label, value = _a.value; | ||
var dependency = _this.get(value); | ||
if (!dependency) { | ||
throw new errors_1.ModuleDependencyNotFoundError(metadata.name, value); | ||
} | ||
module[label] = dependency; | ||
_loop_1(label, value); | ||
} | ||
var _loop_2 = function (label, alias, keyBy) { | ||
Object.defineProperty(module, label, { | ||
configurable: true, | ||
set: function (val) { | ||
Object.defineProperty(module, label, { get: function () { return val; } }); | ||
}, | ||
get: function () { | ||
return self.getAlias(alias, keyBy); | ||
} | ||
}); | ||
}; | ||
for (var _b = 0, aliasDependencies_1 = aliasDependencies; _b < aliasDependencies_1.length; _b++) { | ||
var _c = aliasDependencies_1[_b], label = _c.label, alias = _c.alias, keyBy = _c.keyBy; | ||
module[label] = _this.getAlias(alias, keyBy); | ||
_loop_2(label, alias, keyBy); | ||
} | ||
@@ -312,2 +331,21 @@ }); | ||
/** | ||
* Manually add module with metadata | ||
* | ||
* @param item - Module with metadata to add | ||
*/ | ||
InjexContainer.prototype.addModule = function (item) { | ||
if (!metadataHandlers_1.default.hasMetadata(item.prototype)) { | ||
this._logger.debug("You're trying to add module without any metadata."); | ||
return this; | ||
} | ||
this._register(item); | ||
this._createModule(item); | ||
var _a = this.getModuleDefinition(item), module = _a.module, metadata = _a.metadata; | ||
if (metadata.singleton) { | ||
this._injectModuleDependencies(metadata.lazyLoader || module); | ||
this._invokeModuleInitMethod(metadata.lazyLoader || module, metadata); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Manually add object to the container as singleton | ||
@@ -314,0 +352,0 @@ * |
{ | ||
"name": "@injex/core", | ||
"version": "3.0.0-alpha.1", | ||
"version": "3.0.0-alpha.2", | ||
"description": "Simple, Decorated, Pluggable dependency-injection framework for TypeScript apps", | ||
@@ -46,4 +46,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@injex/stdlib": "^3.0.0-alpha.1", | ||
"tslib": "^2.0.1" | ||
"@injex/stdlib": "^3.0.0-alpha.2", | ||
"tslib": "^2.1.0" | ||
}, | ||
@@ -56,3 +56,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "963c75797223c24242d3fc44904aed8e97ff77ee" | ||
"gitHead": "cd07a11f02aa1fdbe3f457079975da0416d17e07" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51094
739
Updated@injex/stdlib@^3.0.0-alpha.2
Updatedtslib@^2.1.0