UNPKG

@ncodedcode/ncode_react_lib

Version:

ncode react application context library

70 lines 3.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NCApplicationContext = void 0; var NCApplicationConfiguration_1 = require("./NCApplicationConfiguration"); var ServiceLocator_1 = require("./di/ServiceLocator"); var NCDating_1 = require("./utils/date/NCDating"); var JSDateDating_1 = require("./utils/date/JSDateDating"); var NCStorage_1 = require("./IO/persistant/NCStorage"); var MemoryStorage_1 = require("./IO/persistant/MemoryStorage"); var NCApplicationContext = (function () { function NCApplicationContext(configuration) { var _this = this; if (configuration === void 0) { configuration = new NCApplicationConfiguration_1.NCDefaultApplicationConfiguration(); } this._modeDev = false; this.initDefaults = function () { _this._serviceLocator.registFactory(NCDating_1.NCDatingClassName, function () { return new JSDateDating_1.JSDateDating(); }); _this._serviceLocator.registFactory(NCStorage_1.NCInstantStorageClassName, function () { return new MemoryStorage_1.MemoryStorage(); }); _this._serviceLocator.registFactory(NCStorage_1.NCStorageClassName, function () { return new MemoryStorage_1.MemoryStorage(); }); }; this._serviceLocator = new ServiceLocator_1.ServiceLocator(); this.initDefaults(); configuration.application(this); configuration.config(this._serviceLocator); } NCApplicationContext.createContext = function (configuration) { if (NCApplicationContext._instance !== null) { throw new Error("Global Application Context has already created"); } NCApplicationContext._instance = new NCApplicationContext(configuration); return NCApplicationContext._instance; }; Object.defineProperty(NCApplicationContext, "global", { get: function () { if (NCApplicationContext._instance === null) { throw new Error("Global Application Context has not been created"); } return NCApplicationContext._instance; }, enumerable: false, configurable: true }); Object.defineProperty(NCApplicationContext.prototype, "devMode", { get: function () { return this._modeDev; }, set: function (mode) { this._modeDev = mode; }, enumerable: false, configurable: true }); Object.defineProperty(NCApplicationContext.prototype, "container", { get: function () { return this._serviceLocator; }, enumerable: false, configurable: true }); Object.defineProperty(NCApplicationContext.prototype, "serviceLocator", { get: function () { return this._serviceLocator; }, enumerable: false, configurable: true }); NCApplicationContext._instance = null; return NCApplicationContext; }()); exports.NCApplicationContext = NCApplicationContext; //# sourceMappingURL=NCApplicationContext.js.map