Skip to content
Dmytro Shchehlov edited this page Dec 28, 2024 · 5 revisions

di-tory is a lightweight dependency injection library for TypeScript.

Motivation

The library is designed to enable writing clean and testable code without cluttering the codebase with dependency injection boilerplate or relying on a heavy dependency injection framework.

So the di-tory is:

  • Lightweight: The library is designed to be as small as possible.
  • Type Safe: The library is written in TypeScript and provides type-safe DI.
  • Framework Agnostic: The library is designed to be used with any framework or without any framework.
  • Platform Agnostic: The library is designed to be used in Node.js, the browser, or any other platform.

Installation

npm install di-tory

Examples

The library is based on the following concepts:

  • Module: A container for instances and methods.
  • Module Builder: A builder for a module.
  • Visibility: A way to define the visibility of instances and methods.
  • Resolver: A function that creates an instance, resolving its dependencies.
  • Lifecycle (Scope): A way to manage the lifecycle of instances.
  • Implementation: A way to define a module methods.
  • Initializers: A way to resolve circular dependencies, by initializing instances after their creation.

The library core is a ModuleBuilder object, which is used to define a module structure.

The ModuleBuilder is exposed as a factory function Module, so you cna import it like this:

import { Module } from 'di-tory';

The ModuleBuilder has the following methods:

... coming soon ...