In symfony you have two ways of injecting something:
- Using the
services.yml
file - Using the
@required
annotation
I am trying to move away from services.yml
.
I can easily inject other services using the @required
like this:
class SomeClass
{
private LoggerInterface $logger;
/** @required */
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
}
Is there a way to inject a parameter using this method?
Currently I am using this hacky approach, but I was hoping for something more strait forward than injecting the entire container.
class SomeClass
{
private array $configuration;
/** @required */
public function setConfiguration(ContainerInterface $container)
{
$this->configuration = $container->getParameter('my_bundle.config');
}
}