Browse files

minor #4656 Tried to clarify private services (WouterJ)

This PR was merged into the 2.3 branch.


Tried to clarify private services

| Q   | A
| --- | ---
| Doc fix? | yes
| New docs? | kind of
| Applies to | all
| Fixed tickets | #4524

It was a though one to describe, as I wanted to make it clear and short. I'm really happy if people can review this and provide other, better, alternatives!


d89ad21 Tried to clarify private services
  • Loading branch information...
weaverryan committed Jan 3, 2015
2 parents 127ebc1 + d89ad21 commit 9958c41f8efdd143cba1b1e832c7d8b61aa15030
Showing with 9 additions and 5 deletions.
  1. +9 −5 components/dependency_injection/advanced.rst
@@ -20,11 +20,14 @@ argument for another service.
.. _inlined-private-services:
.. note::
Since a container is not able to detect if a service is retrieved from inside
the container or the outside, a private service may still be retrieved using
the ``get()`` method.
If you use a private service as an argument to only one other service,
this will result in an inlined instantiation (e.g. ``new PrivateFooBar()``)
inside this other service, making it publicly unavailable at runtime.
What makes private services special, is that they are converted from services
to inlined instantiation (e.g. ``new PrivateThing()``) when they are only
injected once, to increase the container performance. This means that you can
never be sure if a private service exists in the container.
Simply said: A service will be private when you do not want to access it
directly from your code.
@@ -60,7 +63,8 @@ Here is an example:
$container->setDefinition('foo', $definition);
Now that the service is private, you *cannot* call::
Now that the service is private, you *should not* call (should not means, this
*might* fail, see the explaination above)::

0 comments on commit 9958c41

Please sign in to comment.