在eggjs app.js文件中调用service的方法

栏目: EggJs

在 egg app.js 文件中,我们可以使用 app.createAnonymousContext() 方法创建一个匿名 Context 实例,这样就可以调用 service 的方法了。

module.exports = app => {
  app.beforeStart(() => {
    // app.createAnonymousContext() 方法创建一个匿名Context实例
    const ctx = app.createAnonymousContext()
    ctx.service.queue.process()
  })
}

本文地址:https://www.tides.cn/p_eggjs-app-context