Skip to content

Commit 2e820e6

Browse files
committed
minor #9755 [Autowiring] - Rephrase aliasing when multiple classes with same interface (Plopix, javiereguiluz)
This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #9755). Discussion ---------- [Autowiring] - Rephrase aliasing when multiple classes with same interface This PR aims to enforce the "non-magic" aspect of the Autowiring. Especially that sentence: ```If you register this as a service, you now have two services that implement the App\Util\TransformerInterface type. Symfony doesn't know which one should be used for autowiring, so you need to choose one by creating an alias from the type to the correct service id (see Working with Interfaces).``` This: `Symfony doesn't know which one should be used for autowiring` The more I read the more I think it is clear, but somehow It feels like, after one or two readings, you could understand that Symfony is somehow "choosing" by some sort of magic the service (i.e: Reflection for instance). Where it is definitely not and the "developer" *must decide* and tells the autowiring which one to use. I think the current sentence is also clearer when you read all the documentation page where often (I guess) developers go straight to what they need and in this case "how to configure when you have an interface and multiple classes" So I propose this change (which should not hurt) and open the discussion. Feel free to close if you think it is useless, I won't mind it did not take that long to do the PR ;) Commits ------- 3165948 Fixed formatting c89f73f Autowiring - Rephrase aliasing when multiple classes implement same interface
2 parents 63795fa + 3165948 commit 2e820e6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

service_container/autowiring.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,10 @@ Suppose you create a second class - ``UppercaseTransformer`` that implements
365365
}
366366

367367
If you register this as a service, you now have *two* services that implement the
368-
``AppBundle\Util\TransformerInterface`` type. Symfony doesn't know which one should
369-
be used for autowiring, so you need to choose one by creating an alias from the type
370-
to the correct service id (see :ref:`autowiring-interface-alias`).
368+
``AppBundle\Util\TransformerInterface`` type. Autowiring subsystem can not decide
369+
which one to use. Remember, autowiring isn't magic; it simply looks for a service
370+
whose id matches the type-hint. So you need to choose one by creating an alias
371+
from the type to the correct service id (see :ref:`autowiring-interface-alias`).
371372

372373
If you want ``Rot13Transformer`` to be the service that's used for autowiring, create
373374
that alias:

0 commit comments

Comments
 (0)