initial commit
This commit is contained in:
31
dist/PortResolver.js
vendored
Normal file
31
dist/PortResolver.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var PortResolver = /** @class */ (function () {
|
||||
function PortResolver() {
|
||||
this._container = {};
|
||||
}
|
||||
PortResolver.prototype.register = function (name, fn) {
|
||||
this._container[name] = fn;
|
||||
};
|
||||
PortResolver.prototype.registerInstance = function (name, fn) {
|
||||
var _instance = null;
|
||||
var getInstance = function (fn) {
|
||||
return function () {
|
||||
if (!_instance) {
|
||||
_instance = fn();
|
||||
}
|
||||
return _instance;
|
||||
};
|
||||
};
|
||||
this._container[name] = getInstance(fn);
|
||||
};
|
||||
PortResolver.prototype.resolve = function (name) {
|
||||
if (name in this._container && typeof this._container[name] == 'function') {
|
||||
return this._container[name]();
|
||||
}
|
||||
throw new Error('PortResolver can not resolve ' + name);
|
||||
};
|
||||
return PortResolver;
|
||||
}());
|
||||
exports.PortResolver = PortResolver;
|
||||
//# sourceMappingURL=PortResolver.js.map
|
||||
Reference in New Issue
Block a user