##// END OF EJS Templates
sync
cin -
r116:e81085d00fcb ioc ts support
parent child
Show More
@@ -1,64 +1,36
1 import { Foo } from "./Foo";
1 import { Foo } from "./Foo";
2 import { Bar } from "./Bar";
2 import { Bar } from "./Bar";
3 import { ActivationType } from "../di/interfaces";
4 import { Builder } from "../di/Annotations";
5 import { Box } from "./Box";
3 import { Box } from "./Box";
6
4 import { primitive } from "../safe";
7 interface RegistrationOptions {
5 import { Constructor } from "../interfaces";
8 activation?: ActivationType;
9 }
10
11 interface Dependency<K extends keyof any> {
12 $dependency: K;
13
14 lazy?: boolean;
15 }
16
6
17 interface Lazy<K extends keyof any> extends Dependency<K> {
7 interface Services {
18 lazy: true;
19 }
20
21 type PromiseOrValue<T> = T | PromiseLike<T>;
22
23 interface ConfigBuilder<S> {
24 build<K extends keyof S, T = S[K]>(name: K): Builder<T, S>;
25
26 dependency<K extends keyof S>(name: K): Dependency<K>;
27
28 lazy<K extends keyof S>(name: K): Lazy<K>;
29
30 mapTo<K extends keyof S>(name: K, ctor: () => PromiseOrValue<new (...args: any[]) => S[K]>): ConfigBuilder<S>;
31
32 }
33
34 interface ContainerServices {
35 barBox: Box<Bar>;
36
37 foo: Foo;
8 foo: Foo;
38
9
39 bar: Bar;
10 bar: Bar;
40
11
41 password: string;
12 box: Box<Foo>;
13
14 host: string;
42
15
43 user: string;
16 }
44
17
45 timeout: number;
18 interface TypeDescriptor<T, C extends Constructor<T>> {
19 $type: C;
20
21 params: Wrap<ConstructorParameters<C>>;
46 }
22 }
47
23
48 declare function load<M, C extends keyof M>(m: PromiseLike<M>, name: C): () => PromiseLike<M[C]>;
24 function typeRegistration<T, C extends Constructor<T>>(target: C, params: Wrap<ConstructorParameters<C>>): TypeDescriptor<T, C> {
25 throw new Error();
26 }
49
27
50 const t = {
28 type Wrap<T> = T extends primitive ? T :
51 barBox: load(import("./Box"), "Box"),
29 { [k in keyof T]: Wrap<T[k]> } | TypeDescriptor<T, Constructor<T>>;
52
53 foo: async () => (await import("./Bar")).Bar,
54
55 bar: Bar,
56
30
57 password: String,
31 const config: Wrap<Services> = {
58
32 foo: typeRegistration(Foo, []),
59 user: String,
33 bar: typeRegistration(Bar, [{ foo: null as any, nested: null as any }]),
60
34 box: typeRegistration(Box, [{ $type: Bar, params: [] }]),
61 timeout: Number
35 host: ""
62 };
36 };
63
64 export declare const config: ConfigBuilder<ContainerServices>;
General Comments 0
You need to be logged in to leave comments. Login now