Skip to content

Injection

Danny edited this page Feb 28, 2022 · 10 revisions

Before building this library, I built a small and 100% coverage dependency injection library for this project specifically, but separated into another package for anyone to use. The framework is fairly basic, and uses a basic principle of getters to change the response to a get call of a property of your class, this can be used as decorators or programatically.

Documentation over at the Symbux Injector project.


Basic Usage

import { Provide, Inject } from '@symbux/injector';

@Provide() // Give it a name instead of using class name.
export class NumberHelper {
	public multiply(num1: number, num2: number): number {
		return num1 * num2;
	}
}

export class BusinessLogic {

	@Inject() helper!: NumberHelper; // When no name is given, will resolve on the class name.

	public main(): void {
		console.log(this.helper.multiply(5, 5));
	}
}

Built-in Provides

Below is a list of built in provides, these are the ones that are automatically added when the engine starts. These are the ones that are active instances, things like the FibreManager class is static, and can be imported and called as is.

Name Description Type
turbo.core The main instance of the Turbo engine. Engine
turbo.options The options object used to start the engine. IOptions
turbo.auth The authentication manager instance. Authentication
turbo.autowire The autowire class instance. Autowire
turbo.runner The task runner class instance. Runner
turbo.registry The registry class instance. Registry
turbo.services The services manager class instance. Services
turbo.translator The translator class instance. Translator
tp.http The instance of the HttpPlugin's service. Http.Service
tp.http.options The HttpPlugin's options. Http.IOptions
tp.ws The instance of the WsPlugin's service. Ws.Service
tp.ws.options The WsPlugin's options. Ws.IOptions

Library Injects

Some of the libraries we use will also have classes that we re-export/add meta data into, and then we shall provide them, so they can be imported; a good example is the Prisma client.

Note: Please import from the providing package, for example:

import { PrismaClient } from '@symbux/turbo';
Name Description Type Provided By Example
PrismaClient An instance of the Prisma client. PrismaClient @symbux/turbo @Inject() private prisma!: PrismaClient

Features

Plugins

Future Plans

Resources

Clone this wiki locally