dinjy
v0.1.2
Published
Simple, transparent, type-safe dependency injector
Readme
dinjy - Dani's Injection Thingy
A simple, type-safe dependency injector that you can add to any Node.js project.
The main goal of this project is to remain easy to use and set up, and to be transparent for the components being injected by not requiring them to be shaped around the functionality of the injector, and thus allow this library to serve as a useful tool you can add or remove rather than a key piece you are forced to shape your code around.
To this end, one key principle in guiding this project is that it must be possible to add the injector to a project that already follows the priciple of dependency injection (i.e., dependencies are provided by the constructing code, and not constructed by a component) without changing how the injected components work.
Usage
Usage of dinjy is divided into two steps. First, you use the Binder class to define your components, their
dependencies, and how to instantiate them:
import { Binder } from 'dinjy'
const binder = new Binder()
binder.bindConstructor(SomeComponent, [SomeDependency, AnotherDependency])Afterwards, you create an Injector by calling .injector() on your binder, allowing you to then get your instantiated components:
const injector = binder.injector()
const component = injector.get(SomeComponent)Documentation
TO-DO
Examples
Check the examples directory for a few usage examples.
License
This package is license under the MIT License. Check LICENSE for the full license.
