Skip to content

Commit 798dab4

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: [DI] Mark service as public with #[Autoconfigure] attribute
2 parents 48726ce + 5d8e49c commit 798dab4

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

service_container.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,21 @@ setting:
11151115
;
11161116
};
11171117
1118+
It is also possible to define a service as public thanks to the ``#[Autoconfigure]``
1119+
attribute. This attribute must be used directly on the class of the service
1120+
you want to configure::
1121+
1122+
// src/Service/PublicService.php
1123+
namespace App\Service;
1124+
1125+
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
1126+
1127+
#[Autoconfigure(public: true)]
1128+
class PublicService
1129+
{
1130+
// ...
1131+
}
1132+
11181133
.. _service-psr4-loader:
11191134

11201135
Importing Many Services at once with resource

service_container/alias_private.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ 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+
6580
.. _services-why-private:
6681

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

0 commit comments

Comments
 (0)