Request Bean

scope is a bean of request type, the framework is not 初始化 when it is 初始化

Instead, lazy loading is used after the onRequest event is triggered.

It will not be initialized when the framework is initialized.

It will only be initialized when it is actually called. The singleton will be kept in the current request and will be automatically destroyed after the request ends. The scope is always in one request


Can only be obtained by getting BeanFactory::getRequestBean

$obj = BeanFactory::getRequestBean($name, (string) $tid);
  • name requestBean 的名称/别名/类名
  • tid 通常是与是顶级协程ID绑定。获取顶级协程IDCo::tid()获取当前协程环境 顶级协程ID

如果你需要获取当前请求加载了那些 request bean 。可以使用:

$pool = BeanFactory::getContainer()->getRequestPool()


After all coroutines have been executed, the request bean bound to the 顶级协程ID is 自动销毁 in the SwoftEvent::COROUTINE_COMPLETE event.

At this point, the life cycle of the request bean is over.