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: 4 months 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 (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-23T12:30:43.000Z (almost 3 years ago)
- Last Synced: 2025-01-19T05:38:26.839Z (6 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
[](https://codecov.io/github/Symbux/Injector)
[](https://github.com/Symbux/Injector/actions)
[](https://github.com/Symbux/Injector/issues)
[](https://www.npmjs.com/package/@symbux/injector)
[](https://www.npmjs.com/package/@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;
}
```