Injector Example
This commit is contained in:
20
src/wiring/Wiring.ts
Normal file
20
src/wiring/Wiring.ts
Normal 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}`)
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user