Injects
Dependency injection for TypeScript : https://mickgrz.github.io/injects/
Use case :
Use a class instance without instantiate it.
The responsibility of providing dependency is delegated to an injector.
This separates the responsibilities of usages and construction.
This also improves readability, testability & maintainability.
Example :
public { ... }
;; private dao: Dao; { thisdao = ; } public { return thisdao; }
const service: Service = ;service;// will call dao.create
You can also write :
;; private dao: Dao = ; public { return thisdao; }
Unit test example :
Stubbing dependency is easy :
;; ;const service: Service = ;// will get stub dependencyservice;// will call the stub
Name of dependency's class is the key used to register the dependency instance.
Installation :
npm install --save injects