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E;;OAEG;IACqB,wBAAc,GAAsB,IAAI,qCAAiB,CAAC,SAAS,CAAC,CAAC;IAE7F;;OAEG;IACqB,mBAAS,GAAwB,EAAE,CAAC;IAE5D;;OAEG;IACa,kBAAQ,GAAc,EAAE,CAAC;IAwK7C,gBAAC;CA3LD,AA2LC,IAAA;AA3LY,8BAAS","file":"Container.js","sourcesContent":["import {ServiceMetadata} from \"./types/ServiceMetadata\";\nimport {ObjectType} from \"./types/ObjectType\";\nimport {Handler} from \"./types/Handler\";\nimport {Token} from \"./Token\";\nimport {ServiceIdentifier} from \"./types/ServiceIdentifier\";\nimport {ContainerInstance} from \"./ContainerInstance\";\n\n/**\n * Service container.\n */\nexport class Container {\n\n // -------------------------------------------------------------------------\n // Private Static Properties\n // -------------------------------------------------------------------------\n\n /**\n * Global container instance.\n */\n private static readonly globalInstance: ContainerInstance = new ContainerInstance(undefined);\n\n /**\n * Other containers created using Container.of method.\n */\n private static readonly instances: ContainerInstance[] = [];\n\n /**\n * All registered handlers.\n */\n static readonly handlers: Handler[] = [];\n\n // -------------------------------------------------------------------------\n // Public Static Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets a separate container instance for the given instance id.\n */\n static of(instanceId: any): ContainerInstance {\n if (instanceId === undefined)\n return this.globalInstance;\n\n let container = this.instances.find(instance => instance.id === instanceId);\n if (!container) {\n container = new ContainerInstance(instanceId);\n this.instances.push(container);\n }\n\n return container;\n }\n\n /**\n * Checks if the service with given name or type is registered service container.\n * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.\n */\n static has<T>(type: ObjectType<T>): boolean;\n\n /**\n * Checks if the service with given name or type is registered service container.\n * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.\n */\n static has<T>(id: string): boolean;\n\n /**\n * Checks if the service with given name or type is registered service container.\n * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.\n */\n static has<T>(id: Token<T>): boolean;\n\n /**\n * Checks if the service with given name or type is registered service container.\n * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.\n */\n static has<T>(identifier: ServiceIdentifier): boolean {\n return this.globalInstance.has(identifier as any);\n }\n\n /**\n * Retrieves the service with given name or type from the service container.\n * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.\n */\n static get<T>(type: ObjectType<T>): T;\n\n /**\n * Retrieves the service with given name or type from the service container.\n * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.\n */\n static get<T>(id: string): T;\n\n /**\n * Retrieves the service with given name or type from the service container.\n * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.\n */\n static get<T>(id: Token<T>): T;\n\n /**\n * Retrieves the service with given name or type from the service container.\n * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.\n */\n static get<T>(identifier: ServiceIdentifier): T {\n return this.globalInstance.get(identifier as any);\n }\n\n /**\n * Gets all instances registered in the container of the given service identifier.\n * Used when service defined with multiple: true flag.\n */\n static getMany<T>(id: string): T[];\n\n /**\n * Gets all instances registered in the container of the given service identifier.\n * Used when service defined with multiple: true flag.\n */\n static getMany<T>(id: Token<T>): T[];\n\n /**\n * Gets all instances registered in the container of the given service identifier.\n * Used when service defined with multiple: true flag.\n */\n static getMany<T>(id: string|Token<T>): T[] {\n return this.globalInstance.getMany(id as any);\n }\n\n /**\n * Sets a value for the given type or service name in the container.\n */\n static set<T, K extends keyof T>(service: ServiceMetadata<T, K>): Container;\n\n /**\n * Sets a value for the given type or service name in the container.\n */\n static set(type: Function, value: any): Container;\n\n /**\n * Sets a value for the given type or service name in the container.\n */\n static set(name: string, value: any): Container;\n\n /**\n * Sets a value for the given type or service name in the container.\n */\n static set(token: Token<any>, value: any): Container;\n\n /**\n * Sets a value for the given type or service name in the container.\n */\n static set<T, K extends keyof T>(values: ServiceMetadata<T, K>[]): Container;\n\n /**\n * Sets a value for the given type or service name in the container.\n */\n static set(identifierOrServiceMetadata: ServiceIdentifier|ServiceMetadata<any, any>|(ServiceMetadata<any, any>[]), value?: any): Container {\n this.globalInstance.set(identifierOrServiceMetadata as any, value);\n return this;\n }\n\n /**\n * Removes services with a given service identifiers (tokens or types).\n */\n static remove(...ids: ServiceIdentifier[]): Container {\n this.globalInstance.remove(...ids);\n return this;\n }\n\n /**\n * Completely resets the container by removing all previously registered services and handlers from it.\n */\n static reset(containerId?: any): Container {\n if (containerId) {\n const instance = this.instances.find(instance => instance.id === containerId);\n if (instance) {\n instance.reset();\n this.instances.splice(this.instances.indexOf(instance), 1);\n }\n\n } else {\n this.globalInstance.reset();\n this.instances.forEach(instance => instance.reset());\n }\n return this;\n }\n\n /**\n * Registers a new handler.\n */\n static registerHandler(handler: Handler): Container {\n this.handlers.push(handler);\n return this;\n }\n\n /**\n * Helper method that imports given services.\n */\n static import(services: Function[]): Container {\n return this;\n }\n\n}\n"],"sourceRoot":"."}
\No newline at end of file