Description
http://symfony.com/doc/current/service_container/alias_private.html
What makes private services special is that, if they are only injected once, they are converted from services to inlined instantiations (e.g. new PrivateThing()). This increases the container's performance.
It seems that a private service is only inline instantiated if there is only one service depending on it which is not shared(shared:false
), couldn't find any other use case..
Now that the service is private, you should not fetch the service directly from the container:
This may or may not work, depending on if the service could be inlined. Simply said: A service can be marked as private if you do not want to access it directly from your code
Whether the private service is inline instantiated or not, or even used or not, i couldn't find any use-case where i could get it manually from the container.
Services are by default public, but it's considered a good practice to mark as much services private as possible.
For something that's considered a good practise, it would be good to have a little insight on what's going on. You would expect a private service to simply not be callable from the container, let alone "it may or may not". It doesn't seem to have any use besides the small performance boost, and the vague behaviour you get in return doens't seem worth it.
It feels like poor design and not good practise at all, but maybe someone can improve the docs. I looked into the file that has the conditions, but they contain no inline docs with some sort of clarification.
This would feel like a more solid feature doing only what it suggests, namely the only possibility for it to be injected into another service, no side-effects or performance boosts