@@ -73,61 +73,6 @@ below) to access this service (via the alias).
7373
7474 Services are by default public.
7575
76- Synthetic Services
77- ------------------
78-
79- Synthetic services are services that are injected into the container instead
80- of being created by the container.
81-
82- For example, if you're using the :doc: `HttpKernel </components/http_kernel/introduction >`
83- component with the DependencyInjection component, then the ``request ``
84- service is injected in the
85- :method: `ContainerAwareHttpKernel::handle() <Symfony\\ Component\\ HttpKernel\\ DependencyInjection\\ ContainerAwareHttpKernel::handle> `
86- method when entering the request :doc: `scope </cookbook/service_container/scopes >`.
87- The class does not exist when there is no request, so it can't be included in
88- the container configuration. Also, the service should be different for every
89- subrequest in the application.
90-
91- To create a synthetic service, set ``synthetic `` to ``true ``:
92-
93- .. configuration-block ::
94-
95- .. code-block :: yaml
96-
97- services :
98- request :
99- synthetic : true
100-
101- .. code-block :: xml
102-
103- <?xml version =" 1.0" encoding =" UTF-8" ?>
104- <container xmlns =" http://symfony.com/schema/dic/services"
105- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
106- xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
107-
108- <services >
109- <service id =" request" synthetic =" true" />
110- </services >
111- </container >
112-
113- .. code-block :: php
114-
115- use Symfony\Component\DependencyInjection\Definition;
116-
117- $container
118- ->setDefinition('request', new Definition())
119- ->setSynthetic(true);
120-
121- As you see, only the ``synthetic `` option is set. All other options are only used
122- to configure how a service is created by the container. As the service isn't
123- created by the container, these options are omitted.
124-
125- Now, you can inject the class by using
126- :method: `Container::set <Symfony\\ Component\\ DependencyInjection\\ Container::set> `::
127-
128- // ...
129- $container->set('request', new MyRequest(...));
130-
13176Aliasing
13277--------
13378
0 commit comments