@symbux/injector
TypeScript icon, indicating that this package has built-in type declarations

1.5.0 • Public • Published

Dependecy Injection

Codecov GitHub Workflow Status GitHub issues NPM npm (scoped) npm

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.

Getting Started

Standard usage.

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));
	}
}

Custom usage.

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;
}

Package Sidebar

Install

npm i @symbux/injector

Weekly Downloads

1

Version

1.5.0

License

MIT

Unpacked Size

27.9 kB

Total Files

27

Last publish

Collaborators

  • dannysmc95