@@ -119,7 +119,7 @@ Fetching Services
119119-----------------
120120
121121If you extend the base ``Controller `` class, you can access services directly from
122- the container via ``$this->container->get() `` or ``$this->get() ``. Instead , you
122+ the container via ``$this->container->get() `` or ``$this->get() ``. But instead , you
123123should use dependency injection to fetch services: most easily done by
124124:ref: `type-hinting action method arguments <controller-accessing-services >`:
125125
@@ -128,6 +128,9 @@ should use dependency injection to fetch services: most easily done by
128128 Don't use ``$this->get() `` or ``$this->container->get() `` to fetch services
129129 from the container. Instead, use dependency injection.
130130
131+ By not fetching services directly from the container, you can make your services
132+ *private *, which has :ref: `several advantages <services-why-private >`.
133+
131134.. _best-practices-paramconverter :
132135
133136Using the ParamConverter
@@ -177,14 +180,13 @@ manually. In our application, we have this situation in ``CommentController``:
177180
178181.. code-block :: php
179182
180- use Doctrine\ORM\EntityManagerInterface;
181-
182183 /**
183184 * @Route("/comment/{postSlug}/new", name = "comment_new")
184185 */
185- public function newAction(Request $request, $postSlug, EntityManagerInterface $em )
186+ public function newAction(Request $request, $postSlug)
186187 {
187- $post = $em->getRepository('AppBundle:Post')
188+ $post = $this->getDoctrine()
189+ ->getRepository('AppBundle:Post')
188190 ->findOneBy(array('slug' => $postSlug));
189191
190192 if (!$post) {
0 commit comments