| @@ -1,15 +1,15 | |||||
| 1 |
|
|
1 | import { services } from "../di/Annotations"; | |
| 2 |
|
|
2 | import { Bar } from "./Bar"; | |
| 3 |
|
|
3 | ||
| 4 | // declare required dependencies |
|
4 | // declare required dependencies | |
| 5 |
|
|
5 | const config = services<{ | |
| 6 |
|
|
6 | bar: Bar; | |
| 7 |
|
|
7 | }>(); | |
| 8 |
|
|
8 | ||
| 9 | // export service descriptor |
|
9 | // export service descriptor | |
| 10 |
|
|
10 | export const service = config.build<Box<Bar>>(); | |
| 11 |
|
|
11 | ||
| 12 |
|
|
12 | @service.consume(config.dependency("bar")) | |
| 13 | export class Box<T> { |
|
13 | export class Box<T> { | |
| 14 | private _value: T | undefined; |
|
14 | private _value: T | undefined; | |
| 15 |
|
15 | |||
| @@ -25,12 +25,14 function typeRegistration<T, C extends C | |||||
| 25 | throw new Error(); |
|
25 | throw new Error(); | |
| 26 | } |
|
26 | } | |
| 27 |
|
27 | |||
|
|
28 | declare function register<T>(): { type<C extends Constructor<T>>(target: C, params: Wrap<ConstructorParameters<C>>): TypeDescriptor<T, C>}; | |||
|
|
29 | ||||
| 28 | type Wrap<T> = T extends primitive ? T : |
|
30 | type Wrap<T> = T extends primitive ? T : | |
| 29 | { [k in keyof T]: Wrap<T[k]> } | TypeDescriptor<T, Constructor<T>>; |
|
31 | { [k in keyof T]: Wrap<T[k]> } | TypeDescriptor<T, Constructor<T>>; | |
| 30 |
|
32 | |||
| 31 | const config: Wrap<Services> = { |
|
33 | const config: Wrap<Services> = { | |
| 32 | foo: typeRegistration(Foo, []), |
|
34 | foo: typeRegistration(Foo, []), | |
| 33 | bar: typeRegistration(Bar, [{ foo: null as any, nested: null as any }]), |
|
35 | bar: typeRegistration(Bar, [{ foo: null as any, nested: null as any }]), | |
| 34 |
box: |
|
36 | box: register<Box<Foo>>().type(Box, [{ $type: Bar, params: [] }]), | |
| 35 | host: "" |
|
37 | host: "" | |
| 36 | }; |
|
38 | }; | |
General Comments 0
You need to be logged in to leave comments.
Login now
