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AC,GAAG,CAAI,SAAS,CAAC,CAAC;AAC9C,CAAC","file":"container.js","sourcesContent":["\n/**\n * Container options.\n */\nexport interface UseContainerOptions {\n\n /**\n * If set to true, then default container will be used in the case if given container haven't returned anything.\n */\n fallback?: boolean;\n\n /**\n * If set to true, then default container will be used in the case if given container thrown an exception.\n */\n fallbackOnErrors?: boolean;\n\n}\n\n/**\n * Container to be used by this library for inversion control. If container was not implicitly set then by default\n * container simply creates a new instance of the given class.\n */\nconst defaultContainer: { get(someClass: { new (...args: any[]): T }|Function): T } = new (class {\n private instances: { type: Function, object: any }[] = [];\n get(someClass: { new (...args: any[]): T }): T {\n let instance = this.instances.find(instance => instance.type === someClass);\n if (!instance) {\n instance = { type: someClass, object: new someClass() };\n this.instances.push(instance);\n }\n\n return instance.object;\n }\n})();\n\nlet userContainer: { get(someClass: { new (...args: any[]): T }|Function): T };\nlet userContainerOptions: UseContainerOptions;\n\n/**\n * Sets container to be used by this library.\n */\nexport function useContainer(iocContainer: { get(someClass: any): any }, options?: UseContainerOptions) {\n userContainer = iocContainer;\n userContainerOptions = options;\n}\n\n/**\n * Gets the IOC container used by this library.\n */\nexport function getFromContainer(someClass: { new (...args: any[]): T }|Function): T {\n if (userContainer) {\n try {\n const instance = userContainer.get(someClass);\n if (instance)\n return instance;\n\n if (!userContainerOptions || !userContainerOptions.fallback)\n return instance;\n\n } catch (error) {\n if (!userContainerOptions || !userContainerOptions.fallbackOnErrors)\n throw error;\n }\n }\n return defaultContainer.get(someClass);\n}\n"],"sourceRoot":"."}