Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/symbux/injector
A simple and clean dependency injection (DI) library for usage with classes in TypeScript, the library utilises decorators.
https://github.com/symbux/injector
decorator-pattern decorators dependecy-injection dependency-injection injection ioc typescript typescript-library
Last synced: about 1 month ago
JSON representation
A simple and clean dependency injection (DI) library for usage with classes in TypeScript, the library utilises decorators.
- Host: GitHub
- URL: https://github.com/symbux/injector
- Owner: Symbux
- License: mit
- Created: 2021-07-15T09:32:36.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-07-23T12:30:43.000Z (over 2 years ago)
- Last Synced: 2024-08-09T02:23:39.061Z (5 months ago)
- Topics: decorator-pattern, decorators, dependecy-injection, dependency-injection, injection, ioc, typescript, typescript-library
- Language: TypeScript
- Homepage:
- Size: 78.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dependecy Injection
[![Codecov](https://img.shields.io/codecov/c/github/Symbux/Injector)](https://codecov.io/github/Symbux/Injector)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Symbux/Injector/Build)](https://github.com/Symbux/Injector/actions)
[![GitHub issues](https://img.shields.io/github/issues/Symbux/Injector)](https://github.com/Symbux/Injector/issues)
[![NPM](https://img.shields.io/npm/l/@symbux/injector)](https://www.npmjs.com/package/@symbux/injector)
[![npm (scoped)](https://img.shields.io/npm/v/@symbux/injector)](https://www.npmjs.com/package/@symbux/injector)
[![npm](https://img.shields.io/npm/dw/@symbux/injector)](https://www.npmjs.com/package/@symbux/injector)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.
```typescript
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.
```typescript
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;
}
```