1.0.0 • Published 2 years ago

@sparx/injector v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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 '@sparx/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 '@sparx/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;
}