ts-injection is an annotation based dependency injection framework written in Typescript for NodeJS apps. It enables building applications that have loosely coupled components.
@Injectable()
class ArnyService {
public getQuote(): string {
return "Get to the choppa!";
}
}
@Injectable()
class ArnyApp {
@Autowire(ArnyService)
private service!: ArnyService;
public getQuote(): string {
return this.service.getQuote();
}
}
const container = new InjectionContainer();
function main(): void {
const app = container.resolve(ArnyApp);
console.log(app.getQuote());
}
- ๐พ Field injection
- ๐จ Constructor injection
- ๐ข Environment variable parsing