项目作者: Symbux

项目描述 :
A dependecy injection library using TypeScript decorators.
高级语言: TypeScript
项目地址: git://github.com/Symbux/Injector.git
创建时间: 2021-07-15T09:32:36Z
项目社区:https://github.com/Symbux/Injector

开源协议:MIT License

下载


Dependecy Injection

Codecov
GitHub Workflow Status
GitHub issues
@symbux/injector"">NPM
@symbux/injector"">npm (scoped)
@symbux/injector"">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.

  1. import { Inject, Provide } from '@symbux/injector';
  2. @Provide() // You can optionally give it a name.
  3. export class NumberHelper {
  4. public multiply(num1: number, num2: number): number {
  5. return num1 * num2;
  6. }
  7. }
  8. export class BusinessLogic {
  9. @Inject() helper!: NumberHelper;
  10. public main(): void {
  11. console.log(this.helper.multiply(5, 5));
  12. }
  13. }

Custom usage.

  1. import { Injector, Inject } from '@symbux/injector';
  2. // You can register variables specifically.
  3. Injector.register('my_special_var', 12345);
  4. // You can also resolve them manually.
  5. const mySpecialVar = Injector.resolve('my_special_var');
  6. // You can also inject with a name.
  7. export class BusinessLogic {
  8. @Inject('my_special_var')
  9. public specialVariable!: number;
  10. }