The injector package is a dependecy injection tool built on top of TypeScript decorators for use with Node.JS/TypeScript applications. The original design is for a framework that is soon to come out, this is a prerequisite library.
import { Inject, Provide } from '@symbux/injector';
@Provide() // You can optionally give it a name.
export class NumberHelper {
public multiply(num1: number, num2: number): number {
return num1 * num2;
}
}
export class BusinessLogic {
@Inject() helper!: NumberHelper;
public main(): void {
console.log(this.helper.multiply(5, 5));
}
}
import { Injector, Inject } from '@symbux/injector';
// You can register variables specifically.
Injector.register('my_special_var', 12345);
// You can also resolve them manually.
const mySpecialVar = Injector.resolve('my_special_var');
// You can also inject with a name.
export class BusinessLogic {
@Inject('my_special_var')
public specialVariable!: number;
}