Incorrect ServiceCircularReferenceException? #2347
Comments
Circular references in the services can lead to incorrect creation of the objects, eventually leading to infinite loops. The issue is that each service requires the other one to be created before itself being created. |
So my service must somehow be passed TwigEngine from within my twig template? |
The |
It's been 3 years. It this possible yet (to not have to inject the container into a twig extension when you only need the templating service)? |
Answering my own question here. I think I can use |
@bmeynell I think what @fabpot was trying to say is that it is practically impossible: you need the twig service for the extension, but you need the extension for the twig service. So you have the circular reference, as thrown. It would only be possible if the twig service is only loaded when you actually need it (instead of on creation time) - which you do by inserting the whole service container and requesting the service in your method. |
It seems like it is not possible to only inject the templating See symfony/symfony#2347 (comment) for more information.
I've written a service that gets invoked inside a Twig template, which has a dependancy on the 'Templating' service. This results in a ServiceCircularReferenceException. Commenting out the exception causes the code to run fine.
The text was updated successfully, but these errors were encountered: