-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Dmytro Shchehlov edited this page Dec 28, 2024
·
5 revisions
di-tory is a lightweight dependency injection library for TypeScript.
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.
npm install di-toryThe 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:
-
.private(resolvers, scope?): Defines resolution rules for private instances. -
.public(resolvers, scope?): Defines resolution rules for public instances. -
.privateImpl(implementation): Defines private methods. -
.publicImpl(implementation): Defines public methods. -
.init(initializers): Defines initializers for instances. -
.create(params): Creates an instance of the module.
... coming soon ...