Injector Example

This commit is contained in:
2018-02-26 13:05:32 +01:00
parent 0cc84f5a58
commit 6ddb90e8e2
4 changed files with 37 additions and 17 deletions

20
src/wiring/Wiring.ts Normal file
View File

@@ -0,0 +1,20 @@
import { IInjector } from "../domain/ports/IInjector"
export class Wiring implements IInjector {
private static container : any = { };
public static register(name : string, fn : Function) : void {
Wiring.container[name] = fn;
};
public static GetInjector() : IInjector {
return new Wiring();
}
public inject = function<T>(name : string) : T {
if (Wiring.container[name]) {
return Wiring.container[name]();
}
throw new Error(`Failed to resolve ${name}`)
};
};