Injets is a TypeScript Dependency Injection library inspired by NestJS that uses reflect-metadata and annotations to make your code more organized.
Features
💉 Dependency Injection: Organize your code in modules and inject providers in other modules.
✏️ Annotations: Use annotations in your module classes to make your dependecy flow easier to understand.
🏢 Singletons and Transient providers: Create singletons just by specifying a single flag, and don't bother when you should instantiate your classes anymore.
Table of Contents
Installation
npm i injetsyarn add injets
Getting started
To start using injets, you first have to create a root module
.
A root module
is simply a starting point for your project, so all
other modules are going to be attached to it.
Here's how you can register a provider on the root module
:
// --- hello-world.provider.ts --- // --- app.module.ts ---;
Instantiating the root module
To get your app up and running you first have to instantiate the root module
.
To do so, there's a static helper called createModule
.
This is your entry point:
// --- index.js --- main
Accessing Providers
Providers are entities that are responsible for executing the logic of your application. You often have to access logic from other parts of your app.
To access another Provider, you can simply declare its type on the current Provider constructor:
// --- app.module.ts ---; // --- http.provider.ts ---;
Documentation
Modules
Modules are a group of providers, your application must have at least one module (root module).
Structure of a module
Providers
A provider can be anything you want to use anywhere in your application, but they are generally used to provide business logic methods for your app.
Structure of a provider
// A provider can have SINGLETON or TRANSIENT scope