| @@ -65,7 +65,7 interface Declaration<S extends object> | |||
|
|
65 | 65 | dependency<K extends keyof S>(name: K, opts: LazyDependencyOptions<S[K]>): Lazy<K>; |
|
|
66 | 66 | dependency<K extends keyof S>(name: K, opts?: DependencyOptions<S[K]>): Dependency<K>; |
|
|
67 | 67 | |
|
|
68 | config(): Config<S>; | |
|
|
68 | configure(): Config<S>; | |
|
|
69 | 69 | } |
|
|
70 | 70 | |
|
|
71 | 71 | type ServiceModule<T, S extends object, M extends string = "service"> = { |
| @@ -74,11 +74,11 type ServiceModule<T, S extends object, | |||
|
|
74 | 74 | |
|
|
75 | 75 | type PromiseOrValue<T> = PromiseLike<T> | T; |
|
|
76 | 76 | |
|
|
77 | ||
|
|
77 | 78 | export interface Config<S extends object, Y extends keyof S = keyof S> { |
|
|
78 |
register<K extends Y>(name: K, |
|
|
|
79 | register<K extends Y>(name: K, m: Promise<ServiceModule<S[K], S>>): Config<S, Exclude<Y, K>>; | |
|
|
80 |
register<K extends Y, |
|
|
|
81 | ||
|
|
79 | register<K extends Y>(name: K, m: { $from: Promise<ServiceModule<S[K], S>> } | S[K]): Config<S, Exclude<Y, K>>; | |
|
|
80 | register<K extends Y, M extends string>(name: K, m: { $from: Promise<ServiceModule<S[K], S, M>>, service: M }): Config<S, Exclude<Y, K>>; | |
|
|
81 | register<K extends Y, C extends new (...args: any) => S[K]>(name: K, d: TypeRegistration<C, S>): Config<S, Exclude<Y, K>>; | |
|
|
82 | 82 | } |
|
|
83 | 83 | |
|
|
84 | 84 | export declare function declare<S extends object>(): Declaration<S>; |
| @@ -46,6 +46,7 export interface ServiceRegistration<T, | |||
|
|
46 | 46 | |
|
|
47 | 47 | export interface TypeRegistration<C extends new () => any, S extends object> extends ServiceRegistration<InstanceType<C>, S> { |
|
|
48 | 48 | $type: string | C; |
|
|
49 | params?: ConstructorParameters<C>; | |
|
|
49 | 50 | } |
|
|
50 | 51 | |
|
|
51 | 52 | export interface FactoryRegistration<F extends () => any, S extends object> extends ServiceRegistration<ReturnType<F>, S> { |
| @@ -1,6 +1,15 | |||
|
|
1 | import { config } from "./services"; | |
|
|
1 | import { configure } from "./services"; | |
|
|
2 | import { Foo } from "./Foo"; | |
|
|
3 | import { Bar } from "./Bar"; | |
|
|
2 | 4 | |
|
|
3 | config() | |
|
|
4 | .register("bar", import("./Bar")) | |
|
|
5 |
.register("box", import("./Box") |
|
|
|
6 | // .register("foo", import("./Foo"), "Foo"); | |
|
|
5 | export const config = configure() | |
|
|
6 | .register("bar", { $from: import("./Bar"), service: "service" }) | |
|
|
7 | .register("box", { $from: import("./Box") }) | |
|
|
8 | .register("host", "example.com") | |
|
|
9 | .register("foo", { | |
|
|
10 | $type: Foo | |
|
|
11 | }) | |
|
|
12 | .register("bar2", { | |
|
|
13 | $type: Bar, | |
|
|
14 | params: [] | |
|
|
15 | }); | |
| @@ -11,6 +11,8 export interface Services { | |||
|
|
11 | 11 | |
|
|
12 | 12 | bar: Bar; |
|
|
13 | 13 | |
|
|
14 | bar2: Bar; | |
|
|
15 | ||
|
|
14 | 16 | box: Box<Bar>; |
|
|
15 | 17 | |
|
|
16 | 18 | host: string; |
| @@ -20,4 +22,4 export interface Services { | |||
|
|
20 | 22 | /** |
|
|
21 | 23 | * Экспортируем вспомогательные функции для описания сервисов и кинфогурации |
|
|
22 | 24 | */ |
|
|
23 | export const { define, dependency, config } = declare<Services>(); | |
|
|
25 | export const { define, dependency, configure } = declare<Services>(); | |
General Comments 0
You need to be logged in to leave comments.
Login now
