On a Symfony 5.4 project, I am trying to get rid of this deprecation
Since symfony/framework-bundle 5.3: The “SymfonyComponentHttpFoundationSessionSessionInterface” and “SessionInterface” aliases are deprecated, use “$requestStack->getSession()” instead.
I followed the official doc for service, so
use SymfonyComponentHttpFoundationRequestStack;
class SomeService
{
public function __construct(private RequestStack $requestStack)
{
}
public function someMethod()
{
$session = $this->requestStack->getSession();
$session->get("...");
}
}
instead of the previous version that was
use SymfonyComponentHttpFoundationSessionSessionInterface;
class SomeService
{
public function __construct(private SessionInterface $session)
{
}
public function someMethod()
{
$this->session->get("...");
}
}
but this fails with SessionNotFoundException
and error
There is currently no session available.
it seems that the RequestStack
that the dependency injector injects inside the service has no Session available.