Skip to content

Commit 54e5ffd

Browse files
committed
Mention DI in Singleton. Fix munificent#184.
1 parent 479339b commit 54e5ffd

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

book/singleton.markdown

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,18 @@ working with it. Before we take the shotgun approach of a singleton
449449
object with *global* scope, let's consider other ways our codebase can
450450
get access to an object:
451451

452-
* **Pass it in.** The simplest solution, and often the best, is to simply pass the
453-
object you need as an argument to the functions that need it. It's worth
454-
considering before we discard it as too cumbersome.
452+
* **Pass it in.** The <span name="di">simplest</span> solution, and often the
453+
best, is to simply pass the object you need as an argument to the functions
454+
that need it. It's worth considering before we discard it as too cumbersome.
455+
456+
<aside name="di">
457+
458+
Some use the term "dependency injection" to refer
459+
to this. Instead of code reaching *out* and finding its dependencies by calling into something global, the dependencies are pushed *in* to the code that needs it through parameters.
460+
461+
Others reserve "dependency injection" for more complex ways of providing dependencies to code.
462+
463+
</aside>
455464

456465
Consider a function for rendering objects. In order to render, it
457466
needs access to an object that represents the graphics device and maintains the render state. It's very common to just pass that in to all of the rendering functions, usually as a parameter named something like `context`.

html/singleton.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,16 @@ <h3><a href="#to-provide-convenient-access-to-an-instance" name="to-provide-conv
590590
get access to an object:</p>
591591
<ul>
592592
<li>
593-
<p><strong>Pass it in.</strong> The simplest solution, and often the best, is to simply pass the
594-
object you need as an argument to the functions that need it. It&#8217;s worth
595-
considering before we discard it as too cumbersome.</p>
593+
<p><strong>Pass it in.</strong> The <span name="di">simplest</span> solution, and often the
594+
best, is to simply pass the object you need as an argument to the functions
595+
that need it. It&#8217;s worth considering before we discard it as too cumbersome.</p>
596+
<aside name="di">
597+
598+
<p>Some use the term &#8220;dependency injection&#8221; to refer
599+
to this. Instead of code reaching <em>out</em> and finding its dependencies by calling into something global, the dependencies are pushed <em>in</em> to the code that needs it through parameters.</p>
600+
<p>Others reserve &#8220;dependency injection&#8221; for more complex ways of providing dependencies to code.</p>
601+
</aside>
602+
596603
<p>Consider a function for rendering objects. In order to render, it
597604
needs access to an object that represents the graphics device and maintains the render state. It&#8217;s very common to just pass that in to all of the rendering functions, usually as a parameter named something like <code>context</code>.</p>
598605
<p>On the other hand, some objects don&#8217;t belong in the signature of a

0 commit comments

Comments
 (0)