Skip to content

Commit 97f13fa

Browse files
committed
feat(info): progress on type advantages/disadvantages
1 parent 59f1500 commit 97f13fa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

service_container/injection_types.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ which allow the container to return the newly created service:
322322
$container->register('app.newsletter_manager', NewsletterManager::class)
323323
->addMethodCall('withMailer', [new Reference('mailer')], true);
324324
325+
.. note::
326+
327+
This type of injection require that you add a `@return static` docblock in order
328+
to be capable of understanding the method usage.
329+
325330
This approach is useful if you need to configure your service according to your needs,
326331
so, what are the advantages?
327332

@@ -338,3 +343,12 @@ so, what are the advantages?
338343

339344
* As the method automatically receive and set the attribute value,
340345
you couldn't obtain the newly created service without this dependency.
346+
347+
The disadvantages are:
348+
349+
* As the `@return static` docblock is required by the container to
350+
understand that the method return a cloned object, you can
351+
found that adding docblock for a single method isn't adapted.
352+
353+
* As a new object is created once the method is called,
354+
you can found hard to debug and test your code.

0 commit comments

Comments
 (0)