From 072f64eb29c1cebf7772296fcf7dc7b1f97dfbef Mon Sep 17 00:00:00 2001 From: lkolndeep Date: Fri, 5 Sep 2025 22:46:05 +0200 Subject: [PATCH] [DependencyInjection] Corrections and rephrasings --- service_container/injection_types.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/service_container/injection_types.rst b/service_container/injection_types.rst index f56458b4c20..8f6ee2f5cc5 100644 --- a/service_container/injection_types.rst +++ b/service_container/injection_types.rst @@ -1,9 +1,9 @@ Types of Injection ================== -Making a class's dependencies explicit and requiring that they be injected +Making a class's dependencies explicit and requiring that they must be injected into it is a good way of making a class more reusable, testable and decoupled -from others. +from other parts of the code. There are several ways that the dependencies can be injected. Each injection point has advantages and disadvantages to consider, as well as different @@ -88,10 +88,10 @@ service container configuration: There are several advantages to using constructor injection: * If the dependency is a requirement and the class cannot work without it - then injecting it via the constructor ensures it is present when the class + then injecting it via the constructor ensures it is present especially when the class is used as the class cannot be constructed without it. -* The constructor is only ever called once when the object is created, so +* The constructor is only called once when the object is created, so you can be sure that the dependency will not change during the object's lifetime. @@ -190,7 +190,7 @@ so, here's the advantages of immutable-setters: * Immutable setters works with optional dependencies, this way, if you don't need a dependency, the setter doesn't need to be called. -* Like the constructor injection, using immutable setters force the dependency to stay +* Like the constructor injection, using immutable setters forces the dependency to stay the same during the lifetime of a service. * This type of injection works well with traits as the service can be composed, @@ -362,7 +362,7 @@ Another possibility is setting public fields of the class directly:: ->property('mailer', service('mailer')); }; -There are mainly only disadvantages to using property injection, it is similar +There are mainly only disadvantages to using property injection. It is similar to setter injection but with this additional important problem: * You cannot control when the dependency is set at all, it can be changed