@@ -308,7 +308,10 @@ and a Twitter client using it:
308
308
services :
309
309
rot13_transformer :
310
310
class : Acme\Rot13Transformer
311
- autowiring_types : Acme\TransformerInterface
311
+
312
+ Acme\TransformerInterface :
313
+ alias : rot13_transformer
314
+ public : false
312
315
313
316
twitter_client :
314
317
class : Acme\TwitterClient
@@ -330,9 +333,8 @@ and a Twitter client using it:
330
333
xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
331
334
332
335
<services >
333
- <service id =" rot13_transformer" class =" Acme\Rot13Transformer" >
334
- <autowiring-type >Acme\TransformerInterface</autowiring-type >
335
- </service >
336
+ <service id =" rot13_transformer" class =" Acme\Rot13Transformer" />
337
+ <service id =" Acme\TransformerInterface" alias =" rot13_transformer" public =" false" />
336
338
337
339
<service id =" twitter_client" class =" Acme\TwitterClient" autowire =" true" />
338
340
@@ -352,13 +354,13 @@ and a Twitter client using it:
352
354
use Acme\TransformerInterface;
353
355
use Acme\TwitterClient;
354
356
use Acme\UppercaseTransformer;
357
+ use Symfony\Component\DependencyInjection\Alias;
355
358
use Symfony\Component\DependencyInjection\Reference;
356
359
use Symfony\Component\DependencyInjection\Definition;
357
360
358
361
// ...
359
- $rot13Definition = new Definition(Rot13Transformer::class);
360
- $rot13Definition->setAutowiringTypes(array(TransformerInterface::class));
361
- $container->setDefinition('rot13_transformer', $rot13Definition);
362
+ $container->register('rot13_transformer', Rot13Transformer::class);
363
+ $container->setAlias(TransformerInterface::class, new Alias('rot13_transformer', false))
362
364
363
365
$clientDefinition = new Definition(TwitterClient::class);
364
366
$clientDefinition->setAutowired(true);
@@ -382,10 +384,14 @@ to use which leads to errors like this:
382
384
[Symfony\Component\DependencyInjection\Exception\RuntimeException]
383
385
Unable to autowire argument of type "Acme\TransformerInterface" for the service "twitter_client".
384
386
385
- Fortunately, the ``autowiring_types `` key is here to specify which implementation
386
- to use by default. This key can take a list of types if necessary.
387
+ Fortunately, the FQCN alias is here to specify which implementation
388
+ to use by default.
389
+
390
+ .. versionadded :: 3.2
391
+ Using FQCN aliases to fix autowiring ambiguities is allowed since Symfony
392
+ 3.3. Prior to version 3.3, you needed to use the ``autowiring_types `` key.
387
393
388
- Thanks to this setting , the ``rot13_transformer `` service is automatically injected
394
+ Thanks to this alias , the ``rot13_transformer `` service is automatically injected
389
395
as an argument of the ``uppercase_transformer `` and ``twitter_client `` services. For
390
396
the ``uppercase_twitter_client ``, a standard service definition is used to
391
397
inject the specific ``uppercase_transformer `` service.
0 commit comments