@@ -154,9 +154,6 @@ each time you ask for it.
154
154
_defaults :
155
155
autowire : true # Automatically injects dependencies in your services.
156
156
autoconfigure : true # Automatically registers your services as commands, event subscribers, etc.
157
- public : false # Allows optimizing the container by removing unused services; this also means
158
- # fetching services directly from the container via $container->get() won't work.
159
- # The best practice is to be explicit about your dependencies anyway.
160
157
161
158
# makes classes in src/ available to be used as services
162
159
# this creates a service per class whose id is the fully-qualified class name
@@ -177,7 +174,7 @@ each time you ask for it.
177
174
178
175
<services >
179
176
<!-- Default configuration for services in *this* file -->
180
- <defaults autowire =" true" autoconfigure =" true" public = " false " />
177
+ <defaults autowire =" true" autoconfigure =" true" />
181
178
182
179
<prototype namespace =" App\" resource =" ../src/*" exclude =" ../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}" />
183
180
</services >
@@ -815,8 +812,7 @@ loss, enable the compiler pass in your application.
815
812
Public Versus Private Services
816
813
------------------------------
817
814
818
- Thanks to the ``_defaults `` section in ``services.yaml ``, every service defined in
819
- this file is ``public: false `` by default.
815
+ From Symfony 4.0, every service defined is private by default.
820
816
821
817
What does this mean? When a service **is ** public, you can access it directly
822
818
from the container object, which is accessible from any controller that extends
@@ -956,9 +952,7 @@ them will not cause the container to be rebuilt.
956
952
.. note ::
957
953
958
954
Wait, does this mean that *every * class in ``src/ `` is registered as
959
- a service? Even model classes? Actually, no. As long as you have
960
- ``public: false `` under your ``_defaults `` key (or you can add it under the
961
- specific import), all the imported services are *private *. Thanks to this, all
955
+ a service? Even model classes? Actually, no. As long as you keep your imported services as :ref: `private <container-public >`, all
962
956
classes in ``src/ `` that are *not * explicitly used as services are
963
957
automatically removed from the final container. In reality, the import
964
958
means that all classes are "available to be *used * as services" without needing
0 commit comments