AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
## 通过@Inject注解注入 ~~~ <?php namespace App\Controller; use App\Service\UserService; use Hyperf\Di\Annotation\Inject; class IndexController { /** * 通过 `@Inject` 注解注入由 `@var` 注解声明的属性类型对象 * * @Inject * @var UserService */ private $userService; public function index() { $id = 1; // 直接使用 return $this->userService->getInfoById($id); } } ~~~ > 通过`@Inject`注解注入可作用于 DI 创建的(单例)对象,也可作用于通过`new`关键词创建的对象; > 使用`@Inject`注解时需`use Hyperf\Di\Annotation\Inject;`命名空间;