# HG changeset patch # User cin # Date 2020-06-19 18:56:45 # Node ID 0d76488aa00a0f4b657bda3752697cc8c265af4d # Parent 3725cefc8f982db44e9df840682747f96a0dee6c dependency builder proposal diff --git a/src/main/ts/di/Annotations.ts b/src/main/ts/di/Annotations.ts --- a/src/main/ts/di/Annotations.ts +++ b/src/main/ts/di/Annotations.ts @@ -4,7 +4,33 @@ export interface InjectOptions { lazy?: boolean; } -export function inject void } >(dependency: string) { +type Setter = (v: T) => void; + +type Injector = { + [k in keyof T]: Setter; +}; + +export class Builder { + provides(name: string) { + return >(constructor: C) => { + return constructor; + }; + } + + inject(dependency: K) { + return (target: any, memberName: M, descriptor: TypedPropertyDescriptor> ) => { + + }; + } + + prop(dependency: K) { + return (target: any, memberName: M, descriptor: TypedPropertyDescriptor ) => { + + }; + } +} + +export function inject >(dependency: string) { return (target: any, memberName: M, descriptor: TypedPropertyDescriptor ) => { }; diff --git a/src/test/ts/mock/Box.ts b/src/test/ts/mock/Box.ts --- a/src/test/ts/mock/Box.ts +++ b/src/test/ts/mock/Box.ts @@ -1,13 +1,18 @@ -import { inject } from "../di/Annotations"; +import { Builder } from "../di/Annotations"; +import { Bar } from "./Bar"; +import { Foo } from "./Foo"; export interface Injector { setValue(value: T); } +const builder = new Builder, { bar: Bar; foo: Foo}>(); + +@builder.provides("barBox") export class Box implements Injector { private _value: T; - @inject>("bar") + @builder.inject("bar") setValue(value: T) { this._value = value; }