@chyan/ioc
v1.3.3
Published
Dependency injection library for Typescript.
Downloads
20
Readme
Dependency Injection
Dependency injection library for Typescript.
Small And Easier To Use.
Quick Start
import { Injectable, MainApplication, ioc, AutoWired } from "@chyan/ioc";
@Injectable()
class Service1 {
log() {
console.log("service 1");
}
}
@Injectable()
class Service2 {
log() {
console.log("service 2");
}
}
@MainApplication()
class Application {
@AutoWired()
s1!: Service1;
constructor(private s2: Service2) {}
log() {
console.log(this.s1 === ioc.fetchInjectorViaClass(Service1)); // true
console.log(this.s2 === ioc.fetchInjectorViaClass(Service2)); // true
this.s1.log(); // service 1
this.s2.log(); // service 2
}
main() {
this.log();
}
}
MainApplication
will auto invokemain
method