@symbux/injector

A dependecy injection library using TypeScript decorators.

Usage no npm install needed!

<script type="module">
  import symbuxInjector from 'https://cdn.skypack.dev/@symbux/injector';
</script>

README

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