@wdxlab/di
v1.0.0-alpha.11
Published
Dependency Injection for TypeScript
Downloads
163
Readme
@WDXLab/DI
Dependency Injection for TypeScript
Installation
npm install @wdxlab/di --save
Usage
tsconfig.json
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
}
Simple example:
import {Injector, Injectable} from "@wdxlab/di";
@Injectable()
class Foo {
sum(a: number, b: number) {
return a + b;
}
}
@Injectable()
class Bar {
constructor(protected foo: Foo) {}
sum(a: number, b: number) {
return this.foo.sum(a, b);
}
}
const injector = new Injector();
const bar = injector.instantiate(Bar);
console.log(bar.sum(1, 2)); // 3
‼️ TODO: describe docs below ‼️
Methods
instantiate(module, description?)
callMethod(target, methodName, description?)
get(clazz)
set(instance)
fn(fn, params)
clear()
Decorators
Injectable(description?)
Class decorator
isInjectable(target)
getInjectableOptions(target)
InjectArg(name)
Parameter decorator
InjectArgFactory(factory)
Parameter decorator
getInjectionParamFactories(target, key?)
Method(meta?)
Method decorator