You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by bu...@apache.org on 2013/02/25 13:20:49 UTC

svn commit: r851873 - in /websites/production/tapestry/content: cache/main.pageCache tapestry-ioc-overview.html

Author: buildbot
Date: Mon Feb 25 12:20:48 2013
New Revision: 851873

Log:
Production update by buildbot for tapestry

Modified:
    websites/production/tapestry/content/cache/main.pageCache
    websites/production/tapestry/content/tapestry-ioc-overview.html

Modified: websites/production/tapestry/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.

Modified: websites/production/tapestry/content/tapestry-ioc-overview.html
==============================================================================
--- websites/production/tapestry/content/tapestry-ioc-overview.html (original)
+++ websites/production/tapestry/content/tapestry-ioc-overview.html Mon Feb 25 12:20:48 2013
@@ -130,6 +130,23 @@ table.ScrollbarTable td.ScrollbarNextIco
 
 <h2><a shape="rect" name="TapestryIoCOverview-DependencyInjection"></a>Dependency Injection</h2>
 
+<p>Main Article: <a shape="rect" href="injection.html" title="Injection">Injection</a></p>
+
+<div class="navmenu" style="float:right; background:#eee; margin:3px; padding:3px"><table class="tableview" width="100%"><tr><th colspan="1" rowspan="1" style="padding: 3px 3px 3px 0px">Related Articles</th></tr><tr><td colspan="1" rowspan="1">
+                                 <span class="icon icon-page" title="Page">Page:</span>
+                         <a shape="rect" href="injection-faq.html">Injection FAQ</a>
+        
+                                            </td></tr><tr><td colspan="1" rowspan="1">
+                                 <span class="icon icon-page" title="Page">Page:</span>
+                         <a shape="rect" href="injection-in-detail.html">Injection in Detail</a>
+        
+                                            </td></tr><tr><td colspan="1" rowspan="1">
+                                 <span class="icon icon-page" title="Page">Page:</span>
+                         <a shape="rect" href="injection.html">Injection</a>
+        
+                                            </td></tr></table>
+</div>
+
 <p>Inversion of Control refers to the fact that the container, here Tapestry IoC's Registry, instantiates your classes. It decides on when the classes get instantiated.</p>
 
 <p>Dependency Injection is a key part of <em>realization</em>: this is how a service is provided with the other services it needs to operate. For example, a Data Access Object service may be injected with a ConnectionPool service.</p>
@@ -140,7 +157,7 @@ table.ScrollbarTable td.ScrollbarNextIco
 
 <h2><a shape="rect" name="TapestryIoCOverview-Whycan%27tIjustuse%7B%7Bnew%7D%7D%3F"></a>Why can't I just use <tt>new</tt>?</h2>
 
-<p>That's a common question. All these new concepts seem alien. All that XML (in the Spring or HiveMind IoC containers; Tapestry IoC uses no XML) is a burden. What's wrong with <tt>new</tt>?</p>
+<p>That's a common question. All these concepts seem alien at first. What's wrong with <tt>new</tt>?</p>
 
 <p>The problem with new is that it rigidly connects one implementation to another implementation. Let's follow a progression that reflects how a lot of projects get written. It will show that in the real world, <tt>new</tt> is not as simple as it first seems.</p>
 
@@ -156,13 +173,12 @@ table.ScrollbarTable td.ScrollbarNextIco
 
   <span class="code-keyword">public</span> void execute() 
   {
-
     <span class="code-object">int</span> rowCount = . . .;
     Metric metric = <span class="code-keyword">new</span> Metric(<span class="code-quote">"app/clients"</span>, <span class="code-object">System</span>.currentTimeMillis(), rowCount);
-
     <span class="code-keyword">new</span> QueueWriter().sendMetric(metric);
   }
-}</pre>
+}
+</pre>
 </div></div>
 
 <p>We've omitted some of the details (this code will need a database URL or a connection pool to operate), so as to focus on the one method and it's relationship to the QueueWriter class.</p>
@@ -181,8 +197,7 @@ table.ScrollbarTable td.ScrollbarNextIco
   {
     <span class="code-object">int</span> rowCount = . . .;
     Metric metric = <span class="code-keyword">new</span> Metric(<span class="code-quote">"app/clients"</span>, <span class="code-object">System</span>.currentTimeMillis(), rowCount);
-
-   queueWriter.sendMetric(metric);
+    queueWriter.sendMetric(metric);
   }</pre>
 </div></div>
 
@@ -211,11 +226,13 @@ table.ScrollbarTable td.ScrollbarNextIco
   <span class="code-keyword">public</span> <span class="code-keyword">static</span> getInstance()
   {
     <span class="code-keyword">if</span> (instance == <span class="code-keyword">null</span>)
+    {
       instance = <span class="code-keyword">new</span> QueueWriter();
-
+    }
     <span class="code-keyword">return</span> instance;
   }
-}</pre>
+}
+</pre>
 </div></div>
 
 <p>Much better! Now all the metric producers running inside all the threads can share a single QueueWriter. Oh wait ...</p>
@@ -225,10 +242,12 @@ table.ScrollbarTable td.ScrollbarNextIco
   <span class="code-keyword">public</span> <span class="code-keyword">synchronized</span> <span class="code-keyword">static</span> getInstance()
   {
     <span class="code-keyword">if</span> (instance == <span class="code-keyword">null</span>)
+    {
       instance = <span class="code-keyword">new</span> QueueWriter();
-
+    }
     <span class="code-keyword">return</span> instance;
-  }</pre>
+  }
+</pre>
 </div></div>
 
 <p>Is that necessary? Yes. Will the code work without it? Yes &#8211; <b>99.9% of the time</b>. In fact, this is a very common error in systems that manually code a lot of these construction patterns: forgetting to properly synchronize access. These things often work in development and testing, but fail (with infuriating infrequency) in production, as it takes two or more threads running simultaneously to reveal the coding error.</p>
@@ -273,7 +292,8 @@ table.ScrollbarTable td.ScrollbarNextIco
 
    queueWriter.sendMetric(metric);
   }
-}</pre>
+}
+</pre>
 </div></div>
 
 <p>This still isn't ideal, as we still have an explicit linkage between TableMetricProducer and QueueWriterImpl.</p>
@@ -298,7 +318,8 @@ table.ScrollbarTable td.ScrollbarNextIco
   {
     configuration.add(<span class="code-keyword">new</span> TableMetricProducer(queueWriter, . . .))
   }
-}</pre>
+}
+</pre>
 </div></div>
 
 <p>Again, we've omitted a few details related to the database the TableMetricProducer will point at (in fact, Tapestry IoC provides a lot of support for configuration of this type as well, which is yet another concern).</p>