Injectofy is a TypeScript library designed to simplify dependency injection in your projects. It allows you to manage your dependencies easily, promoting better code organization and testability.
You can install Injectofy using Yarn:
yarn add injectofy
Or using npm:
npm install injectofy
First, set up the container in your project. This is where you'll register your dependencies.
import { Container } from 'injectofy';
const container = new Container();
You can register dependencies using the register method. You need to provide an identifier, the instance, and the class type.
export class TestService {
public getValue(): string {
return 'Hello, Injectofy!';
}
}
container.register('TestService', new TestService(), TestService);
You can resolve dependencies using the resolve method. NOTICE! : Service is of the type of the resolver automatically.
const service = container.resolve('TestService');