forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inversify.d.ts
143 lines (120 loc) · 4.23 KB
/
inversify.d.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
// Type definitions for inversify 2.0.0-alpha.3
// Project: https://github.com/inversify/InversifyJS
// Definitions by: inversify <https://github.com/inversify>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../bluebird/bluebird.d.ts" />
declare namespace inversify {
interface IKernelConstructor {
new(options?: IKernelOptions): IKernel;
}
export interface IKernel {
bind<T>(runtimeIdentifier: string): IBindingToSyntax<T>;
unbind(runtimeIdentifier: string): void;
unbindAll(): void;
get<T>(runtimeIdentifier: string): T;
getAll<T>(runtimeIdentifier: string): T[];
}
export interface IKernelOptions {
middleware?: IMiddleware[];
modules?: IKernelModule[];
}
interface IMiddleware extends Function {
(...args: any[]): any;
}
export interface IKernelModule extends Function {
(kernel: IKernel): void;
}
interface IBindingToSyntax<T> {
to(constructor: { new(...args: any[]): T; }): IBindingInWhenProxySyntax<T>;
toValue(value: T): IBindingInWhenProxySyntax<T>;
toConstructor<T2>(constructor: INewable<T2>): IBindingInWhenProxySyntax<T>;
toFactory<T2>(factory: IFactoryCreator<T2>): IBindingInWhenProxySyntax<T>;
toAutoFactory<T2>(): IBindingInWhenProxySyntax<T>;
toProvider<T2>(provider: IProviderCreator<T2>): IBindingInWhenProxySyntax<T>;
}
interface IBindingInWhenProxySyntax<T> {
inTransientScope(): IBindingInWhenProxySyntax<T>;
inSingletonScope(): IBindingInWhenProxySyntax<T>;
when(constraint: (request: IRequest) => boolean): IBindingInWhenProxySyntax<T>;
whenTargetNamed(name: string): IBindingInWhenProxySyntax<T>;
whenTargetTagged(tag: string, value: any): IBindingInWhenProxySyntax<T>;
proxy(fn: (injectable: T) => T): IBindingInWhenProxySyntax<T>;
}
export interface IFactory<T> extends Function {
(): T;
}
interface IFactoryCreator<T> extends Function {
(context: IContext): IFactory<T>;
}
export interface INewable<T> {
new(...args: any[]): T;
}
export interface IProvider<T> extends Function {
(): Promise<T>;
}
interface IProviderCreator<T> extends Function {
(context: IContext): IProvider<T>;
}
export interface IContext {
kernel: IKernel;
plan: IPlan;
addPlan(plan: IPlan): void;
}
export interface IPlan {
parentContext: IContext;
rootRequest: IRequest;
}
export interface IRequest {
service: string;
parentContext: IContext;
parentRequest: IRequest;
childRequests: IRequest[];
target: ITarget;
bindings: IBinding<any>[];
addChildRequest(
service: string,
bindings: (IBinding<any>|IBinding<any>[]),
target: ITarget): IRequest;
}
export interface IBinding<T> {
runtimeIdentifier: string;
implementationType: INewable<T>;
factory: IFactoryCreator<any>;
provider: IProviderCreator<any>;
constraint: (request: IRequest) => boolean;
proxyMaker: (injectable: T) => T;
cache: T;
scope: number; // BindingScope
type: number; // BindingType
}
export interface ITarget {
service: IQueryableString;
name: IQueryableString;
metadata: Array<IMetadata>;
isArray(): boolean;
isNamed(): boolean;
isTagged(): boolean;
matchesName(name: string): boolean;
matchesTag(name: IMetadata): boolean;
}
export interface IQueryableString {
startsWith(searchString: string): boolean;
endsWith(searchString: string): boolean;
contains(searchString: string): boolean;
equals(compareString: string): boolean;
value(): string;
}
export interface IMetadata {
key: string;
value: any;
}
export var Kernel: IKernelConstructor;
export var decorate: any;
export function inject(...typeIdentifiers: string[]): (typeConstructor: any) => void;
export var tagged: any;
export var named: any;
export var paramNames: any;
}
declare module "inversify" {
export = inversify;
}