8000 Add warning about removed services by alexislefebvre · Pull Request #14819 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Add warning about removed services #14819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

alexislefebvre
Copy link
Contributor
@alexislefebvre alexislefebvre commented Jan 11, 2021

I was confused by the fact that the documentation explains:

Finally, for the most rare edge-cases, Symfony includes a special container which provides access to all services, public and private. This special container is a service that can be get via the normal container

and the fact that the special container doesn't give access to the removed service.

So I added a tip in the documentation, taking inspiration from a Symfony article:

Keep in mind that, because of how Symfony's service container work, unused services are removed from the container. This means that if you have a private service not used by any other service, Symfony will remove it and you won't be able to get it as explained in this article. The solution is to define the service as public explicitly so Symfony doesn't remove it.

Source: https://symfony.com/blog/new-in-symfony-4-1-simpler-service-testing

This is also consistent with the error message from Symfony: https://github.com/symfony/symfony/blob/3ffe5573e9dd045e157c6f17358c700fceae3feb/src/Symfony/Component/DependencyInjection/Container.php#L275

See also #12647 and symfony/symfony#30104

@carsonbot carsonbot added this to the 4.4 milestone Jan 11, 2021
@alexislefebvre alexislefebvre changed the title Add tip about removed services Add warning about removed services Jan 11, 2021
@javiereguiluz javiereguiluz force-pushed the add-tip-about-removed-services branch from 9bd3b60 to e6a6c33 Compare January 15, 2021 16:06
@javiereguiluz javiereguiluz merged commit c9bad24 into symfony:4.4 Jan 15, 2021
@javiereguiluz
Copy link
Member

Thank you Alexis!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0