| @@ -1,33 +1,29 | |||
|
|
1 |
import { |
|
|
|
2 | import { Bar } from "./Bar"; | |
|
|
3 | import { Foo } from "./Foo"; | |
|
|
1 | import { config } from "./config"; | |
|
|
4 | 2 | |
|
|
5 | const builder = new Builder<Box<Bar>, { bar: Bar; foo: Foo; obj: object }>(); | |
|
|
3 | const service = config.service("barBox"); | |
|
|
6 | 4 | |
|
|
7 |
@ |
|
|
|
8 | @builder.dependencies("bar") | |
|
|
5 | @service.provides() | |
|
|
9 | 6 | export class Box<T> { |
|
|
10 | 7 | private _value: T | undefined; |
|
|
11 | 8 | |
|
|
12 | 9 | constructor(value: T) { |
|
|
13 | 10 | this._value = value; |
|
|
14 | 11 | } |
|
|
15 | 12 | |
|
|
16 |
@ |
|
|
|
13 | @service.inject("bar") | |
|
|
17 | 14 | setValue(value: T) { |
|
|
18 | 15 | this._value = value; |
|
|
19 | 16 | } |
|
|
20 | 17 | |
|
|
21 | ||
|
|
22 | @builder.inject("foo") | |
|
|
18 | @service.inject("foo") | |
|
|
23 | 19 | setObj(value: object) { |
|
|
24 | 20 | |
|
|
25 | 21 | } |
|
|
26 | 22 | |
|
|
27 | 23 | getValue() { |
|
|
28 | 24 | if (this._value === undefined) |
|
|
29 | 25 | throw new Error("Trying to get a value from the empty box"); |
|
|
30 | 26 | |
|
|
31 | 27 | return this._value; |
|
|
32 | 28 | } |
|
|
33 | 29 | } No newline at end of file |
| @@ -0,0 +1,29 | |||
|
|
1 | import { Foo } from "./Foo"; | |
|
|
2 | import { Bar } from "./Bar"; | |
|
|
3 | import { ActivationType } from "../di/interfaces"; | |
|
|
4 | import { Builder } from "../di/Annotations"; | |
|
|
5 | import { Box } from "./Box"; | |
|
|
6 | ||
|
|
7 | interface RegistrationOptions { | |
|
|
8 | activation?: ActivationType; | |
|
|
9 | } | |
|
|
10 | ||
|
|
11 | interface ConfigBuilder<S> { | |
|
|
12 | service<K extends keyof S>(name: K): Builder<S[K], S>; | |
|
|
13 | } | |
|
|
14 | ||
|
|
15 | interface ContainerServices { | |
|
|
16 | barBox: Box<Bar>; | |
|
|
17 | ||
|
|
18 | foo: Foo; | |
|
|
19 | ||
|
|
20 | bar: Bar; | |
|
|
21 | ||
|
|
22 | password: string; | |
|
|
23 | ||
|
|
24 | user: string; | |
|
|
25 | ||
|
|
26 | timeout: number; | |
|
|
27 | } | |
|
|
28 | ||
|
|
29 | export declare const config: ConfigBuilder<ContainerServices>; | |
General Comments 0
You need to be logged in to leave comments.
Login now
