idd
A dependency injection system with destructuring. Combines a common pattern of using a single destructuring argument to avoid confusing the order of arguments to high-parity functions, possibly with many optional parameters.
Getting Started
To install the dependency injection system, use npm install
npm install --save idd
Then, from other peer directories, you can require the files as properties on the directory's default export
lib/config.js
{ return language: 'ru-ru' level: 'info' ;};
lib/greeter.js
{ const logger = ; return { if configlanguage === 'en-us' logger; else if configlanguage === 'ru-ru' logger; else logger; } ;};
lib/Logger.js
; { thislevel = processenvLEVEL; } { if thislevel !== 'quiet' console; } { if thislevel !== 'quiet' && thislevel !== 'silent' chalk; };
index.js
;; const greeter = ; greeter;
Then the output would be 'Hello World!'. If you were to change config to be instead
{ language: 'ru-ru' level: 'error'}
Then the output would be 'Привет, мир!'.
Testing
A good dependency injection system should make unit testing easy. To mock out your dependencies, just provide an optional third option with the mocks
;;; ;