##// END OF EJS Templates
dependency builder proposal
cin -
r110:cc196cedcf24 ioc ts support
parent child
Show More
@@ -1,11 +1,8
1 import { Builder } from "../di/Annotations";
1 import { config } from "./config";
2 import { Bar } from "./Bar";
3 import { Foo } from "./Foo";
4
2
5 const builder = new Builder<Box<Bar>, { bar: Bar; foo: Foo; obj: object }>();
3 const service = config.service("barBox");
6
4
7 @builder.provides()
5 @service.provides()
8 @builder.dependencies("bar")
9 export class Box<T> {
6 export class Box<T> {
10 private _value: T | undefined;
7 private _value: T | undefined;
11
8
@@ -13,13 +10,12 export class Box<T> {
13 this._value = value;
10 this._value = value;
14 }
11 }
15
12
16 @builder.inject("bar")
13 @service.inject("bar")
17 setValue(value: T) {
14 setValue(value: T) {
18 this._value = value;
15 this._value = value;
19 }
16 }
20
17
21
18 @service.inject("foo")
22 @builder.inject("foo")
23 setObj(value: object) {
19 setObj(value: object) {
24
20
25 }
21 }
@@ -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