我正在使用symfony/dependency-injection组件(注意:不是使用完整的堆栈框架)
在注册新服务时,我想在构造函数中注入一个类的新实例。例如:
$container->register('session', 'Vendor\Core\Session')
->addArgument(new PhpBridgeSessionStorage());
这个例子非常好,但如果我想使用yml文件来定义这个服务怎么办?就像这样:
services:
session:
class: Vendor\Core\Session
arguments: [ new Class\To\Inject ]
我需要定义 Class\To\Inject 作为新服务吗?还是需要创建服务工厂?