UNPKG

4.25 kBTypeScriptView Raw
1import { ServiceMetadata } from "./types/ServiceMetadata";
2import { ObjectType } from "./types/ObjectType";
3import { Token } from "./Token";
4import { ServiceIdentifier } from "./types/ServiceIdentifier";
5/**
6 * TypeDI can have multiple containers.
7 * One container is ContainerInstance.
8 */
9export declare class ContainerInstance {
10 /**
11 * Container instance id.
12 */
13 id: any;
14 /**
15 * All registered services.
16 */
17 private services;
18 constructor(id: any);
19 /**
20 * Checks if the service with given name or type is registered service container.
21 * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.
22 */
23 has<T>(type: ObjectType<T>): boolean;
24 /**
25 * Checks if the service with given name or type is registered service container.
26 * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.
27 */
28 has<T>(id: string): boolean;
29 /**
30 * Checks if the service with given name or type is registered service container.
31 * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.
32 */
33 has<T>(id: Token<T>): boolean;
34 /**
35 * Retrieves the service with given name or type from the service container.
36 * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.
37 */
38 get<T>(type: ObjectType<T>): T;
39 /**
40 * Retrieves the service with given name or type from the service container.
41 * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.
42 */
43 get<T>(id: string): T;
44 /**
45 * Retrieves the service with given name or type from the service container.
46 * Optionally, parameters can be passed in case if instance is initialized in the container for the first time.
47 */
48 get<T>(id: Token<T>): T;
49 /**
50 * Gets all instances registered in the container of the given service identifier.
51 * Used when service defined with multiple: true flag.
52 */
53 getMany<T>(id: string): T[];
54 /**
55 * Gets all instances registered in the container of the given service identifier.
56 * Used when service defined with multiple: true flag.
57 */
58 getMany<T>(id: Token<T>): T[];
59 /**
60 * Sets a value for the given type or service name in the container.
61 */
62 set<T, K extends keyof T>(service: ServiceMetadata<T, K>): this;
63 /**
64 * Sets a value for the given type or service name in the container.
65 */
66 set(type: Function, value: any): this;
67 /**
68 * Sets a value for the given type or service name in the container.
69 */
70 set(name: string, value: any): this;
71 /**
72 * Sets a value for the given type or service name in the container.
73 */
74 set(token: Token<any>, value: any): this;
75 /**
76 * Sets a value for the given type or service name in the container.
77 */
78 set(token: ServiceIdentifier, value: any): this;
79 /**
80 * Sets a value for the given type or service name in the container.
81 */
82 set<T, K extends keyof T>(values: ServiceMetadata<T, K>[]): this;
83 /**
84 * Removes services with a given service identifiers (tokens or types).
85 */
86 remove(...ids: ServiceIdentifier[]): this;
87 /**
88 * Completely resets the container by removing all previously registered services from it.
89 */
90 reset(): this;
91 /**
92 * Filters registered service in the with a given service identifier.
93 */
94 private filterServices(identifier);
95 /**
96 * Finds registered service in the with a given service identifier.
97 */
98 private findService(identifier);
99 /**
100 * Gets service value.
101 */
102 private getServiceValue(identifier, service);
103 /**
104 * Initializes all parameter types for a given target service class.
105 */
106 private initializeParams(type, paramTypes);
107 /**
108 * Checks if given type is primitive (e.g. string, boolean, number, object).
109 */
110 private isTypePrimitive(param);
111 /**
112 * Applies all registered handlers on a given target class.
113 */
114 private applyPropertyHandlers(target, instance);
115}