1
我正在處理一些回購。並添加重構提取一些功能類Node.js +測試:DI與硬依賴
問題是 - 我更喜歡使用從外部傳遞的依賴關係(DI)。但是我發現它不是node.js應用程序的常見模式。
所以這個問題 - 是否有任何很好的例子(鏈接到回購),其中傢伙使用DI提供依賴關係。
相反的意見是 - 「我們總是可以用proxyquire
模塊來模擬依賴」
PS 例子代碼我的建議是
// use
const inst = new Cls(getDep1(), getDep2());
// where getDep1/getDep2 provide dependencies from side modules
,而不是
//Cls
const dep1 = require('dep1');
const dep2 = require('dep2');
module.exports = function Cls() {
// deps usage
}
// and
const inst = new Cls();
的問題是關於node.js相關項目中的參數