/
interfaces.ts
205 lines (196 loc) · 5.32 KB
/
interfaces.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
export type ObjectIdentifier = string;
export type Scope = 'Singleton' | 'Request' | 'Prototype';
export interface IScopeEnum {
Singleton: Scope;
Request: Scope;
Prototype: Scope;
}
/**
* 生命周期定义
*/
export interface ILifeCycle {
key: string;
onStart(): void;
onReady(): void;
onRefresh(): void;
onStop(): void;
}
export type Locale = string;
/**
* 多语言支持接口
*/
export interface IMessageSource {
get(code: string,
args?: any[],
defaultMessage?: string,
locale?: Locale): string;
}
/**
* 对象容器抽象
* 默认用Xml容器实现一个
*/
export interface IObjectFactory {
registry: IObjectDefinitionRegistry;
isAsync(identifier: ObjectIdentifier): boolean;
get<T>(identifier: ObjectIdentifier, args?: any): T;
getAsync<T>(identifier: ObjectIdentifier, args?: any): Promise<T>;
}
/**
* 对象描述定义
*/
export interface IObjectDefinition {
creator: IObjectCreator;
id: string;
name: string;
initMethod: string;
destroyMethod: string;
constructMethod: string;
path: any;
export: string;
dependsOn: ObjectIdentifier[];
constructorArgs: IManagedInstance[];
properties: IConfiguration;
isAutowire(): boolean;
isAsync(): boolean;
isSingletonScope(): boolean;
isRequestScope(): boolean;
isExternal(): boolean;
isDirect(): boolean;
hasDependsOn(): boolean;
hasConstructorArgs(): boolean;
getAttr(key: ObjectIdentifier): any;
hasAttr(key: ObjectIdentifier): boolean;
setAttr(key: ObjectIdentifier, value: any): void;
}
export interface IObjectCreator {
load(): any;
doConstruct(Clzz: any, args?: any): any;
doConstructAsync(Clzz: any, args?: any): Promise<any>;
doInit(obj: any): void;
doInitAsync(obj: any): Promise<void>;
doDestroy(obj: any): void;
doDestroyAsync(obj: any): Promise<void>;
}
/**
* 对象定义存储容器
*/
export interface IObjectDefinitionRegistry {
readonly identifiers: ObjectIdentifier[];
readonly count: number;
registerDefinition(identifier: ObjectIdentifier, definition: IObjectDefinition);
getDefinition(identifier: ObjectIdentifier): IObjectDefinition;
getDefinitionByPath(path: string): IObjectDefinition;
getDefinitionByName(name: string): IObjectDefinition[];
removeDefinition(identifier: ObjectIdentifier): void;
hasDefinition(identifier: ObjectIdentifier): boolean;
clearAll(): void;
hasObject(identifier: ObjectIdentifier): boolean;
registerObject(identifier: ObjectIdentifier, target: any);
getObject(identifier: ObjectIdentifier): any;
}
/**
* 属性配置抽象
*/
export interface IConfiguration {
readonly size: number;
keys(): ObjectIdentifier[];
get(key: ObjectIdentifier, ...args: any[]): any;
dup(key: ObjectIdentifier): any;
has(key: ObjectIdentifier): boolean;
set(key: ObjectIdentifier, value: any): any;
putAll(props: IConfiguration): void;
toJSON(): Object;
stringPropertyNames(): ObjectIdentifier[];
getProperty(key: ObjectIdentifier, defaultValue?: any): any;
addProperty(key: ObjectIdentifier, value: any): void;
setProperty(key: ObjectIdentifier, value: any): any;
clear(): void;
clone(): IConfiguration;
}
/**
* 资源配置抽象
*/
export interface IResource {
readonly name: string;
readonly contentLength: number;
readonly lastModified: number;
encoding: string;
exists(): boolean;
isDir(): boolean;
isFile(): boolean;
isURL(): boolean;
getURL(): any;
getPath(): string;
getContent(): Buffer;
getContentAsJSON(): Object;
getSubResources(): IResource[];
createRelative(path: string): IResource;
}
/**
* IoC上下文抽象
*/
export interface IApplicationContext extends IObjectFactory {
baseDir: string;
parent: IApplicationContext;
props: IConfiguration;
configLocations: string[];
messageSource: IMessageSource;
dependencyMap: Map<string, ObjectDependencyTree>;
refreshAsync(): Promise<void>;
ready(): Promise<void>;
addLifeCycle(lifeCycle: ILifeCycle): void;
removeLifeCycle(lifeCycle: ILifeCycle): void;
stop(): Promise<void>;
dumpDependency(): void;
}
/**
* 内部管理的属性、json、ref等解析实例存储
*/
export interface IManagedInstance {
type: string;
}
/**
* 解析内部管理的属性、json、ref等实例的解析器
* 同时创建这些对象的实际使用的对象
*/
export interface IManagedResolver {
type: string;
resolve(managed: IManagedInstance): any;
resolveAsync(managed: IManagedInstance): Promise<any>;
}
export interface ObjectDefinitionOptions {
isAsync?: boolean;
initMethod?: string;
destroyMethod?: string;
scope?: Scope;
constructorArgs?: Array<IManagedInstance>;
// 是否自动装配
isAutowire?: boolean;
}
/**
* 提供简化的容器绑定能力
*/
export interface IContainer extends IApplicationContext {
bind<T>(target: T, options?: ObjectDefinitionOptions): void ;
bind<T>(identifier: ObjectIdentifier, target: T, options?: ObjectDefinitionOptions): void;
createChild(): IContainer;
resolve<T>(target: T): T;
registerCustomBinding(objectDefinition: IObjectDefinition, target): void;
}
export interface TagPropsMetadata {
key: string | number | symbol;
value: any;
}
export interface TagClsMetadata {
id: string;
originName: string;
}
export interface ReflectResult {
[key: string]: TagPropsMetadata[];
}
export interface ObjectDependencyTree {
scope: IScopeEnum;
name: string;
constructorArgs: string[];
properties: string[];
}