I am creating a Symfony Bundle that defines a synthetic service:
my_alias:
public: true
synthetic: true
After installing the bundle, the application's console command cache:clear
always fails with the error:
[Symfony\Component\DependencyInjection\Exception\RuntimeException] Invalid service "my_alias": class "" does not exist.
If I create the same alias inside the actual framework, this error does not turn up.
Is this a bug, or am I doing something wrong?
答案 0 :(得分:0)
清除缓存后,将重新编译内核,并且容器将不会找出未注入到容器中的服务,这就是为什么需要将其注入到您的Kernel类下:
if (!$container->hasDefinition('my_alias')) {
$container->set('my_alias', new SyntheticService());
}