We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我们想要在controller中使用this.ctx.service.check.index();这样的形式,那我们必须要对ctx.service的getter进行重写。 我们在controller中可能会多次使用到this.ctx.service对象,所以我们必须要对其进行缓存,不然每次使用,我们都遍历service文件夹,导入模块,重新生成所有service对象,再挂载,我们的性能会急剧下降。
如果直接在外部初始化,是不是就不需要缓存了?这两种写法有什么 优劣吗?(loadConfig 好像也是类似这么实现的)
loadService() { const services = fs.readdirSync(__dirname + '/service'); const loaded = {}; services.forEach(serivce => { const name = serivce.split('.')[0]; const mod = require(__dirname + '/service/' + services); loaded[name] = new mod(this); }) Object.defineProperty(this.app.context, 'service', { get() { return loaded } }) }
The text was updated successfully, but these errors were encountered:
@Joursion 我们要保证每个service的生命周期和context是一样的,也就是说,每一条链接,我们需要一个新的context、controller、service。
Sorry, something went wrong.
@Foveluy 这样有什么意义呢? service 状态的原因吗?
No branches or pull requests
如果直接在外部初始化,是不是就不需要缓存了?这两种写法有什么 优劣吗?(loadConfig 好像也是类似这么实现的)
The text was updated successfully, but these errors were encountered: