|
1 | 1 | Types of Injection
|
2 | 2 | ==================
|
3 | 3 |
|
4 |
| -Making a class's dependencies explicit and requiring that they be injected |
5 |
| -into it is a good way of making a class more reusable, testable and decoupled |
6 |
| -from others. |
| 4 | +Making a class's dependencies explicit and requiring that they are injected |
| 5 | +into it is a good way to make a class more reusable, testable, and decoupled |
| 6 | +from the rest of the code. |
7 | 7 |
|
8 | 8 | There are several ways that the dependencies can be injected. Each injection
|
9 | 9 | point has advantages and disadvantages to consider, as well as different
|
@@ -88,10 +88,10 @@ service container configuration:
|
88 | 88 | There are several advantages to using constructor injection:
|
89 | 89 |
|
90 | 90 | * If the dependency is a requirement and the class cannot work without it
|
91 |
| - then injecting it via the constructor ensures it is present when the class |
| 91 | + then injecting it via the constructor ensures it is present especially when the class |
92 | 92 | is used as the class cannot be constructed without it.
|
93 | 93 |
|
94 |
| -* The constructor is only ever called once when the object is created, so |
| 94 | +* The constructor is only called once when the object is created, so |
95 | 95 | you can be sure that the dependency will not change during the object's
|
96 | 96 | lifetime.
|
97 | 97 |
|
@@ -190,7 +190,7 @@ so, here's the advantages of immutable-setters:
|
190 | 190 | * Immutable setters works with optional dependencies, this way, if you don't need
|
191 | 191 | a dependency, the setter doesn't need to be called.
|
192 | 192 |
|
193 |
| -* Like the constructor injection, using immutable setters force the dependency to stay |
| 193 | +* Like the constructor injection, using immutable setters forces the dependency to stay |
194 | 194 | the same during the lifetime of a service.
|
195 | 195 |
|
196 | 196 | * 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::
|
362 | 362 | ->property('mailer', service('mailer'));
|
363 | 363 | };
|
364 | 364 |
|
365 |
| -There are mainly only disadvantages to using property injection, it is similar |
| 365 | +There are mainly only disadvantages to using property injection. It is similar |
366 | 366 | to setter injection but with this additional important problem:
|
367 | 367 |
|
368 | 368 | * You cannot control when the dependency is set at all, it can be changed
|
|
0 commit comments