Skip to content

Commit d09cf03

Browse files
committed
[DI] Mark service as public with #[Autoconfigure] attribute
1 parent 22ea372 commit d09cf03

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

service_container.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,26 @@ setting:
927927
;
928928
};
929929
930+
It is also possible to define a service as public thanks to the ``#[Autoconfigure]``
931+
attribute. This attribute must be used directly on the class of the service
932+
you want to configure::
933+
934+
// src/Service/PublicService.php
935+
namespace App\Service;
936+
937+
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
938+
939+
#[Autoconfigure(public: true)]
940+
class PublicService
941+
{
942+
// ...
943+
}
944+
945+
.. versionadded:: 5.3
946+
947+
The ``#[Autoconfigure]`` attribute was introduced in Symfony 5.3. PHP
948+
attributes require at least PHP 8.0.
949+
930950
.. deprecated:: 5.1
931951

932952
As of Symfony 5.1, it is no longer possible to autowire the service

service_container/alias_private.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ You can also control the ``public`` option on a service-by-service basis:
6262
->public();
6363
};
6464
65+
It is also possible to define a service as public thanks to the ``#[Autoconfigure]``
66+
attribute. This attribute must be used directly on the class of the service
67+
you want to configure::
68+
69+
// src/Service/Foo.php
70+
namespace App\Service;
71+
72+
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
73+
74+
#[Autoconfigure(public: true)]
75+
class Foo
76+
{
77+
// ...
78+
}
79+
80+
.. versionadded:: 5.3
81+
82+
The ``#[Autoconfigure]`` attribute was introduced in Symfony 5.3. PHP
83+
attributes require at least PHP 8.0.
84+
6585
.. _services-why-private:
6686

6787
Private services are special because they allow the container to optimize whether

0 commit comments

Comments
 (0)