1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 1× 1× 1× 1× 1× 1× 1× 1× 1× | /** * Created by zdy on 2016/10/9. */ 'use strict'; const Path = require('path'); const fs = require('fs'); class Service { constructor(app) { const self = this; // 应用中service目录 const serviceDir = Path.join(app.config.baseDir, require('../config/config').serviceDir); fs.readdirSync(serviceDir).forEach(function (file) { const objName = Path.basename(file, '.js'); const serviceClass= require(Path.join(serviceDir, objName))(); self[objName] = new serviceClass(); }); } } module.exports = Service; |