injectio
from Latin injectio(n-), an instance of injecting or being injected
An opinionated, minimalist, dependency-free but functional dependency injection (DI) and inversion of control (IoC) for TypeScript.
Installation
npm install --save injectio
Basic usage
; // tell the IoC container that we want the same (singleton) ElasticSearchLogger instance when we request an instance of a LoggerContainer.bindLogger.singletonElasticSearchLogger; // instance.logger === ElasticSearchLogger ;// logger === instance.logger === ElasticSearchLogger
Declarative binding
// same as Container.bind(A).singleton(B) // same as Container.bind(A).instance(B) // same as Container.bind(A).factory((context) => new B())
Configuration values
Container.configure"mongo-connection-string", process.env.MONGO_CONNECTION_STRING);
Auto wiring
Automatic wiring allows classes to be directly instantiated without using the Container methods while resolving their injected dependencies.
;// b.a is a valid reference
Initializators
Initializators allow to execute arbitrary code after a instance of a binded class has been constructed and its dependencies injected.
;// b.squared === 100