<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-10584900</id><updated>2024-09-16T19:18:40.932-05:00</updated><category term="castle"/><category term="monorail"/><category term="activerecord"/><category term="nhibernate"/><category term="csharp"/><category term="database"/><category term="sql"/><category term="sql server"/><category term="appengine"/><category term="architecture"/><category term="encryption"/><category term="ioc"/><category term="log4net"/><category term="microkernel"/><category term="mvc"/><category term="powershell"/><category term="security"/><category term="tdd"/><category term="windsor"/><title type='text'>Practical Software Development</title><subtitle type='html'>A blog about practical software development using .NET, C#, Castle, NHibernate, SQL Server, and more.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>24</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-10584900.post-1578415068832972620</id><published>2014-11-04T23:34:00.001-06:00</published><updated>2014-11-04T23:47:06.817-06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="appengine"/><category scheme="http://www.blogger.com/atom/ns#" term="encryption"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>Send Encrypted Messages That Expire</title><content type='html'>Store encrypted messages using &lt;a href=&quot;http://securesendapp.appspot.com&quot;&gt;this tool.&lt;/a&gt;  Messages expire after 24 hours.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/1578415068832972620/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/1578415068832972620' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/1578415068832972620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/1578415068832972620'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2014/11/store-encrypted-messages-using-this-tool.html' title='Send Encrypted Messages That Expire'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-8351913959079132126</id><published>2008-10-06T03:41:00.005-05:00</published><updated>2008-10-10T06:07:00.396-05:00</updated><title type='text'>Submit a Form with Multiple Buttons in Monorail</title><content type='html'>Here&#39;s how to submit a form with multiple buttons via MonoRail.  The javascript will control which action is called in the controller.  This example uses prototype to setup the event handlers:&lt;br /&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;br /&gt;$Form.FormTag(&quot;%{id=&#39;myform&#39;}&quot;)&lt;br /&gt;$Form.TextField(&quot;email&quot;)&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;button&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;addbutton&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Add&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;button&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;removebutton&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Remove&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;$Form.EndFormTag()&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Event.observe(&lt;span class=&quot;str&quot;&gt;window&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&#39;load&#39;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;function&lt;/span&gt;() {&lt;br /&gt;&lt;br /&gt; Event.observe(&lt;span class=&quot;str&quot;&gt;&#39;addbutton&#39;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&#39;click&#39;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;function&lt;/span&gt;() {&lt;br /&gt;   $(&lt;span class=&quot;str&quot;&gt;&#39;myform&#39;&lt;/span&gt;).action = &lt;span class=&quot;str&quot;&gt;&#39;$Url.For(&quot;%{action=&#39;&lt;/span&gt;addemail&lt;span class=&quot;str&quot;&gt;&#39;}&quot;)&#39;&lt;/span&gt;;&lt;br /&gt;   $(&lt;span class=&quot;str&quot;&gt;&#39;myform&#39;&lt;/span&gt;).submit();&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;;&lt;br /&gt; });&lt;br /&gt;&lt;br /&gt; Event.observe(&lt;span class=&quot;str&quot;&gt;&#39;removebutton&#39;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&#39;click&#39;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;function&lt;/span&gt;() {&lt;br /&gt;   $(&lt;span class=&quot;str&quot;&gt;&#39;myform&#39;&lt;/span&gt;).action = &lt;span class=&quot;str&quot;&gt;&#39;$Url.For(&quot;%{action=&#39;&lt;/span&gt;removeemail&lt;span class=&quot;str&quot;&gt;&#39;}&quot;)&#39;&lt;/span&gt;;&lt;br /&gt;   $(&lt;span class=&quot;str&quot;&gt;&#39;myform&#39;&lt;/span&gt;).submit();&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;;&lt;br /&gt; });&lt;br /&gt;&lt;br /&gt;});&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I used &lt;a href=&quot;http://www.manoli.net/csharpformat/&quot;&gt;http://www.manoli.net/csharpformat/&lt;/a&gt; to format the code.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/8351913959079132126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/8351913959079132126' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/8351913959079132126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/8351913959079132126'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2008/10/monorail-form-multiple-buttons-submit.html' title='Submit a Form with Multiple Buttons in Monorail'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-2590509468871926489</id><published>2008-06-12T23:29:00.012-05:00</published><updated>2008-06-13T00:16:07.410-05:00</updated><title type='text'>Generalizing the ELO Rating System for Multiple Players</title><content type='html'>The original &lt;a href=&quot;http://en.wikipedia.org/wiki/Elo_rating_system&quot;&gt;ELO rating system&lt;/a&gt; was designed for two player games.  I&#39;ve had a need to generalize the ELO rating system for games where there are more than two players.  I&#39;ve come with with some modifications to the system to allow for multiple players.&lt;br /&gt;&lt;br /&gt;The ELO system assigns a pool of players various ranks based on their abilities.  These ranks can be used to estimate the likelihood for a player to win a given game.&lt;br /&gt;&lt;br /&gt;For a given game, each player is assigned an estimated score which is roughly equivalent to the chance that the player has of winning the game.  After the game, each player&#39;s actual score is compared to his estimated score and his rating will be updated.&lt;br /&gt;&lt;br /&gt;There are a series of math equations that govern the system.&lt;br /&gt;&lt;br /&gt;Let&#39;s start with a two player game, and then generalize from there.&lt;br /&gt;&lt;br /&gt;For two players with rankings &lt;em&gt;R&lt;sub&gt;1&lt;/sub&gt;&lt;/em&gt; and &lt;em&gt;R&lt;sub&gt;2&lt;/sub&gt;&lt;/em&gt;, the estimated scores &lt;em&gt;E&lt;sub&gt;1&lt;/sub&gt;&lt;/em&gt; and &lt;em&gt;E&lt;sub&gt;2&lt;/sub&gt;&lt;/em&gt; are computed:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEjmQ7APRWLQAW5JnnmXQrAdC7VTOLWRGzniRCLvqZtJ00hEDdOLE5GOX6HJ0-g4HoZ6htV74LXV2QhyphenhyphenypX6jNWDqfi7GCKQUCBhyphenhyphenJToqKMXcs1PUgInIEuJTL5O2RNbV85Boh/s400/1.png&quot; /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVVNQl564g5cFb0ZMFixN_HKcOcdKvCgxNhRSpd31efn-gDkfACZD11Y-uDUfw3wXbRBcik6qkDTwgpHDj3qW3WYd8hNd9TzvzLCuwqJTWZdJ8J1DCOdSMKdArf3lPgb2Wegyz/s400/2.png&quot; /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;Note that:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-S4ZoBjaXipcv-PpIE04Kb16Fq3qoP97fbLajtgX-6qrGTTu4UnIOBN6e5oX1AAmtAy95paXiHzZkVjHOPc5wg7Y_wqK4biMb2ANo0tMvn6rbFOLRHmLYfntB-2QwNfYs_WOZ/s400/3.png&quot; align=&quot;middle&quot; /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Once the game is finished, a scoring function determines each player&#39;s actual score &lt;em&gt;S&lt;sub&gt;x&lt;/sub&gt;&lt;/em&gt;.  A common scoring function for games such as chess where a player &lt;em&gt;x&lt;/em&gt; may win, lose, or tie against another opponent is:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAUfEwTsloHR7hCCnl6yeDotNWpotXnZ4q6YDWuXpn8aHo09TmmkC7zJVCRyxN0Oyl2ncxJao30eQ7S0J-YqfzvZ1xVLkHGM6lEMZgKW0spQTrijsP-8QZQmk51qKB94tgKVw3/s400/17.png&quot; align=&quot;middle&quot; /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Note that:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ14TF0IgWCqM47rBzHMyuqIx6i2MsLYDKeBKevFY8CMfKc-ReFlSsY9TL109z40LdLDQGw2_WTcXU3Undz9SZDBfbVenSdy1NPADiyBM2NfqfSxobx5p0X5K_OmCqmo9lCcr3/s400/5.png&quot; align=&quot;middle&quot; /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Player &lt;em&gt;x&lt;/em&gt;&#39;s new rating &lt;em&gt;R&lt;sub&gt;x&lt;/sub&gt;&lt;/em&gt; is then calculated:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWlhmWPFJWvi6kPnzFyDSPF_3ILBLitQRgmnHNpJ9f_a9Cqcf-PBG7Z5rRpxLc2F74GOsKW4SEeTCsk6mMzZRp7XhA3nYMPrFHpOAqRDRAR9TAdV1htW6IW8hIBMljJNCZATly/s400/6.png&quot; align=&quot;middle&quot; /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Now we would like to generalize this system for &lt;em&gt;N&lt;/em&gt; number of players with ratings &lt;em&gt;R&lt;sub&gt;1&lt;/sub&gt;&lt;/em&gt;, &lt;em&gt;R&lt;sub&gt;2&lt;/sub&gt;&lt;/em&gt;, &lt;em&gt;...&lt;/em&gt;, &lt;em&gt;R&lt;sub&gt;N-1&lt;/sub&gt;&lt;/em&gt;, &lt;em&gt;R&lt;sub&gt;N&lt;/sub&gt;&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;We can make the observation that a game with greater than two players is nearly approximated by a set of games where every player is participating in a two-player game with every other opponent.&lt;br /&gt;&lt;br /&gt;The number of games this represents is expressed by:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRUf0a3d3MHau2ufFx1zTmhXJRMlUL1D7w5PSzZWcDjfoggzEJjzIev-aa8ozJs91E9971gxNNOb-6Eja7Sgx3l2MCknZWCCytL-GgIqXRSuoGfJtc27wOy0Oz5sFY_M80997x/s400/7.png&quot; align=&quot;middle&quot; /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The estimated score for a player &lt;em&gt;x&lt;/em&gt; &lt;em&gt;E&lt;sub&gt;x&lt;/sub&gt;&lt;/em&gt; can then be computed:&lt;p&gt;&lt;/p&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRA1aUASs7A5MJy3jTaI5EPL1r3CPV26R21mv79qh8nnlHQf5oJyJDLdDbLVzTETy7dkP9-PM-1QPWpkdtq5dYgrCbyZf6QkDmS5jguh3hGRkgwV0KLktp3adoZyYbsVfxYyC8/s400/18.png&quot; /&gt;&lt;br /&gt;&lt;/div&gt;Note that:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img style=&quot;cursor: pointer;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiedphfN_57WwmNh-aj_3PwWoYUPL48mqBvrQ-ez0JGjRsUZ6JXewO5cP2mhDik7iigOZ61OCCqPSaYFhPuXomucKmtldvcnDsUV5QXYCvMQWrnLucWNLOckdgBS_JAeTMrlfpZ/s400/13.png&quot; /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Now we would like a scoring function for the result of a game with more than two players.  In a game where each player is assigned a place &lt;em&gt;p&lt;/em&gt; (e.g. first, second, third) we might choose the following function:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilyqs2Ho3ZnTiHI2POyE9NdV2w1mwkkh1XFJ_pdEAYGfsxd9ZdzZDi-7Z9DLuF778XKyy40pQepNjBFPmLSnfYGdMYlnRUAaqkK5UaemDn5V1dm1m-RNf_RhApoc6tWI3ENoas/s320/14.png&quot; align=&quot;middle&quot; /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Note that:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPoHrTq93FGsNoingvWwXYF3N-srfBVGMhiYr8GnxipfTEPsFvd2Xtc-TaIJnKiI0pXY5i1ZBn776ChaBZAmo7llWx1DfmWqgXXZbdsclTqGqyNuWXVMwJT7jbTTqkDVSee6JG/s320/15.png&quot; align=&quot;middle&quot; /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Finally, every player&#39;s actual score is compared to his estimated score and the ratings updated using equation described earlier.&lt;br /&gt;&lt;br /&gt;There are two terms &lt;em&gt;D&lt;/em&gt; and &lt;em&gt;K&lt;/em&gt; that are in the equations above but they have not been explained yet.&lt;br /&gt;&lt;br /&gt;The &lt;em&gt;D&lt;/em&gt; term is a number that roughly represents the weight given to a player&#39;s rating when determining their estimated score.  The superiority of a player over another represented by his superior rating will mean less for higher values for &lt;em&gt;D&lt;/em&gt;.  That is to say that for higher values of &lt;em&gt;D&lt;/em&gt;, the fact that one player has a much higher rating an another is less significant in estimating the outcome of a game.  In games where luck more influences the outcome of a game than does skill, a higher value of K is more appropriate.&lt;br /&gt;&lt;br /&gt;The &lt;em&gt;K&lt;/em&gt; term is a factor that scales the magnitude of the change to a player&#39;s rating after a given game.  A player&#39;s rating after a game will change more for higher values of &lt;em&gt;K&lt;/em&gt;.  Generally, the value of &lt;em&gt;K&lt;/em&gt; should be higher when a player&#39;s rating is less certain.  This may be because the player has not participated in many games.  As players play more games and their rating becomes more representative of their skill level, the value of &lt;em&gt;K&lt;/em&gt; should be reduced.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/2590509468871926489/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/2590509468871926489' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/2590509468871926489'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/2590509468871926489'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2008/06/elo-rating-system-multiple-players.html' title='Generalizing the ELO Rating System for Multiple Players'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEjmQ7APRWLQAW5JnnmXQrAdC7VTOLWRGzniRCLvqZtJ00hEDdOLE5GOX6HJ0-g4HoZ6htV74LXV2QhyphenhyphenypX6jNWDqfi7GCKQUCBhyphenhyphenJToqKMXcs1PUgInIEuJTL5O2RNbV85Boh/s72-c/1.png" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-471350827264171989</id><published>2008-05-13T17:33:00.003-05:00</published><updated>2008-05-13T17:44:36.811-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="castle"/><category scheme="http://www.blogger.com/atom/ns#" term="monorail"/><title type='text'>Registering MonoRail Extensions Programatically</title><content type='html'>Hammett inspired me to switch from XML configuration to programmatic configuration of MonoRail with this &lt;a href=&quot;http://hammett.castleproject.org/?p=286&quot;&gt;blog post&lt;/a&gt;.  But he didn&#39;t discuss how to configure MonoRail extensions.  I searched around through the source and came up with this solution:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Configure(&lt;span style=&quot;color: #2b91af;&quot;&gt;IMonoRailConfiguration&lt;/span&gt; configuration)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; configuration.ViewEngineConfig.ViewPathRoot = &lt;span style=&quot;color: #2b91af;&quot;&gt;Path&lt;/span&gt;.Combine(&lt;span style=&quot;color: #2b91af;&quot;&gt;AppDomain&lt;/span&gt;.CurrentDomain.BaseDirectory, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Views&quot;&lt;/span&gt;);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; configuration.ViewEngineConfig.ViewEngines.Add(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;ViewEngineInfo&lt;/span&gt;(&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;NVelocityViewEngine&lt;/span&gt;), &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;));&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; configuration.ConfigurationSection = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;MutableConfiguration&lt;/span&gt;(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;monorail&quot;&lt;/span&gt;);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; configuration.ConfigurationSection.Children.Add(&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;MutableConfiguration&lt;/span&gt;(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;exception&quot;&lt;/span&gt;)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .CreateChild(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;exceptionHandler&quot;&lt;/span&gt;)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Attribute(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;type&quot;&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;EmailHandler&lt;/span&gt;).AssemblyQualifiedName)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Attribute(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;mailTo&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;to@email.com&quot;&lt;/span&gt;)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Attribute(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;mailFrom&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;from@email.com&quot;&lt;/span&gt;));&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; configuration.ExtensionEntries.Add(&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;ExtensionEntry&lt;/span&gt;(&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;ExceptionChainingExtension&lt;/span&gt;), &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;MutableConfiguration&lt;/span&gt;(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;&quot;&lt;/span&gt;)));&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This code sets up the EmailHandler that comes with MonoRail.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/471350827264171989/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/471350827264171989' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/471350827264171989'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/471350827264171989'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2008/05/registering-monorail-extensions.html' title='Registering MonoRail Extensions Programatically'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-993882126956947253</id><published>2007-11-19T03:40:00.000-06:00</published><updated>2007-11-19T03:50:56.226-06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="sql"/><category scheme="http://www.blogger.com/atom/ns#" term="sql server"/><title type='text'>Comparing Production and Development Schemas</title><content type='html'>A common task I that I perform is updating a staging or production SQL server with the changes I&#39;ve made to my local development database.   The way I do it is fairly basic but it works quite well in practice.&lt;br /&gt;&lt;br /&gt;I know this works with SQL Server 2005, but I think it should also work with SQL Server 2000.  The idea should work on almost any database system that allows you to query for table and column metadata.&lt;br /&gt;&lt;br /&gt;Here&#39;s the query I run on the databases:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;table_name, column_name&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;FROM &lt;/span&gt;information_schema.columns&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;WHERE &lt;/span&gt;table_name &lt;span style=&quot;color: blue;&quot;&gt;IN&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;(&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;table_name&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;FROM &lt;/span&gt;information_schema.tables&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;WHERE &lt;/span&gt;table_type = &lt;span style=&quot;color: #a31515;&quot;&gt;&#39;BASE TABLE&#39;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;ORDER BY &lt;/span&gt;table_name, column_name&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;Then, I just take both outputs of this query and stick them into &lt;a href=&quot;http://winmerge.org/&quot;&gt;WinMerge&lt;/a&gt; to get a schema comparison.  I then proceed to update the staging or production database by hand, as is often necessary.&lt;br /&gt;&lt;br /&gt;Take note that this query will only return columns that are in base tables, as you probably noticed by taking a look at the where clause.  If you want to include the columns of views, just take out the where clause like so:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;table_name, column_name&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;FROM &lt;/span&gt;information_schema.columns&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;ORDER BY &lt;/span&gt;table_name, column_name&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/993882126956947253/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/993882126956947253' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/993882126956947253'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/993882126956947253'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/11/comparing-production-development.html' title='Comparing Production and Development Schemas'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-5040592235980654235</id><published>2007-10-18T15:45:00.001-05:00</published><updated>2007-10-18T15:50:21.705-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="castle"/><category scheme="http://www.blogger.com/atom/ns#" term="monorail"/><title type='text'>MonoRail Routing Upgrade Coming</title><content type='html'>I just did an update from the Castle repository, and look what I found:&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvFojPgJ7t8vMPpxOzt385t6fJZSoo2OS_0o8EvnfQ6rlh009br65zNQttabDByNt7iSjewBfnDksF7Hxecp43u37X5Fg5mw8gwYzUs8QEIeH6KZCgQKKPSAnUx9hXcWU3J-eB/s400/routing.jpg&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5122781432266228322&quot; /&gt;&lt;br /&gt;Looks like we may be seeing improved routing capabilities in MonoRail soon.  Isn&#39;t open source grand?</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/5040592235980654235/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/5040592235980654235' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/5040592235980654235'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/5040592235980654235'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/10/monorail-routing-upgrade-coming.html' title='MonoRail Routing Upgrade Coming'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvFojPgJ7t8vMPpxOzt385t6fJZSoo2OS_0o8EvnfQ6rlh009br65zNQttabDByNt7iSjewBfnDksF7Hxecp43u37X5Fg5mw8gwYzUs8QEIeH6KZCgQKKPSAnUx9hXcWU3J-eB/s72-c/routing.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-1910153388555715532</id><published>2007-10-17T15:08:00.000-05:00</published><updated>2007-10-17T15:35:08.297-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="castle"/><category scheme="http://www.blogger.com/atom/ns#" term="monorail"/><category scheme="http://www.blogger.com/atom/ns#" term="mvc"/><title type='text'>Castle MonoRail vs Microsoft MVC</title><content type='html'>Everyone seems to be chiming in on the newly announced &lt;a href=&quot;http://www.google.com/url?sa=t&amp;ct=res&amp;cd=3&amp;url=http%3A%2F%2Fwww.hanselman.com%2Fblog%2FScottGuMVCPresentationAndScottHaScreencastFromALTNETConference.aspx&amp;ei=SnEWR736EYjGigH5u8T7Bg&amp;usg=AFQjCNHvdHSxzoU9PTZYw-6xXqRXZedFuQ&amp;sig2=GN3XGtiOtUsBdeD8VkzzpA&quot;&gt;MVC framework&lt;/a&gt; from Microsoft.  A lot of the posts seem to be very positive.&lt;br /&gt;&lt;br /&gt;The most talked about features seem to be:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt; &lt;li&gt;Routing&lt;/li&gt;&lt;br /&gt; &lt;li&gt;Mockable IHttpRequest/IHttpResponse&lt;/li&gt;&lt;br /&gt; &lt;li&gt;Type-checked views&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;The routing feature seems pretty nice, but how far is MonoRail from having this feature?  I think that MonoRail is missing this feature mainly because it wasn&#39;t developed in the era of IIS6.&lt;br /&gt;&lt;br /&gt;IIS7 as I understand it gives the web application access to the web request earlier than IIS6, which gives it more control over the routing capabilities.  Currently, IIS6 is not really well suited to be able to handle routing requests when there&#39;s no file extension on the URL.  I imagine that this feature could be added fairly quickly once there&#39;s more motivation and more adoption of IIS7.&lt;br /&gt;&lt;br /&gt;The mockability of IHttpRequest and IHttpResponse is a pretty nice feature as well, but couldn&#39;t MonoRail do this?  Scott Guthrie said that they didn&#39;t change ASP.NET at all to get this feature.&lt;br /&gt;&lt;br /&gt;Couldn&#39;t MonoRail wrap the standard HttpResonse and HttpRequest objects with adapters that implement a similar interface?  The major hurdle with this seems to be that this wasn&#39;t done in the first place, and there&#39;s a lot of code out there that would have to change to use the new interfaces.&lt;br /&gt;&lt;br /&gt;I have to admit that type-checked views sound enticing.  It would be pretty cool to have refactoring operations automatically change things in the views.&lt;br /&gt;&lt;br /&gt;But I&#39;ve lived in a compiled view world and I really don&#39;t want to go back.  If I have to recompile my project because I changed something in the view I would be pretty annoyed.  It&#39;s already a huge annoyance to have to wait for the AppDomain to reload when I change something in a controller.  I really don&#39;t want to wait for it to reload when I change a view as well.&lt;br /&gt;&lt;br /&gt;I remember back in my Java/Struts days, I welcomed a switch in our project to Velocity over JSP files.  There was a huge increase in productivity and I really didn&#39;t miss the type checking at all.&lt;br /&gt;&lt;br /&gt;I love being able to submit a patch or jump on the Castle mailinglist to discuss a quick change that would help my own project and have the change implemented within hours or days.  Wouldn&#39;t you lose that ability if you switched to Microsoft&#39;s MVC?&lt;br /&gt;&lt;br /&gt;I guess that&#39;s a standard issue when deciding between open source and commercial frameworks.  I&#39;m really not ready to give that up, and I think that&#39;s one of the main reasons I&#39;ll be sticking with MonoRail as long as the project remains as active as it is.&lt;br /&gt;&lt;br /&gt;Overall, I am pleased with the announcement.  It seems that Microsoft is watching what is going on the community and trying to deliver a better platform for developing web applications.&lt;br /&gt;&lt;br /&gt;My main point is that MonoRail is already a great platform that&#39;s in use by many, it&#39;s actively developed, and I&#39;d be surprised if this new platform from Microsoft doesn&#39;t push it to greater heights.  As always though, I&#39;ll be keeping an open mind as things unfold.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/1910153388555715532/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/1910153388555715532' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/1910153388555715532'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/1910153388555715532'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/10/castle-monorail-vs-microsoft-mvc.html' title='Castle MonoRail vs Microsoft MVC'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-3615504582660588192</id><published>2007-10-08T05:41:00.000-05:00</published><updated>2007-10-08T16:36:15.869-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="csharp"/><title type='text'>Unexceptional Dictionary Accesses in C#</title><content type='html'>Take a look at this:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; dictionary = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; dictionary[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Hello&quot;&lt;/span&gt;] = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;World!&quot;&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(dictionary[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Hello&quot;&lt;/span&gt;]);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(dictionary[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Goodbye&quot;&lt;/span&gt;]);&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;What&#39;s the output of this code?  You might think that you&#39;d get the word &quot;World!&quot; followed by a blank line, but that&#39;s wrong.  You get this big hairy exception:&lt;br /&gt;&lt;span style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;br /&gt;System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.&lt;br /&gt;at System.ThrowHelper.ThrowKeyNotFoundException()&lt;br /&gt;at System.Collections.Generic.Dictionary`2.get_Item(TKey key)&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;I don&#39;t really like that exception at all.  I find that it&#39;s usually quite &lt;em&gt;un&lt;/em&gt;exceptional for something to be missing from a dictionary.  You might think it would be nice to get a null back instead of getting an exception.  I might agree with you.  OK, but maybe they had a reason for making the dictionary behave this way.  Think about this situation:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&amp;gt; dictionary = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&amp;gt;();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; dictionary[1] = 2;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(dictionary[1]);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(dictionary[2]);&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;Now, what do you think?  Still want a null back?  Integers aren&#39;t reference types, and you should never be getting null when something is supposed to return an integer.  You might think that could just return default(T) but in this case the return value would be zero.  But, zero is a perfectly valid number so it probably would have been a bad design decision to have the dictionary return default(T).  So we&#39;re left with this exception.&lt;br /&gt;&lt;br /&gt;You might attempt to fix this by guarding all your dictionary accesses with ContainsKey() checks like so:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; dictionary = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; dictionary[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Hello&quot;&lt;/span&gt;] = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;World!&quot;&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (dictionary.ContainsKey(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Hello&quot;&lt;/span&gt;))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(dictionary[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Hello&quot;&lt;/span&gt;]);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (dictionary.ContainsKey(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Goodbye&quot;&lt;/span&gt;))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(dictionary[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Goodbye&quot;&lt;/span&gt;]);&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;There&#39;s a few of problems with this approach, however.  First of all, it looks ugly, and it&#39;s really verbose.  What if you&#39;re retrieving a large number of values from this dictionary?  All those ifs get really tedious, and there&#39;s more potential for error when you&#39;re providing the key twice to the dictionary.  Also, there&#39;s a potential race condition here.  What if another thread removes the key from the dictionary the instant after you confirm that it is in fact in the dictionary, and then try to retrieve the value for the key?  You&#39;re going to get an exception.  And yet another problem is that this solution is inefficent.  The dictionary has having to perform the work to lookup the key twice instead of just once.&lt;br /&gt;&lt;br /&gt;So if you can&#39;t guard the dictionary access with an if, how can you safely determine if a key is in a dictionary and retrieve its value while avoiding a race condition?  Well, they thought of that.  That&#39;s why they created TryGetValue(), which basically works like this:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; dictionary = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; dictionary[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Hello&quot;&lt;/span&gt;] = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;World!&quot;&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; value;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (dictionary.TryGetValue(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Hello&quot;&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;out&lt;/span&gt; value))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Dictionary has the key!&quot;&lt;/span&gt;);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;The value is &quot;&lt;/span&gt; + value);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Dictionary doesn&#39;t have the key!&quot;&lt;/span&gt;);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;So this solves that latter two problems of the three problems I mentioned above about the guard clauses, but it really exacerbates the first problem of verbosity.  So how can we fix this?  What if you &lt;em&gt;really&lt;/em&gt; just want to get an null back if the key was missing from the dictionary?  As mentioned before, you&#39;d only want to do this if your value type was a reference type.  How would you get about it?  You could create a helper function like this:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; GetValueSafelyFromDictionary(&lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; dictionary, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; key)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; value;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (dictionary.TryGetValue(key, &lt;span style=&quot;color: blue;&quot;&gt;out&lt;/span&gt; value))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; value;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;Or more generally:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; TValue GetValueSafelyFromDictionary&amp;lt;TKey, TValue&amp;gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;TKey, TValue&amp;gt; dictionary, TKey key) &lt;span style=&quot;color: blue;&quot;&gt;where&lt;/span&gt; TValue : &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TValue value;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (dictionary.TryGetValue(key, &lt;span style=&quot;color: blue;&quot;&gt;out&lt;/span&gt; value))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; value;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;So this could definitely helps cut down on the verbosity, especially if the value from dictionary is supposed to go into the property of another reference type instead of some variable on the stack.  But it&#39;s quite annoying to have to keep passing the dictionary, so let&#39;s make this better:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;DictionaryValueGetter&lt;/span&gt;&amp;lt;TKey, TValue&amp;gt; &lt;span style=&quot;color: blue;&quot;&gt;where&lt;/span&gt; TValue : &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;readonly&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;IDictionary&lt;/span&gt;&amp;lt;TKey, TValue&amp;gt; _dictonary;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; DictionaryValueGetter(&lt;span style=&quot;color: #2b91af;&quot;&gt;IDictionary&lt;/span&gt;&amp;lt;TKey, TValue&amp;gt; dictonary)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _dictonary = dictonary;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; TValue &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;[TKey key]&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TValue value;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (!_dictonary.TryGetValue(key, &lt;span style=&quot;color: blue;&quot;&gt;out&lt;/span&gt; value))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; value;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;OK, this is a lot better.  Take a look:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; dictionary = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; dictionary[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Hello&quot;&lt;/span&gt;] = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;World!&quot;&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;DictionaryValueGetter&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; valueGetter = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;DictionaryValueGetter&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;(dictionary);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(valueGetter[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Hello&quot;&lt;/span&gt;]);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(valueGetter[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Goodbye&quot;&lt;/span&gt;]);&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;And this will work with any dictionary where your &quot;value&quot; type is a reference type, which is perfect because that&#39;s the only time this solution makes any sense.  We could have gone further than this solution and provided a full implementation of IDictionary that provided all of this behavior, but I think that was a bit too much work for my simple use case.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/3615504582660588192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/3615504582660588192' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/3615504582660588192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/3615504582660588192'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/10/dictionary-returns-null-instead.html' title='Unexceptional Dictionary Accesses in C#'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-1928007661861461080</id><published>2007-09-28T00:07:00.000-05:00</published><updated>2007-09-28T01:20:37.322-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="activerecord"/><category scheme="http://www.blogger.com/atom/ns#" term="nhibernate"/><title type='text'>Improving Performance of ActiveRecord and NHibernate for Large Queries</title><content type='html'>First off, let me say that in general I think that &lt;a href=&quot;http://www.nhibernate.org/&quot;&gt;NHibernate&lt;/a&gt; is fast enough for most use cases.  And as always, save optimizations for last and use a profiling tool to tell what actually is taking up the most time instead of guessing what you think is taking up the most time.&lt;br /&gt;&lt;br /&gt;With that said, there are occasions when you need to put a little extra thought into improving performance.  A web application I&#39;m working executes a database query that can return thousands of rows.  I really wasn&#39;t pleased with the performance of the application for this use case.  It took a longer than I wanted it to take, especially given that this query is run frequently by the application&#39;s users.  I ran the NHibernate-emitted SQL query inside of SQL Server Management Studio, and the query returned nearly instantly, so that got me thinking.&lt;br /&gt;&lt;br /&gt;I busted out the profiler.  I&#39;m using JetBrain&#39;s &lt;a href=&quot;http://www.jetbrains.com/profiler/&quot;&gt;dotTrace&lt;/a&gt; profiling tool for .NET, which is a great tool.  I loaded up my application to the view where I kick off this large query, turned on the profiling, and then let it run.  Here are the results:&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://farm2.static.flickr.com/1255/1450806873_836b35228c_o_d.jpg&quot;/&gt;&lt;br /&gt;&lt;br /&gt;NHibernate is spending a lot of time determining whether or not it needs to flush changes to the results of my query to the database.  In this specific use case however, no modifications will be made to these entities, so this check is just a waste of resources.  It took this much time not to actually update the database with anything, but rather just to see if it should being doing any updates.&lt;br /&gt;&lt;br /&gt;For those that don&#39;t know, NHibernate follows the unit of work pattern.  All changes made to objects are not immediately flushed to the database (via INSERTs and UPDATEs.)  Instead, NHibernate patiently waits for you to tell it that your session is over (or manually tell it to flush) before it starts updating the database.&lt;br /&gt;&lt;br /&gt;There are a couple of ways to stop NHibernate from spending this much time on the flush.  You can either evict all the objects that you don&#39;t want checked for a flush from the session, or you can just tell the session not to flush when closed.  The latter option will not work if you actually make modifications to some other objects while using the same session, but I&#39;m not making any changes to these objects, so that&#39;s fine with me.  If you&#39;re using &lt;a href=&quot;http://www.castleproject.org/activerecord/index.html&quot;&gt;Castle ActiveRecord&lt;/a&gt; like I am, you can add an argument when you create the SessionScope surrounding your query to turn off flushing:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SessionScope&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;FlushAction&lt;/span&gt;.Never))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;// Large query inside here&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;Normally, the SessionScope is initialized with FlushAction.Auto, which causes NHibernate to perform the flush check at the end of a session.&lt;br /&gt;&lt;br /&gt;As I said before, another option is to evict the objects that came from the query out of the session.  In NHibernate, you can use the ISession.Evict() method to perform this action.  Since I&#39;m using ActiveRecord, I shy away from dealing with NHibernate directly whenever possible, so that is yet another reason I chose not to go this route.&lt;br /&gt;&lt;br /&gt;Now that we&#39;ve told NHibernate not to flush anything, and therefore not to check for something to flush, the performance has increased.  Take a look:&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://farm2.static.flickr.com/1099/1451664578_e9fc5f5122_o_d.jpg&quot;/&gt;&lt;br /&gt;&lt;br /&gt;After I made my changes, NHibernate did not perform any flushes during this request.&lt;br /&gt;&lt;br /&gt;NHiberate and ActiveRecord are great tools and they make tedious data-driven tasks simple and easy, but it helps to know a little bit about what&#39;s going on under the hood.  The takeaway from this is that you should look for opportunies to avoid triggering NHibernate&#39;s flush mechanism if you know an operation is read-only, especially when you&#39;re dealing with lots of entities in the session.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/1928007661861461080/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/1928007661861461080' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/1928007661861461080'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/1928007661861461080'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/09/improving-performance-of-activerecord.html' title='Improving Performance of ActiveRecord and NHibernate for Large Queries'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-8105856347990728522</id><published>2007-09-22T18:00:00.000-05:00</published><updated>2007-10-08T06:48:40.807-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="csharp"/><title type='text'>Elegantly Retry Code If There&#39;s an Error</title><content type='html'>Sometimes you want to try to retry code if there&#39;s an error.  The most applicable situation for this might be when a database is busy or when the network is slow.  Here&#39;s some sample code:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; RetryFiveTimes()&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; count = 0; count &amp;lt; 5; count++)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CodeThatCouldThrowAnError();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;break&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;Exception&lt;/span&gt;)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This seems like a decent first attempt solution, until you find yourself doing this in multiple places.  Plus I just don&#39;t like the way this looks at all.  Let&#39;s try a different approach:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; RetryFiveTimes()&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt;.Times(5).Do(&lt;span style=&quot;color: blue;&quot;&gt;delegate&lt;/span&gt; { CodeThatCouldThrowAnError(); });&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;OK, now I&#39;m happier.  Let&#39;s take a look at the Retry class:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;delegate&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;RetryMethod&lt;/span&gt;();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; _times;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt; Times(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; times)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt; retry = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt;();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; retry._times = times;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; retry;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Do(&lt;span style=&quot;color: #2b91af;&quot;&gt;RetryMethod&lt;/span&gt; method)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; count = 0; count &amp;lt; _times; count++)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; method();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;break&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;Exception&lt;/span&gt;)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This Retry class could probably benefit from some improvements.  The first thing that comes into my head is the ability to retry for specific exceptions.  So let&#39;s improve this code a bit:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;delegate&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;RetryMethod&lt;/span&gt;();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Type&lt;/span&gt; _type = &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; _times;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt; Times(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; times)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt; retry = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt;();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; retry._times = times;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; retry;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt; When&amp;lt;T&amp;gt;() &lt;span style=&quot;color: blue;&quot;&gt;where&lt;/span&gt; T : &lt;span style=&quot;color: #2b91af;&quot;&gt;Exception&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _type = &lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(T);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Do(&lt;span style=&quot;color: #2b91af;&quot;&gt;RetryMethod&lt;/span&gt; method)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; count = 0; count &amp;lt; _times; count++)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; method();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;break&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;Exception&lt;/span&gt; e)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (_type != &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; !_type.IsAssignableFrom(e.GetType()))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;throw&lt;/span&gt; e;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Cool, now we can do this:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; RetryFiveTimesWhenTheresATimeoutException()&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt;.Times(5)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .When&amp;lt;&lt;span style=&quot;color: #2b91af;&quot;&gt;TimeoutException&lt;/span&gt;&amp;gt;()&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Do(&lt;span style=&quot;color: blue;&quot;&gt;delegate&lt;/span&gt; { CodeThatCouldThrowAnError(); });&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Of course, we don&#39;t always have nice exceptions where the type indicates that it was a timeout error.  What if the message of the exception contained the information we needed?  We could probably add further facilities for the user to inspect the exception and provide feedback as to whether we should continue.  Let&#39;s try this:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Predicate&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #2b91af;&quot;&gt;Exception&lt;/span&gt;&amp;gt; _shouldRetry;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Type&lt;/span&gt; _type = &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; _times;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; Retry()&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _shouldRetry = DefaultShouldRetry;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt; Times(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; times)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt; retry = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt;();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; retry._times = times;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; retry;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt; When&amp;lt;T&amp;gt;() &lt;span style=&quot;color: blue;&quot;&gt;where&lt;/span&gt; T : &lt;span style=&quot;color: #2b91af;&quot;&gt;Exception&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _type = &lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(T);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt; If(&lt;span style=&quot;color: #2b91af;&quot;&gt;Predicate&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #2b91af;&quot;&gt;Exception&lt;/span&gt;&amp;gt; predicate)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _shouldRetry = predicate;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt; DefaultShouldRetry(&lt;span style=&quot;color: #2b91af;&quot;&gt;Exception&lt;/span&gt; e)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (_type == &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (!_type.IsAssignableFrom(e.GetType()))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Do(&lt;span style=&quot;color: #2b91af;&quot;&gt;RetryMethod&lt;/span&gt; method)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; count = 0; count &amp;lt; _times; count++)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; method();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;break&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;Exception&lt;/span&gt; e)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (!_shouldRetry(e))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;throw&lt;/span&gt; e;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Great, now we can do this type of thing:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; RetryFiveTimesWhenTheresAnExceptionWithTimeoutInItsMessage()&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Retry&lt;/span&gt;.Times(5)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .If(&lt;span style=&quot;color: blue;&quot;&gt;delegate&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;Exception&lt;/span&gt; e) { &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; e.Message.Contains(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Timeout&quot;&lt;/span&gt;); })&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; .Do(&lt;span style=&quot;color: blue;&quot;&gt;delegate&lt;/span&gt; { CodeThatCouldThrowAnError(); });&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;OK, that&#39;s good enough for now.  We could continue with this forever, but this solution seems pretty flexible.  I think this is a pretty good example of a fluent interface as well.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/8105856347990728522/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/8105856347990728522' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/8105856347990728522'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/8105856347990728522'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/09/elegantly-retry-code-if-theres-error.html' title='Elegantly Retry Code If There&#39;s an Error'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-8575798683755044391</id><published>2007-09-18T21:34:00.000-05:00</published><updated>2007-09-18T21:45:39.503-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="log4net"/><title type='text'>Have Log4Net Send an Email When an Error Occurs</title><content type='html'>Instead of building up your own error notification system and injecting an email sender, you can easily have &lt;a href=&quot;http://logging.apache.org/log4net/&quot;&gt;Log4Net&lt;/a&gt; send you an email when you want to be notified of something.&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; DoSomethingImportant()&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; InternalDoSomethingImportant();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;Exception&lt;/span&gt; e)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _logger.Error(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;A serious error occured.&quot;&lt;/span&gt;, e);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Now, instead of passing in an IEmailSender here and calling SendMessage(), try setting this up in your Log4Net configuration:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;?&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;xml&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;1.0&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;encoding&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;utf-8&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; ?&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;log4net&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;appender&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;SmtpAppender&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;log4net.Appender.SmtpAppender&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;threshold&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;WARN&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;to@emailaddress.com&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;from@emailaddress.com&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;subject&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;SmtpAppender&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;smtpHost&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;SmtpHost&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;bufferSize&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;512&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;lossy&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;layout&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;log4net.Layout.PatternLayout&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;conversionPattern&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;layout&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;appender&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;root&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;level&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;ERROR&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;root&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;log4net&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Of course, you probably will have more configuration than this, but this is the bare minimum if you want to be emailed of errors. Don&#39;t forget about the FATAL log level as well. You could very easily change the level of the message that you wanted to be notified of via email.&lt;br /&gt;&lt;br /&gt;I&#39;ve set the appender threshold of the SmtpAppender here to WARN. You can make sure that you don&#39;t get any emails of lower priority using this setting in more advanced Log4Net configurations.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/8575798683755044391/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/8575798683755044391' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/8575798683755044391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/8575798683755044391'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/09/have-log4net-send-email-when-error.html' title='Have Log4Net Send an Email When an Error Occurs'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-7141431101447172344</id><published>2007-09-17T20:45:00.000-05:00</published><updated>2007-09-17T20:57:40.799-05:00</updated><title type='text'>Five Essential Development Tools</title><content type='html'>&lt;ol&gt;&lt;li&gt;&lt;a href=&quot;http://www.jetbrains.com/resharper&quot;&gt;Resharper&lt;/a&gt; - Make quick work of refactoring and code generation with this addon to Visual Studio.  It costs a bit of money but it&#39;s well worth the price.  I won&#39;t use Visual Studio without this addon.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://tortoisesvn.tigris.org&quot;&gt;TortoiseSVN&lt;/a&gt; - You should be using source control.  This subversion interface makes managing your working copy of your code easy and painless.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.winmerge.org&quot;&gt;WinMerge&lt;/a&gt; - This is best free diff tool that I have found for Windows.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.flos-freeware.ch/notepad2.html&quot;&gt;Notepad2&lt;/a&gt; - This free text editor is much better than the Notepad application that comes with windows.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.getpaint.net&quot;&gt;Paint.NET&lt;/a&gt; - Every programmer at some point has to engage in some minor graphics manipulation.  I mainly use this to change image formats and crop images.&lt;/li&gt;&lt;/ol&gt;</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/7141431101447172344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/7141431101447172344' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/7141431101447172344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/7141431101447172344'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/09/five-essential-development-tools.html' title='Five Essential Development Tools'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-7976017296210224206</id><published>2007-07-31T11:56:00.001-05:00</published><updated>2007-07-31T12:00:22.924-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="activerecord"/><category scheme="http://www.blogger.com/atom/ns#" term="nhibernate"/><category scheme="http://www.blogger.com/atom/ns#" term="sql server"/><title type='text'>Enable MARS on your NHibernate connection if you have SQL Server 2005</title><content type='html'>If you don&#39;t enable MARS, you&#39;ll get exceptions like these every now and then under high load:&lt;br /&gt;&lt;br /&gt;Exception: &lt;strong&gt;There is already an open DataReader associated with this Command which must be closed first.&lt;/strong&gt;&lt;br /&gt;Stack Trace:&lt;br /&gt;at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)&lt;br /&gt;at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)&lt;br /&gt;at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)&lt;br /&gt;at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)&lt;br /&gt;at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)&lt;br /&gt;at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)&lt;br /&gt;at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)&lt;br /&gt;at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()&lt;br /&gt;at NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd)&lt;br /&gt;at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session)&lt;br /&gt;at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)&lt;br /&gt;at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)&lt;br /&gt;at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type)&lt;br /&gt;&lt;br /&gt;To enable MARS, just add this on to our connection string:&lt;br /&gt;&lt;br /&gt;MultipleActiveResultSets=true</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/7976017296210224206/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/7976017296210224206' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/7976017296210224206'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/7976017296210224206'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/07/enable-mars-on-your-nhibernate.html' title='Enable MARS on your NHibernate connection if you have SQL Server 2005'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-4598233535882175888</id><published>2007-07-10T05:29:00.001-05:00</published><updated>2007-07-10T05:33:44.374-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="monorail"/><title type='text'>MonoRail Exception Chaining</title><content type='html'>MonoRail comes with a nice exception handling mechanism.  It&#39;s pretty well &lt;a href=&quot;http://wiki.castleproject.org/index.php/MonoRail:Extensions:Exception_Chaining&quot;&gt;documented &lt;/a&gt; so I won&#39;t explain how it works.&lt;br /&gt;&lt;br /&gt;MonoRail also provides an handler that sends an email with exception and request details.  I got tired of getting this email in my development environment, so here&#39;s what I came up with:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;ExceptionFilterHandler&lt;/span&gt; : &lt;span style=&quot;color: #2b91af;&quot;&gt;AbstractExceptionHandler&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;override&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Process(&lt;span style=&quot;color: #2b91af;&quot;&gt;IRailsEngineContext&lt;/span&gt; context)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (context.Request.IsLocal)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; InvokeNext(context);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Pretty simple and it does the trick.  This also gives you the ability login to the server in production if you have access and see the exception detail in the browser instead of getting an email.  It checks to see the web request was made from the local machine.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/4598233535882175888/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/4598233535882175888' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/4598233535882175888'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/4598233535882175888'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/07/monorail-exception-chaining.html' title='MonoRail Exception Chaining'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-7333238532962164387</id><published>2007-07-10T05:19:00.001-05:00</published><updated>2007-07-10T05:23:44.996-05:00</updated><title type='text'>Disregard the previous post</title><content type='html'>For some reason, the code I posted below doesn&#39;t work anymore.  I don&#39;t have the time to see what changed.  Hopefully soon I&#39;ll get a chance to revisit it and see what happened to MicroKernel that made the code stop working.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/7333238532962164387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/7333238532962164387' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/7333238532962164387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/7333238532962164387'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/07/disregard-previous-post.html' title='Disregard the previous post'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-628317062833129385</id><published>2007-05-09T13:37:00.000-05:00</published><updated>2007-05-09T17:38:34.284-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="castle"/><category scheme="http://www.blogger.com/atom/ns#" term="ioc"/><category scheme="http://www.blogger.com/atom/ns#" term="microkernel"/><category scheme="http://www.blogger.com/atom/ns#" term="windsor"/><title type='text'>Exploring Castle Windsor/MicroKernel Auto-wiring</title><content type='html'>&lt;a href=&quot;http://www.castleproject.org&quot;&gt;Castle Windsor/MicroKernel&lt;/a&gt; is a great tool for dependency injection.  For most applications, the auto-wiring features of MicroKernel will perfectly for the your situation out-of-the-box.  However, imagine a scenario where the dependencies of some components are services defined by an interface, while the dependencies of other components depend not on the interface, but rather on the specific implementation.  Let&#39;s explore how we can get MicroKernel to help us out.  So let&#39;s say we have this interface:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 9pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;interface&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;ISender&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; SendMessage(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; recipient, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; message);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;and we have a couple of implementations:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 9pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;EmailSender&lt;/span&gt; : &lt;span style=&quot;color: #2b91af;&quot;&gt;ISender&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; SendMessage(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; recipient, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; message)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;// ... send email message ...&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 9pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;InstantMessageSender&lt;/span&gt; : &lt;span style=&quot;color: #2b91af;&quot;&gt;ISender&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; SendMessage(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; recipient, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; message)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;// ... send instant message ...&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt; IsOnline(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; recipient)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;// ... check is user is online ...&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;Suppose we have a component that requires a set a &lt;code&gt;ISender&lt;/code&gt; services:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 9pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;AlertSystem&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;ISender&lt;/span&gt;[] _senders;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; AlertSystem(&lt;span style=&quot;color: #2b91af;&quot;&gt;ISender&lt;/span&gt;[] senders)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _senders = senders;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;ISender&lt;/span&gt;[] Senders&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt; { &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; _senders; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: gray;&quot;&gt;///&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt; ... implementation ...&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;OK, so far so good.  Wiring this up with Windsor is a piece of cake:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 9pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;?&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;xml&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;1.0&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;encoding&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;utf-8&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; ?&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;configuration&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;components&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;instant.message.sender&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;service&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.ISender, Eg&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageSender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;email.sender&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;service&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.ISender, Eg&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageSender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;alert.system&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.AlertSystem, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;parameters&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;senders&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.ISender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;${instant.message.sender}&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;${email.sender}&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;senders&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;parameters&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;components&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;configuration&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;But what if I have another component that requires a specific implementation of &lt;code&gt;ISender&lt;/code&gt; like this:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 9pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;InstantMessageComponent&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;InstantMessageSender&lt;/span&gt; _sender;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; InstantMessageComponent(&lt;span style=&quot;color: #2b91af;&quot;&gt;InstantMessageSender&lt;/span&gt; sender)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _sender = sender;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;InstantMessageSender&lt;/span&gt; Sender&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt; { &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; _sender; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;// ... implementation ...&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;How can we get this wired up?  Well, you might think just added the new component would work:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 9pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;?&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;xml&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;1.0&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;encoding&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;utf-8&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; ?&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;configuration&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;components&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;instant.message.sender&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;service&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.ISender, Eg&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageSender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;email.sender&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;service&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.ISender, Eg&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageSender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;alert.system&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.AlertSystem, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;parameters&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;senders&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.ISender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;${instant.message.sender}&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;${email.sender}&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;senders&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;parameters&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;instant.message.component&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageComponent, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;components&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;configuration&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;However, there is a slight problem with this.  MicroKernel will not auto-wire components that have a dependency of &lt;code&gt;InstantMessageSender&lt;/code&gt; because it is instead registered in the config for the service it provides, namely &lt;code&gt;ISender&lt;/code&gt;.  In this case, I can force the kernel to wire it up using the following configuration:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 9pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;?&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;xml&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;1.0&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;encoding&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;utf-8&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; ?&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;configuration&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;components&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;instant.message.sender&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;service&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.ISender, Eg&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageSender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;email.sender&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;service&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.ISender, Eg&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageSender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;alert.system&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.AlertSystem, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;parameters&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;senders&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.ISender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;${instant.message.sender}&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;${email.sender}&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;senders&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;parameters&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;instant.message.component&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageComponent, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;parameters&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;sender&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;${instant.message.sender}&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;sender&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;parameters&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;components&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;configuration&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;This works, but it&#39;s not autowired.  If you have a lot of this going on in your system, you&#39;ll find yourself taking on more and more of the responsibility of wiring your components, even though you originally wanted to leverage MicroKernel to handle much of this for you.  So let&#39;s say we want our configuration to look like the first configuration I presented.  Well, we&#39;re going to have to change the way MicroKernel registers services.  This concern is specifically handled via the NamingSubSystem.  We will do the job by extending MicroKernel&#39;s default &lt;code&gt;INamingSubSystem&lt;/code&gt; implementation, &lt;code&gt;DefaultNamingSubSystem&lt;/code&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 9pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;CustomNamingSubSystem&lt;/span&gt; : &lt;span style=&quot;color: #2b91af;&quot;&gt;DefaultNamingSubSystem&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;override&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Register(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; key, &lt;span style=&quot;color: #2b91af;&quot;&gt;IHandler&lt;/span&gt; handler)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Type&lt;/span&gt; implementation = handler.ComponentModel.Implementation;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (!service2Handler.Contains(implementation))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;[implementation] = handler;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;base&lt;/span&gt;.Register(key, handler);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;In this method, all we&#39;re doing is additionally adding the &lt;em&gt;implementation&lt;/em&gt; to resolvable services if it isn&#39;t already.  The &lt;code&gt;DefaultNamingSubsystem&lt;/code&gt; only adds the &lt;em&gt;service&lt;/em&gt; and not the &lt;em&gt;implementation&lt;/em&gt; except in cases where you don&#39;t specify a &lt;em&gt;service&lt;/em&gt;.  Also note that this method  should also take care of mapping the component &lt;em&gt;id&lt;/em&gt; to the proper component.  Here&#39;s the default implementation:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 9pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;virtual&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Register(&lt;span style=&quot;color: #2b91af;&quot;&gt;String&lt;/span&gt; key, IHandler handler)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Type&lt;/span&gt; service = handler.ComponentModel.Service;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (key2Handler.Contains(key))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ComponentRegistrationException(&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;String&lt;/span&gt;.Format(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;There is a component already registered for the given key {0}&quot;&lt;/span&gt;, key));&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (!service2Handler.Contains(service))&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;[service] = handler;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;[key] = handler;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;And here&#39;s how I got Windsor to use my new &lt;code&gt;DefaultNamingSubSystem&lt;/code&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 9pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;ApplicationContainer&lt;/span&gt; : &lt;span style=&quot;color: #2b91af;&quot;&gt;WindsorContainer&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; ApplicationContainer(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; xmlFile) : &lt;span style=&quot;color: blue;&quot;&gt;base&lt;/span&gt;(xmlFile)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;override&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; RunInstaller()&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Kernel.AddSubSystem(&lt;span style=&quot;color: #2b91af;&quot;&gt;SubSystemConstants&lt;/span&gt;.NamingKey, &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;CustomNamingSubSystem&lt;/span&gt;());&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;base&lt;/span&gt;.RunInstaller();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;By the way, we could have gotten this all wired up if we registered the implementations twice: once for the service it provides and another time for the implementation, like this:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 9pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;?&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;xml&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;1.0&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;encoding&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;utf-8&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt; ?&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;configuration&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;components&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;instant.message.sender.service&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;service&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.ISender, Eg&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageSender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;email.sender.service&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;service&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.ISender, Eg&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageSender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;alert.system&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.AlertSystem, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;parameters&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;senders&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.ISender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;${instant.message.sender}&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;${email.sender}&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;senders&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;parameters&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;instant.message.component&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageComponent, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;instant.message.sender&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageSender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;component&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;email.sender&lt;/span&gt;&quot;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;Eg.InstantMessageSender, Eg&lt;/span&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;components&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #a31515;&quot;&gt;configuration&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;I wouldn&#39;t recommend this approach though.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/628317062833129385/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/628317062833129385' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/628317062833129385'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/628317062833129385'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/05/exploring-castle-windsormicrokernel.html' title='Exploring Castle Windsor/MicroKernel Auto-wiring'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-7018710170304919228</id><published>2007-05-07T14:02:00.000-05:00</published><updated>2007-05-07T15:02:21.097-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="database"/><category scheme="http://www.blogger.com/atom/ns#" term="powershell"/><title type='text'>Compressing SQL Server Backups With Windows PowerShell and 7-zip</title><content type='html'>We run monthly full backups, daily differential backups, and transaction log backups every hour.  The backup drive fills up quickly.  So I decided that I wanted to compress all of the &lt;code&gt;.bak&lt;/code&gt; and &lt;code&gt;.trn&lt;/code&gt; files into their own &lt;code&gt;.7z&lt;/code&gt; files using &lt;a href=&quot;http://www.7-zip.org&quot;&gt;7-zip&lt;/a&gt;.  Doing something like this in a bash shell is trivial.  Windows PowerShell makes it trivial as well (as long as you have it &lt;a href=&quot;http://www.microsoft.com/technet/scriptcenter/topics/msh/download.mspx&quot;&gt;installed&lt;/a&gt;).  Here&#39;s what I did:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;get-childitem -recurse |&lt;br /&gt; where { $_.extension -match &quot;.(bak|trn)&quot; -and&lt;br /&gt;  -not (test-path ($_.fullname -replace &quot;(bak|trn)&quot;, &quot;7z&quot;)) } |&lt;br /&gt; foreach { F:\7za.exe a ($_.fullname -replace &quot;bak&quot;, &quot;7z&quot;) $_.fullname }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here&#39;s a breakdown of what&#39;s going on:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;get-childitem -recurse&lt;/code&gt;: Retreives all files recursively from the current directory&lt;br /&gt;&lt;br /&gt;&lt;code&gt;where { $_.extension -match &quot;.(bak|trn)&quot; -and -not (test-path ($_.fullname -replace &quot;(bak|trn)&quot;, &quot;7z&quot;))&lt;/code&gt;: Filters the filelist to only include files that end in &lt;code&gt;.bak&lt;/code&gt; and &lt;code&gt;.trn&lt;/code&gt; and also where there isn&#39;t already a file with the same name but with an extension of &lt;code&gt;.7z&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;foreach { F:\7za.exe a ($_.fullname -replace &quot;bak&quot;, &quot;7z&quot;) $_.fullname }&lt;/code&gt;: Run the &lt;code&gt;7za.exe&lt;/code&gt; command line utility to add the &lt;code&gt;.bak&lt;/code&gt; or &lt;code&gt;.trn&lt;/code&gt; into a &lt;code&gt;.7z&lt;/code&gt; file.&lt;br /&gt;&lt;br /&gt;After this command completed, I ran the following command to remove all of the original &lt;code&gt;.bak&lt;/code&gt; or &lt;code&gt;.trn&lt;/code&gt; files if they have a corresponding &lt;code&gt;.7z&lt;/code&gt; file:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;get-childitem -recurse |&lt;br /&gt; where { $_.extension -match &quot;.(bak|trn)&quot; -and&lt;br /&gt;  (test-path ($_.fullname -replace &quot;(bak|trn)&quot;, &quot;7z&quot;)) } |&lt;br /&gt; foreach { del $_.fullname }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;By the way, the 7-zip command line utility is good about deleting .7z files that were not properly created (e.g. you cancelled the compression before it finished.)</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/7018710170304919228/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/7018710170304919228' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/7018710170304919228'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/7018710170304919228'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/05/compressing-sql-server-backups-with.html' title='Compressing SQL Server Backups With Windows PowerShell and 7-zip'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-595050176712234659</id><published>2007-05-05T22:00:00.000-05:00</published><updated>2007-05-05T22:10:10.522-05:00</updated><title type='text'>Finding Good Developers</title><content type='html'>I will very soon have the need to find qualified software developers for an upcoming large project.  I&#39;ve tried to hire software developers before, but I think I must be going about this the wrong way.  &lt;br /&gt;&lt;br /&gt;I&#39;ve tried the Monster approach, but I mainly got a group of unqualified developers that didn&#39;t have command of what I specifically stated as a requirement for the job.  For example, if I put that knowing SQL is a requirement, I expect you to know at a minimum how to write SELECT, INSERT, UPDATE, etc. statements without having to Google it.  It was surprising how many of the candidates failed to meet this requirement.&lt;br /&gt;&lt;br /&gt;In addition, I received a bunch of emails from staffing agencies that wanted to charge us 2x-3x the amount that the developer they were pitching was going to end up making.  The facts that I know we&#39;re overpaying and that I&#39;ve had a very bad experience with these staffed developers in the past really make me want to avoid this route.&lt;br /&gt;&lt;br /&gt;I guess I&#39;ll just have to get lucky when I start looking again.  I don&#39;t mind teaching sharp guys new concepts, but even finding them is next to impossible it seems.  Anyway, if you&#39;re in the Houston area and looking, definitely drop me a line.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/595050176712234659/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/595050176712234659' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/595050176712234659'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/595050176712234659'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/05/finding-good-developers.html' title='Finding Good Developers'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-1758187331365881023</id><published>2007-05-02T20:49:00.000-05:00</published><updated>2007-05-02T20:51:44.750-05:00</updated><title type='text'>One of the Funniest Comics Ever</title><content type='html'>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://imgs.xkcd.com/comics/sandwich.png&quot;&gt;&lt;img style=&quot;cursor:pointer; cursor:hand;width: 320px;&quot; src=&quot;http://imgs.xkcd.com/comics/sandwich.png&quot; border=&quot;0&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I couldn&#39;t stop laughing when I saw this.  There&#39;s lots more at &lt;a href=&quot;http://xkcd.com/&quot;&gt;XKCD&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/1758187331365881023/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/1758187331365881023' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/1758187331365881023'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/1758187331365881023'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/05/one-of-funniest-comics-ever.html' title='One of the Funniest Comics Ever'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-5970029742728492009</id><published>2007-05-01T22:01:00.000-05:00</published><updated>2007-05-01T22:34:02.498-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="architecture"/><category scheme="http://www.blogger.com/atom/ns#" term="tdd"/><title type='text'>Top Down vs. Bottom Up</title><content type='html'>I used to start building new applications by writing the model and persistence layer.  I&#39;d flush out my model, then build the persistence on top, and then go about writing the view.  I will not likely use this approach ever again.&lt;br /&gt;&lt;br /&gt;I&#39;m currently working on a &lt;a href=&quot;http://www.castleproject.org&quot;&gt;MonoRail&lt;/a&gt; application where I&#39;m taking a different approach.  I&#39;ve been start at the controller and view level and been working downward.  When I reach a point where I need to work with the model and persistence, I instead define an interface and an appropriate model that would be ideal for the specific use case I&#39;m working on.&lt;br /&gt;&lt;br /&gt;I&#39;ve found myself stubbing out implementations to these interfaces, instead of actually creating the database and persistence logic.  A huge win that I&#39;ve found is that I&#39;m able to test the web application without a database!  It makes changes and refactoring take a fraction of the time because I don&#39;t have to worry about updating the ORM mapping, database tables, etc.  I also save myself from writing unneeded functionality in the model and persistence layer.  But being able to see the application interface using mock data and not ever actually hitting the database have both been a huge benefit.  The time to do a write/compile/test cycle has been greatly reduced.  I have less code in my codebase that I&#39;m not actually using.&lt;br /&gt;&lt;br /&gt;I believe this approach matches the TDD style of development a bit better than what I&#39;m used to doing as well.  Write the API that &lt;span style=&quot;font-style:italic;&quot;&gt;want&lt;/span&gt; to use from the top down, not the API that you &lt;span style=&quot;font-style:italic;&quot;&gt;think&lt;/span&gt; you&#39;ll use from the bottom up.&lt;br /&gt;&lt;br /&gt;My inspiration was this post was &lt;a href=&quot;http://www.jpboodhoo.com/blog/NothinButNetOneDevelopersScratchpad.aspx&quot;&gt;list&lt;/a&gt; of best practices that &lt;a href=&quot;http://www.jpboodhoo.com/&quot;&gt;John-Paul S. Boodhoo&lt;/a&gt; jotted down about a course he was taking.  There&#39;s lots of other great stuff his notes as well.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/5970029742728492009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/5970029742728492009' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/5970029742728492009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/5970029742728492009'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/05/top-down-vs-bottom-up.html' title='Top Down vs. Bottom Up'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-7154120950307617904</id><published>2007-04-30T20:16:00.000-05:00</published><updated>2007-04-30T21:04:06.654-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="activerecord"/><category scheme="http://www.blogger.com/atom/ns#" term="castle"/><category scheme="http://www.blogger.com/atom/ns#" term="nhibernate"/><title type='text'>Getting Started with NHibernate</title><content type='html'>I just found a good video &lt;a href=&quot;http://dnrtv.com/default.aspx?showID=51&quot;&gt;introduction&lt;/a&gt; to &lt;a href=&quot;http://www.nhibernate.org/&quot;&gt;NHibernate&lt;/a&gt; over at &lt;a href=&quot;http://dnrtv.com/default.aspx&quot;&gt;dnrTV&lt;/a&gt; created by Oren Eini (aka &lt;a href=&quot;http://www.ayende.com/&quot;&gt;Ayende)&lt;/a&gt;, who is an active NHibernate contributer.  If you&#39;re an NHibernate pro, you probably won&#39;t find anything you didn&#39;t already know.  I usually use Castle &lt;a href=&quot;http://www.castleproject.org/activerecord/index.html&quot;&gt;ActiveRecord&lt;/a&gt; instead of just using NHibernate directly in order to get a sizable productivity boost, provided the project is small enough.  When a project is sufficiently large or complex (multiple client applications, large model, difficult mapping, etc), I believe that skipping AR and going directly to NHibernate is the way to go.  It helps keep your laying cleaner by reducing coupling of your application services and the persistence mechanism.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/7154120950307617904/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/7154120950307617904' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/7154120950307617904'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/7154120950307617904'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/04/getting-started-with-nhibernate.html' title='Getting Started with NHibernate'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-4863738918690577782</id><published>2007-04-28T13:54:00.000-05:00</published><updated>2007-04-30T21:03:25.964-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="castle"/><category scheme="http://www.blogger.com/atom/ns#" term="monorail"/><title type='text'>Rendering Binary Data with MonoRail</title><content type='html'>Sometimes you want to make your MonoRail controller render binary data for a download.  MonoRail by default is setup to render HTML via the view engine, but you can change that behavior.  I usually put a method like this in my base controller:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; SetupDownload(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; filename, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; contentType)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CancelLayout();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CancelView();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Response.Clear();&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Response.ContentType = contentType;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Response.AppendHeader(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Content-Disposition&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;attachment; filename=\&quot;&quot;&lt;/span&gt; + filename + &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;\&quot;&quot;&lt;/span&gt;);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;By calling this method inside one of your controllers, you will change the default behavior of the controller to not perform the layout (&lt;em&gt;CancelLayout()&lt;/em&gt;) and to not try to render a view via the view engine (&lt;em&gt;CancelView()&lt;/em&gt;).  The &lt;em&gt;contentType&lt;/em&gt; should be something like &quot;application/zip&quot;.  It&#39;s the MIME type that is reported to the browser.  This method also tells the browser that the data is not inline, and that the user should be prompted to download the file with a default filename provided by the &lt;em&gt;filename&lt;/em&gt; argument.&lt;br /&gt;&lt;br /&gt;So you have changed the default behavior of MonoRail to render something other than a plain vanilla view.  All that&#39;s left is to write the binary data into the response&#39;s output stream.  If you already have a stream, then you would do something like this:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; CopyStream(&lt;span style=&quot;color: #2b91af;&quot;&gt;Stream&lt;/span&gt; from, &lt;span style=&quot;color: #2b91af;&quot;&gt;Stream&lt;/span&gt; to)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;byte&lt;/span&gt;[] buffer = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;byte&lt;/span&gt;[_bufferSize];&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; bytes = 0;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; ((bytes = from.Read(buffer, 0, buffer.Length)) &amp;gt; 0)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; to.Write(buffer, 0, bytes);&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CopyStream(System.IO.&lt;span style=&quot;color: #2b91af;&quot;&gt;File&lt;/span&gt;.OpenRead(path), Response.OutputStream);&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Or, if you have a byte array (&lt;em&gt;buffer&lt;/em&gt; in this example) or something similar, you can do something like this.&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Response.OutputStream.Write(buffer, 0, buffer.Length);&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Notice that if you want to have the brower render something inline (e.g. an image), than you can just remove line that adds the &lt;em&gt;Content-Disposition&lt;/em&gt; header that is in my example &lt;em&gt;SetupDownload&lt;/em&gt; function.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/4863738918690577782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/4863738918690577782' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/4863738918690577782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/4863738918690577782'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/04/rendering-binary-data-with-monorail.html' title='Rendering Binary Data with MonoRail'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-1101809080175031932</id><published>2007-04-27T10:34:00.000-05:00</published><updated>2007-04-28T00:39:21.062-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="database"/><category scheme="http://www.blogger.com/atom/ns#" term="sql"/><title type='text'>Remove All Tables and Constraints from a Database Using T-SQL</title><content type='html'>You&#39;ve had this problem before:  You don&#39;t want to drop a database completely, but you do want to drop all the tables.  Try to drop your tables in the wrong order and you&#39;re slapped with an error regarding referential constraints.  I&#39;ve created this script to ease the burden.  It first drops all the constraints, and then it drops all the tables.  Let me know if this doesn&#39;t work on your SQL Server database.  Here&#39;s a warning for those who didn&#39;t bother to read this paragraph:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;WARNING:  The following script will delete all the tables in your database.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;On to the script:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;font-family: Consolas, Courier New; font-size: 10pt; color: black; background: white;&quot;&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;DECLARE &lt;/span&gt;@TableName NVARCHAR(&lt;span style=&quot;color: blue;&quot;&gt;MAX&lt;/span&gt;)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;DECLARE &lt;/span&gt;@ConstraintName NVARCHAR(&lt;span style=&quot;color: blue;&quot;&gt;MAX&lt;/span&gt;)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;DECLARE &lt;/span&gt;Constraints &lt;span style=&quot;color: blue;&quot;&gt;CURSOR FOR&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;TABLE_NAME, CONSTRAINT_NAME &lt;span style=&quot;color: blue;&quot;&gt;FROM &lt;/span&gt;INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;OPEN &lt;/span&gt;Constraints&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;FETCH NEXT FROM &lt;/span&gt;Constraints &lt;span style=&quot;color: blue;&quot;&gt;INTO &lt;/span&gt;@TableName, @ConstraintName&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;WHILE &lt;/span&gt;@@FETCH_STATUS = 0&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;BEGIN &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;EXEC&lt;/span&gt;(&lt;span style=&quot;color: #a31515;&quot;&gt;&#39;ALTER TABLE [&#39; &lt;/span&gt;+ @TableName + &lt;span style=&quot;color: #a31515;&quot;&gt;&#39;] DROP CONSTRAINT [&#39; &lt;/span&gt;+ @ConstraintName + &lt;span style=&quot;color: #a31515;&quot;&gt;&#39;]&#39;&lt;/span&gt;)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;FETCH NEXT FROM &lt;/span&gt;Constraints &lt;span style=&quot;color: blue;&quot;&gt;INTO &lt;/span&gt;@TableName, @ConstraintName&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;END&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;CLOSE &lt;/span&gt;Constraints&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;DEALLOCATE &lt;/span&gt;Constraints&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;DECLARE &lt;/span&gt;Tables &lt;span style=&quot;color: blue;&quot;&gt;CURSOR FOR&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;TABLE_NAME &lt;span style=&quot;color: blue;&quot;&gt;FROM &lt;/span&gt;INFORMATION_SCHEMA.TABLES&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;OPEN &lt;/span&gt;Tables&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;FETCH NEXT FROM &lt;/span&gt;Tables &lt;span style=&quot;color: blue;&quot;&gt;INTO &lt;/span&gt;@TableName&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;WHILE &lt;/span&gt;@@FETCH_STATUS = 0&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;BEGIN &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;EXEC&lt;/span&gt;(&lt;span style=&quot;color: #a31515;&quot;&gt;&#39;DROP TABLE [&#39; &lt;/span&gt;+ @TableName + &lt;span style=&quot;color: #a31515;&quot;&gt;&#39;]&#39;&lt;/span&gt;)&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;FETCH NEXT FROM &lt;/span&gt;Tables &lt;span style=&quot;color: blue;&quot;&gt;INTO &lt;/span&gt;@TableName&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;END&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;CLOSE &lt;/span&gt;Tables&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;DEALLOCATE &lt;/span&gt;Tables&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Enjoy.  Let me know if this doesn&#39;t work for you.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/1101809080175031932/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/1101809080175031932' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/1101809080175031932'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/1101809080175031932'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2007/04/remove-all-tables-and-constraints-from.html' title='Remove All Tables and Constraints from a Database Using T-SQL'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10584900.post-111595802289599664</id><published>2005-05-12T22:58:00.001-05:00</published><updated>2008-06-12T23:56:02.759-05:00</updated><title type='text'>Adapting the Elo Rating System for Poker</title><content type='html'>Chess players know what the Elo rating system is. Every player gets a rating a from 0 to 3000. The higher your rating, the better you are. I recently was tasked with coming up with a rating system for poker players that play tournaments. I have previously played around with rolling my own system of statistics to determine the ability of a poker player, but I&#39;m no math genius so I looked for something prebuilt.&lt;br /&gt;&lt;br /&gt;I decided I&#39;d modify the Elo rating system used in chess for poker. It has to be modified because it was originally designed for games where there are only two players.  Ratings for players are calculated based on who won the game and what the respective ratings of the players were before the game completed.  The problem is that poker tournaments have many players, not just two, so it had to be modifed.&lt;br /&gt;&lt;br /&gt;The Elo rating system tries to predict the probability that a given player will beat another player based on their ratings. It then uses the new data, i.e. the result of the game, to adjust its predictions for the next game. If a player wins, he gets a score of 1. If he loses, he gets a score of 0. And if both players draw, they both get a score of 0.5.&lt;br /&gt;&lt;br /&gt;In poker tournaments, you want capture not only who won the game, but who did well in the tournament. Obviously, second place, third place, etc. deserve some recognition. You can&#39;t just recognize first place as the only &quot;winner.&quot;  So, instead of a score of 1 for the winner, and 0 for all the losers, a player attains a score equal to that player&#39;s place scaled by the size of the tournament he played in.  The equation looks something like:&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;S = Score&lt;br /&gt;P = Place of a specific player&lt;br /&gt;N = Number of players&lt;br /&gt;&lt;br /&gt;S = (P-1)/(N-1)&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Using this formula, first place gets a 1, last place gets a 0, and all the players in between get something between 0 and 1.&lt;br /&gt;&lt;br /&gt;The Elo system also uses an expression to predict the score of a given player based on his opponent. The original system only takes into account one other player. The new system has to include the ratings of all of the other players in the tournament. Traditionally, the Elo system uses an expression to predict the score that looks something like:&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;Ea = Estimated score for Player A&lt;br /&gt;Eb = Estimated score for Player B&lt;br /&gt;Ra = Rating of Player A&lt;br /&gt;Rb = Rating of Player B&lt;br /&gt;&lt;br /&gt;Ea = 1 / (1 + 10^((Rb-Ra)/400))&lt;br /&gt;Eb = 1 / (1 + 10^((Ra-Rb)/400))&lt;br /&gt;&lt;/blockquote&gt;We have more than one opposing player, so I average the ratings of &lt;span style=&quot;font-style: italic;&quot;&gt;all&lt;/span&gt; &lt;span style=&quot;font-style: italic;&quot;&gt;opposing&lt;/span&gt; players.  This is the second modification I made.  By the way, the 400 is used to fit the ratings along a normal distribution curve desired for chess ratings.&lt;br /&gt;&lt;br /&gt;I&#39;ve tested this model with good results.  I plan on implementing it for a large group of poker players and hope that others might test it and try it out on their own.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Update&lt;/span&gt;: I&#39;ve revised my ideas on the modification to the system &lt;a href=&quot;http://sradack.blogspot.com/2008/06/elo-rating-system-multiple-players.html&quot;&gt;here&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://sradack.blogspot.com/feeds/111595802289599664/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/10584900/111595802289599664' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/111595802289599664'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10584900/posts/default/111595802289599664'/><link rel='alternate' type='text/html' href='http://sradack.blogspot.com/2005/05/adapting-elo-rating-system-for-poker.html' title='Adapting the Elo Rating System for Poker'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>