<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 - Entries tagged with Patterns</title>
    <atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Tags/patterns/RSS"></atom:link>
    <itunes:summary></itunes:summary>
    <itunes:author>Microsoft</itunes:author>
    <itunes:subtitle></itunes:subtitle>
    <image>
      <url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
      <title>Channel 9 - Entries tagged with Patterns</title>
      <link>http://channel9.msdn.com/Tags/patterns</link>
    </image>
    <itunes:image href=""></itunes:image>
    <itunes:category text="Technology"></itunes:category>
    <description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
    <link>http://channel9.msdn.com/Tags/patterns</link>
    <language>en</language>
    <pubDate>Fri, 24 May 2013 02:55:31 GMT</pubDate>
    <lastBuildDate>Fri, 24 May 2013 02:55:31 GMT</lastBuildDate>
    <generator>Rev9</generator>
    <c9:totalResults>34</c9:totalResults>
    <c9:pageCount>2</c9:pageCount>
    <c9:pageSize>25</c9:pageSize>
  <item>
      <title>ARCast.TV - Rocky Lhotka on Patterns, Architecture and MVVM</title>
      <description><![CDATA[
<p><a shape="rect" href="http://www.lhotka.net/" shape="rect">Rockford Lhotka</a> is the Principal Technology Evangelist for
<a shape="rect" href="http://magenic.com/" shape="rect">Magenic</a>, a company focused on delivering business value through applied technology and one of the nation's premiere Microsoft Gold Certified Partners. Rocky is the creator of CSLA .NET, one of the
 most widely used development frameworks for Microsoft .NET and he is the author of numerous books, including the Expert 2008 Business Objects book.</p>
<p>In this episode Rocky talks to <a shape="rect" href="http://blogs.msdn.com/b/bobfamiliar/" shape="rect">
Bob Familiar</a> about why patterns are important, the relationship between patterns and layered architecture and the emergence of MVVM as a key pattern for Rich Internet Applications.</p>
<p>More information on patterns and MVVM can be found on <a shape="rect" href="http://www.lhotka.net/weblog/" shape="rect">
Rocky’s Blog</a>.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:8301f9cd75974c91ae149dea009f0197">]]></description>
      <comments>http://channel9.msdn.com/Shows/ARCast.TV/ARCastTV-Rocky-Lhotka-on-Patterns-Architecture-and-MVVM</comments>
      <itunes:summary>
Rockford Lhotka is the Principal Technology Evangelist for
Magenic, a company focused on delivering business value through applied technology and one of the nation&#39;s premiere Microsoft Gold Certified Partners. Rocky is the creator of CSLA .NET, one of the
 most widely used development frameworks for Microsoft .NET and he is the author of numerous books, including the Expert 2008 Business Objects book. 
In this episode Rocky talks to 
Bob Familiar about why patterns are important, the relationship between patterns and layered architecture and the emergence of MVVM as a key pattern for Rich Internet Applications. 
More information on patterns and MVVM can be found on 
Rocky’s Blog. 
</itunes:summary>
      <itunes:duration>887</itunes:duration>
      <link>http://channel9.msdn.com/Shows/ARCast.TV/ARCastTV-Rocky-Lhotka-on-Patterns-Architecture-and-MVVM</link>
      <pubDate>Sun, 18 Jul 2010 21:19:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Shows/ARCast.TV/ARCastTV-Rocky-Lhotka-on-Patterns-Architecture-and-MVVM</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/556324_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/556324_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/4/2/3/6/5/5/ARCastRockyOnMVVM_320_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/4/2/3/6/5/5/ARCastRockyOnMVVM_512_ch9.png" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/4/2/3/6/5/5/ARCastRockyOnMVVM_85_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/4/2/3/6/5/5/ARCastRockyOnMVVM_2MB_ch9.wmv" expression="full" duration="887" fileSize="228962773" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/4/2/3/6/5/5/ARCastRockyOnMVVM_ch9.mp3" expression="full" duration="887" fileSize="7104437" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/4/2/3/6/5/5/ARCastRockyOnMVVM_ch9.mp4" expression="full" duration="887" fileSize="91793880" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/4/2/3/6/5/5/ARCastRockyOnMVVM_ch9.wma" expression="full" duration="887" fileSize="7187541" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/4/2/3/6/5/5/ARCastRockyOnMVVM_ch9.wmv" expression="full" duration="887" fileSize="136913951" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/4/2/3/6/5/5/ARCastRockyOnMVVM_Zune_ch9.wmv" expression="full" duration="887" fileSize="79346003" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/4/2/3/6/5/5/ARCastRockyOnMVVM_ch9.wmv" length="136913951" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Bob Familiar</dc:creator>
      <itunes:author>Bob Familiar</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Shows/ARCast.TV/ARCastTV-Rocky-Lhotka-on-Patterns-Architecture-and-MVVM/RSS</wfw:commentRss>
      <category>ARCast</category>
      <category>Architects</category>
      <category>Architecture</category>
      <category>MVVM</category>
      <category>Patterns</category>
      <category>Thought Leadership</category>
    </item>
  <item>
      <title>deCast - Patterns-Based Silverlight - Part III - The Pipeline Pattern</title>
      <description><![CDATA[
<p>In this multi-part blog series, Rob Bagby will be illustrating the use of various design patterns in Silverlight development.&nbsp; The patterns covered in the series are Repository, Pipeline, Service Agent and Model View ViewModel (MVVM).<br />&nbsp; <br />In this screencast, Rob will implement the Pipeline pattern.&nbsp; He will then implement a fake repository and use it to test our Pipeline.</p>
<p>You can view the code and read the <a shape="rect" href="http://www.robbagby.com/posts/patterns-based-silverlight-development-part-iii-pipeline-pattern/" shape="rect">
blog post regarding implementing the pipeline pattern here</a>.&nbsp; You can download the code at
<a shape="rect" href="http://www.robbagby.com" shape="rect">www.robbagby.com</a>.
</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:89376fba75654522943d9deb0014920b">]]></description>
      <comments>http://channel9.msdn.com/Blogs/RobBagby/deCast-Patterns-Based-Silverlight-Part-III-The-Pipeline-Pattern</comments>
      <itunes:summary>
In this multi-part blog series, Rob Bagby will be illustrating the use of various design patterns in Silverlight development.&amp;nbsp; The patterns covered in the series are Repository, Pipeline, Service Agent and Model View ViewModel (MVVM).&amp;nbsp; In this screencast, Rob will implement the Pipeline pattern.&amp;nbsp; He will then implement a fake repository and use it to test our Pipeline. 
You can view the code and read the 
blog post regarding implementing the pipeline pattern here.&amp;nbsp; You can download the code at
www.robbagby.com.
 
</itunes:summary>
      <itunes:duration>962</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/RobBagby/deCast-Patterns-Based-Silverlight-Part-III-The-Pipeline-Pattern</link>
      <pubDate>Mon, 26 Oct 2009 12:22:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/RobBagby/deCast-Patterns-Based-Silverlight-Part-III-The-Pipeline-Pattern</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/501880_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/501880_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/0/8/8/1/0/5/SilverlightPartIII_320_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/0/8/8/1/0/5/SilverlightPartIII_512_ch9.png" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/0/8/8/1/0/5/SilverlightPartIII_85_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/8/8/1/0/5/SilverlightPartIII_2MB_ch9.wmv" expression="full" duration="962" fileSize="38745177" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/8/8/1/0/5/SilverlightPartIII_ch9.mp3" expression="full" duration="962" fileSize="7702601" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/8/8/1/0/5/SilverlightPartIII_ch9.mp4" expression="full" duration="962" fileSize="39233532" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/8/8/1/0/5/SilverlightPartIII_ch9.wma" expression="full" duration="962" fileSize="7797353" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/8/8/1/0/5/SilverlightPartIII_ch9.wmv" expression="full" duration="962" fileSize="47811001" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/8/8/1/0/5/SilverlightPartIII_Zune_ch9.wmv" expression="full" duration="962" fileSize="36453902" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/0/8/8/1/0/5/SilverlightPartIII_ch9.wmv" length="47811001" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Rob Bagby</dc:creator>
      <itunes:author>Rob Bagby</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/RobBagby/deCast-Patterns-Based-Silverlight-Part-III-The-Pipeline-Pattern/RSS</wfw:commentRss>
      <category>deCast</category>
      <category>Patterns</category>
      <category>Repository</category>
      <category>Silverlight</category>
      <category>Silverlight 3</category>
    </item>
  <item>
      <title>deCast - Patterns-Based Silverlight - Part II - The Repository Pattern</title>
      <description><![CDATA[
<p>In this multi-part blog series, Rob Bagby will be illustrating the use of various design patterns in Silverlight development.&nbsp; The patterns covered in the series are Repository, Pipeline, Service Agent and Model View ViewModel (MVVM).<br />&nbsp; <br />In this screencast, Rob will implement the Repository pattern and set up server-side validation.</p>
<p>You can view the code and read the <a shape="rect" href="http://www.robbagby.com/silverlight/patterns-based-silverlight-development-part-ii-repository-and-validation/" shape="rect">
blog post regarding implementing the repository pattern here</a>.&nbsp; You can download the code at
<a shape="rect" href="http://www.robbagby.com" shape="rect">www.robbagby.com</a>.&nbsp;
</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:088940c9626b439dbe2e9deb00149638">]]></description>
      <comments>http://channel9.msdn.com/Blogs/RobBagby/deCast-Patterns-Based-Silverlight-Part-II-The-Repository-Pattern</comments>
      <itunes:summary>
In this multi-part blog series, Rob Bagby will be illustrating the use of various design patterns in Silverlight development.&amp;nbsp; The patterns covered in the series are Repository, Pipeline, Service Agent and Model View ViewModel (MVVM).&amp;nbsp; In this screencast, Rob will implement the Repository pattern and set up server-side validation. 
You can view the code and read the 
blog post regarding implementing the repository pattern here.&amp;nbsp; You can download the code at
www.robbagby.com.&amp;nbsp;
 
</itunes:summary>
      <itunes:duration>1166</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/RobBagby/deCast-Patterns-Based-Silverlight-Part-II-The-Repository-Pattern</link>
      <pubDate>Wed, 21 Oct 2009 20:34:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/RobBagby/deCast-Patterns-Based-Silverlight-Part-II-The-Repository-Pattern</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/500877_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/500877_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/7/7/8/0/0/5/SilverlightPartII_320_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/7/7/8/0/0/5/SilverlightPartII_512_ch9.png" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/7/7/8/0/0/5/SilverlightPartII_85_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/7/8/0/0/5/SilverlightPartII_2MB_ch9.wmv" expression="full" duration="1166" fileSize="56325655" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/7/8/0/0/5/SilverlightPartII_ch9.mp3" expression="full" duration="1166" fileSize="9337403" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/7/8/0/0/5/SilverlightPartII_ch9.mp4" expression="full" duration="1166" fileSize="52112782" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/7/8/0/0/5/SilverlightPartII_ch9.wma" expression="full" duration="1166" fileSize="9449547" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/7/8/0/0/5/SilverlightPartII_ch9.wmv" expression="full" duration="1166" fileSize="66261851" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/7/8/0/0/5/SilverlightPartII_Zune_ch9.wmv" expression="full" duration="1166" fileSize="47510235" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/7/7/8/0/0/5/SilverlightPartII_ch9.wmv" length="66261851" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Rob Bagby</dc:creator>
      <itunes:author>Rob Bagby</itunes:author>
      <slash:comments>1</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/RobBagby/deCast-Patterns-Based-Silverlight-Part-II-The-Repository-Pattern/RSS</wfw:commentRss>
      <category>deCast</category>
      <category>Patterns</category>
      <category>Repository</category>
      <category>Silverlight</category>
      <category>Silverlight 3</category>
    </item>
  <item>
      <title>deCast - Patterns-Based Silverlight - Part I - Getting Started</title>
      <description><![CDATA[
<p>In this multi-part blog series, Rob Bagby will be illustrating the use of various design patterns in Silverlight development.&nbsp; The patterns covered in the series are Repository, Pipeline, Service Agent and Model View ViewModel.&nbsp; In this screencast, Rob will
 set up the project, build the LINQ to SQL model and ensure the generated objects are serializable.</p>
<p>You can visit this&nbsp;<a shape="rect" href="http://www.robbagby.com/silverlight/patterns-based-silverlight-development-blog-screencast-series-index/" shape="rect">index of all blog posts and screencasts on Patterns-Based Silverlight</a>.&nbsp; You can download the
 code at <a shape="rect" href="http://www.robbagby.com" shape="rect">www.robbagby.com</a>.&nbsp;
</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:906a9a9a786843238dec9deb00149ab6">]]></description>
      <comments>http://channel9.msdn.com/Blogs/RobBagby/deCast-Patterns-Based-Silverlight-Part-I-Getting-Started</comments>
      <itunes:summary>
In this multi-part blog series, Rob Bagby will be illustrating the use of various design patterns in Silverlight development.&amp;nbsp; The patterns covered in the series are Repository, Pipeline, Service Agent and Model View ViewModel.&amp;nbsp; In this screencast, Rob will
 set up the project, build the LINQ to SQL model and ensure the generated objects are serializable. 
You can visit this&amp;nbsp;index of all blog posts and screencasts on Patterns-Based Silverlight.&amp;nbsp; You can download the
 code at www.robbagby.com.&amp;nbsp;
 
</itunes:summary>
      <itunes:duration>744</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/RobBagby/deCast-Patterns-Based-Silverlight-Part-I-Getting-Started</link>
      <pubDate>Mon, 19 Oct 2009 15:19:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/RobBagby/deCast-Patterns-Based-Silverlight-Part-I-Getting-Started</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/500034_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/500034_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/4/3/0/0/0/5/SilverlightPartI_320_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/4/3/0/0/0/5/SilverlightPartI_512_ch9.png" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/4/3/0/0/0/5/SilverlightPartI_85_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/4/3/0/0/0/5/SilverlightPartI_2MB_ch9.wmv" expression="full" duration="744" fileSize="29664009" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/4/3/0/0/0/5/SilverlightPartI_ch9.mp3" expression="full" duration="744" fileSize="5954206" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/4/3/0/0/0/5/SilverlightPartI_ch9.mp4" expression="full" duration="744" fileSize="29198568" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/4/3/0/0/0/5/SilverlightPartI_ch9.wma" expression="full" duration="744" fileSize="6030995" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/4/3/0/0/0/5/SilverlightPartI_ch9.wmv" expression="full" duration="744" fileSize="34911943" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/4/3/0/0/0/5/SilverlightPartI_Zune_ch9.wmv" expression="full" duration="744" fileSize="27549589" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/4/3/0/0/0/5/SilverlightPartI_ch9.wmv" length="34911943" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Rob Bagby</dc:creator>
      <itunes:author>Rob Bagby</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/RobBagby/deCast-Patterns-Based-Silverlight-Part-I-Getting-Started/RSS</wfw:commentRss>
      <category>deCast</category>
      <category>Design Patterns</category>
      <category>Patterns</category>
      <category>Silverlight</category>
      <category>Silverlight 3</category>
    </item>
  <item>
      <title>ARCast.TV - How to Improve Testability with a Modular Architecture</title>
      <description><![CDATA[<a shape="rect" href="http://www.mariocardinal.com/" shape="rect">Mario Cardinal
</a>and <a shape="rect" href="http://geekswithblogs.net/aaronsblog/Default.aspx" shape="rect">
Aaron Kowall </a>discuss how to easily test in an autonomous way an application conceived with modular abstractions such as the &quot;layer&quot;. Mario and Aaron discuss&nbsp;how to partition the concerns of the application&nbsp;into layers&nbsp;and best practices regarding application
 architecture and modularity.  <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:84b3fdab6e724f57a6339dea00c0b609">]]></description>
      <comments>http://channel9.msdn.com/Shows/ARCast.TV/ARCastTV-How-to-Improve-Testability-with-a-Modular-Architecture</comments>
      <itunes:summary>Mario Cardinal
and 
Aaron Kowall discuss how to easily test in an autonomous way an application conceived with modular abstractions such as the &amp;quot;layer&amp;quot;. Mario and Aaron discuss&amp;nbsp;how to partition the concerns of the application&amp;nbsp;into layers&amp;nbsp;and best practices regarding application
 architecture and modularity. </itunes:summary>
      <itunes:duration>1156</itunes:duration>
      <link>http://channel9.msdn.com/Shows/ARCast.TV/ARCastTV-How-to-Improve-Testability-with-a-Modular-Architecture</link>
      <pubDate>Mon, 12 Oct 2009 16:26:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Shows/ARCast.TV/ARCastTV-How-to-Improve-Testability-with-a-Modular-Architecture</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/470735_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/470735_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/5/3/7/0/7/4/ARCastImprovingTestability_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/5/3/7/0/7/4/ARCastImprovingTestability_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/5/3/7/0/7/4/ARCastImprovingTestability_2MB_ch9.wmv" expression="full" duration="1156" fileSize="118748379" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/5/3/7/0/7/4/ARCastImprovingTestability_ch9.mp3" expression="full" duration="1156" fileSize="9253796" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/5/3/7/0/7/4/ARCastImprovingTestability_ch9.mp4" expression="full" duration="1156" fileSize="101454499" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/5/3/7/0/7/4/ARCastImprovingTestability_ch9.wma" expression="full" duration="1156" fileSize="18710897" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/5/3/7/0/7/4/ARCastImprovingTestability_ch9.wmv" expression="full" duration="1156" fileSize="69772379" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/5/3/7/0/7/4/ARCastImprovingTestability_Zune_ch9.wmv" expression="full" duration="1156" fileSize="119228359" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/ch9/5/3/7/0/7/4/ARCastImprovingTestability_s_ch9.wmv" expression="full" duration="1156" fileSize="233" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/5/3/7/0/7/4/ARCastImprovingTestability_ch9.wmv" length="69772379" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Bob Familiar</dc:creator>
      <itunes:author>Bob Familiar</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Shows/ARCast.TV/ARCastTV-How-to-Improve-Testability-with-a-Modular-Architecture/RSS</wfw:commentRss>
      <category>ARCast</category>
      <category>Architects</category>
      <category>Architectural Skills</category>
      <category>Architecture</category>
      <category>Frameworks</category>
      <category>modularity</category>
      <category>Patterns</category>
      <category>Practical Guidance</category>
      <category>Test Driven Development</category>
      <category>Testability</category>
      <category>Testing</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready - Refactoring Notification</title>
      <description><![CDATA[
<h1>Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready –Refactoring Notification</h1>
<p>The circular dependency problem between Pages and Users is due to each class implementing part of a larger notification feature. Once again this was not obvious when the two classes were coupled together via Singleton instances. Although the Single Responsibility
 Principle (SRP) would encourage us to have a separate Notification class, our primary job right now is to disentangle Pages and Users. Once the responsibility for notifications has been moved to one class or the other, it can be separated more easily into
 a separate Notification class. Let’s work on moving it to Pages.</p>
<p>We’ll start by adding notification-related methods on IUsers to IPages (we won’t remove the methods from IUsers or Users yet):</p>
<pre>public interface IPages {&nbsp;&nbsp;&nbsp; ...&nbsp;&nbsp;&nbsp; bool SetEmailNotification(UserInfo user, PageInfo page,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bool pageChanges, bool discussionMessages);&nbsp;&nbsp;&nbsp; bool SetEmailNotification(UserInfo user, NamespaceInfo nspace, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bool pageChanges, bool discussionMessages);&nbsp;&nbsp;&nbsp; void GetEmailNotification(UserInfo user, PageInfo page, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out bool pageChanges, out bool discussionMessages);&nbsp;&nbsp;&nbsp; void GetEmailNotification(UserInfo user, NamespaceInfo nspace, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out bool pageChanges, out bool discussionMessages);&nbsp;&nbsp;&nbsp; UserInfo[] GetUsersToNotifyForPageChange(PageInfo page);&nbsp;&nbsp;&nbsp; UserInfo[] GetUsersToNotifyForDiscussionMessages(PageInfo page);}</pre>
<br>
<p>We will implement these methods on Pages by temporarily delegating to Users:</p>
<pre>public bool SetEmailNotification(UserInfo user, PageInfo page,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool pageChanges, bool discussionMessages) {&nbsp;&nbsp;&nbsp; return users.SetEmailNotification(user, page, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pageChanges, discussionMessages);}</pre>
<br>
<p>The other methods are implemented similarly. We can now look for usages of those methods on IUsers and change them to reference the same methods on IPages instead. The only usages for the IUsers methods should now be by Pages and the IUsers methods can be
 removed. You’ll have to temporarily cast the IUsers instances in the delegating methods to Users as the methods no longer exist on the IUsers interface:</p>
<pre>public bool SetEmailNotification(UserInfo user, PageInfo page,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool pageChanges, bool discussionMessages) {&nbsp;&nbsp;&nbsp; return ((Users)users).SetEmailNotification(user, page,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pageChanges, discussionMessages);}</pre>
<br>
<p>Time to pack up the notification-related methods on Users and move them to their new home on Pages.</p>
<h2>And That’s a Wrap</h2>
<p>Simply by making the dependencies between classes explicit via dependency injection, we revealed a number of circular dependencies lurking in the ScrewTurn Wiki codebase. Circular dependencies between components effectively turn the individual components
 into one large super-structure, which is difficult to modify. Changes ripple through these super-structures and resulting in unexpected breakages after seemingly innocuous modifications.
</p>
<p>Applying the same techniques to Host’s other dependencies, we remove Host’s use of singletons altogether. (For the curious reader, the code is available for download from
<a shape="rect" href="http://code.msdn.microsoft.com/mag2009BFXASP" shape="rect">
MSDN Code Gallery for Extreme ASP.NET Makeover</a>.) Host’s constructor signature now looks like this:</p>
<pre>public Host(ISettings settings, IAuthWriter authWriter, IUsers users,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IPages pages, ISnippets snippets, INavigationPaths navigationPaths)</pre>
<br>
<p>Its dependencies are obvious in a way that they were not before. Host has a fair number of dependencies, but it is acting as a facade between ScrewTurn Wiki and the plug-ins. So it is not overly worrying.</p>
<p>We can start asking ourselves meta questions about our software:</p>
<ul>
<li>Do these dependencies make sense? </li><li>Should some of these dependencies be combined/split? </li><li>How do the dependencies relate to one another and can those relationships be improved?
</li></ul>
<p>We can reason about the overall structure of our software and improve it because that structure is more apparent. In the end, our software becomes more flexible, more testable, and more resilient in the face of change.</p>
<h2>Acknowledgements</h2>
<p>I would like to thank Dario Solera, creator of ScrewTurn Wiki, for being brave and open in allowing me to use ScrewTurn Wiki as the brownfield application throughout this series. He has already taken the constructive criticism provided in earlier articles
 and used it to improve the latest builds of ScrewTurn Wiki. Kudos to Dario for permitting all of us to learn together out in the open.</p>
<p>Thank you to my two occasional co-authors, Kyle Baley and Donald Belcham, for their assistance on parts 6 and 7. Your insights were invaluable in pushing the series forward. Dario has agreed to allow ScrewTurn Wiki to be used as the sample brownfield application
 for Kyle and Donald’s upcoming book, <i>Brownfield Application Development in .NET</i>, published by Manning. If you want more information about improving brownfield applications, their book is an excellent resource.</p>
<p>A big thanks to Howard Dierking for giving me the latitude and encouragement to take the series where I thought would be most useful and practical. Thanks also to Gary Clarke and the rest of the
<i>MSDN Magazine</i> staff for their helpful suggestions, patience, and quick turn-around while editing the series.</p>
<p>Finally, I would like to offer special thanks to my spouse, Risa Kawchuk, and my two sons, Daegan and Gareth, for their understanding in not having as much spouse/daddy time in the last few months as I’ve toiled away evenings and weekends on these articles
 and screencasts.</p>
<h2>Other videos from this article</h2>
<ul>
<li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Overview/" shape="rect">Overview</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Dependency/" shape="rect">Dependency</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Host-Users-Dependency-Cycle/" shape="rect">Host Users Dependency Cycle</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Circular-Dependency-Cycle/" shape="rect">Circular Dependency Cycle</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Refactoring-Notification/" shape="rect">Refactoring Notification</a>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/magazine/ee470637.aspx" shape="rect">
http://msdn.microsoft.com/magazine/ee470637.aspx</a></p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:5ad4081946474e2a87649deb0020ffc0">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Refactoring-Notification</comments>
      <itunes:summary>
Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready –Refactoring Notification
The circular dependency problem between Pages and Users is due to each class implementing part of a larger notification feature. Once again this was not obvious when the two classes were coupled together via Singleton instances. Although the Single Responsibility
 Principle (SRP) would encourage us to have a separate Notification class, our primary job right now is to disentangle Pages and Users. Once the responsibility for notifications has been moved to one class or the other, it can be separated more easily into
 a separate Notification class. Let’s work on moving it to Pages. 
We’ll start by adding notification-related methods on IUsers to IPages (we won’t remove the methods from IUsers or Users yet): 
public interface IPages {&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&amp;nbsp;&amp;nbsp;&amp;nbsp; bool SetEmailNotification(UserInfo user, PageInfo page,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bool pageChanges, bool discussionMessages);&amp;nbsp;&amp;nbsp;&amp;nbsp; bool SetEmailNotification(UserInfo user, NamespaceInfo nspace, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bool pageChanges, bool discussionMessages);&amp;nbsp;&amp;nbsp;&amp;nbsp; void GetEmailNotification(UserInfo user, PageInfo page, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;out bool pageChanges, out bool discussionMessages);&amp;nbsp;&amp;nbsp;&amp;nbsp; void GetEmailNotification(UserInfo user, NamespaceInfo nspace, &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;out bool pageChanges, out bool discussionMessages);&amp;nbsp;&amp;nbsp;&amp;nbsp; UserInfo[] GetUsersToNotifyForPageChange(PageInfo page);&amp;nbsp;&amp;nbsp;&amp;nbsp; UserInfo[] GetUsersToNotifyForDiscussionMessages(PageInfo page);}

We will implement these methods on Pages by temporarily delegating to Users: 
public bool SetEmailNotification(UserInfo user, PageInfo page,&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;</itunes:summary>
      <itunes:duration>655</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Refactoring-Notification</link>
      <pubDate>Fri, 11 Sep 2009 18:18:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Refactoring-Notification</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/491010_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/491010_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/0/1/0/1/9/4/RefactoringNotifications_320_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/0/1/0/1/9/4/RefactoringNotifications_512_ch9.png" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/0/1/0/1/9/4/RefactoringNotifications_85_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/1/0/1/9/4/RefactoringNotifications_2MB_ch9.wmv" expression="full" duration="655" fileSize="45492622" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/1/0/1/9/4/RefactoringNotifications_ch9.mp3" expression="full" duration="655" fileSize="5245821" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/1/0/1/9/4/RefactoringNotifications_ch9.mp4" expression="full" duration="655" fileSize="22819755" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/1/0/1/9/4/RefactoringNotifications_ch9.wma" expression="full" duration="655" fileSize="5307031" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/1/0/1/9/4/RefactoringNotifications_ch9.wmv" expression="full" duration="655" fileSize="43406749" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/0/1/0/1/9/4/RefactoringNotifications_Zune_ch9.wmv" expression="full" duration="655" fileSize="23182677" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/ch9/0/1/0/1/9/4/RefactoringNotifications_s_ch9.wmv" expression="full" duration="655" fileSize="229" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/0/1/0/1/9/4/RefactoringNotifications_ch9.wmv" length="43406749" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>1</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Refactoring-Notification/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready - Circular Dependency Cycle</title>
      <description><![CDATA[
<h1>Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready –Circular Dependency Cycle</h1>
<p>The only reason for Users to reference Host is to raise events on behalf of the Users class. We can quickly and easily remove this dependency by allowing Users to raise its own events, as shown in
<b>Figure 4</b>.</p>
<p><b>Figure 4 Users Raises Its Own Events</b></p>
<pre>public class Users : IUsers {&nbsp; public event     EventHandler&lt;UserAccountActivityEventArgs&gt; UserAccountChanged;&nbsp; private void OnUserAccountChanged(UserInfo user,    UserAccountActivity activity) {&nbsp; &nbsp;   if(UserAccountChanged != null) {&nbsp;&nbsp;&nbsp; &nbsp;   UserAccountChanged(this,           new UserAccountActivityEventArgs(user, activity));&nbsp;&nbsp;&nbsp;   }  }&nbsp; public event     EventHandler&lt;UserGroupActivityEventArgs&gt; UserGroupChanged;&nbsp; private void OnUserGroupChanged(UserGroup group,&nbsp;&nbsp;&nbsp;&nbsp;UserGroupActivity activity) {&nbsp;&nbsp;&nbsp; if(UserGroupChanged != null) {&nbsp; &nbsp;&nbsp;&nbsp; UserGroupChanged(this,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new UserGroupActivityEventArgs(group, activity));&nbsp;&nbsp;&nbsp; }&nbsp; }}</pre>
<br>
<p>Host can now subscribe to the Users.UserAccountChanged and Users.UserGroupChanged events and re-broadcast those events to interested listeners without breaking the facade by exposing the Users class directly, as
<b>Figure 5</b> shows.</p>
<p><b>Figure 5 Host Can Subscribe to the Users.UserAccountChanged and Users.UserGroupChanged Events</b></p>
<pre>public class Host : IHostV30 {&nbsp;&nbsp;&nbsp; public Host(ISettings settings, IUsers users) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; customSpecialTags = new Dictionary&lt;string, CustomToolbarItem&gt;(5);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.settings = settings;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.users = users;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; users.UserAccountChanged &#43;= OnUserAccountActivity;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; users.UserGroupChanged &#43;= OnUserGroupActivity;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; public event EventHandler&lt;UserAccountActivityEventArgs&gt; UserAccountActivity;&nbsp;&nbsp;&nbsp; private void OnUserAccountActivity(object sender,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserAccountActivityEventArgs args) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(UserAccountActivity != null) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; UserAccountActivity(this, args);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; public event EventHandler&lt;UserGroupActivityEventArgs&gt; UserGroupActivity;&nbsp;&nbsp;&nbsp; private void OnUserGroupActivity(object sender, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserGroupActivityEventArgs args) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(UserGroupActivity != null) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; UserGroupActivity(this, args);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; }}</pre>
<br>
<p>Users no longer needs a reference to Host and it can be safely removed from Users’ constructor. We have broken the circular dependency between Host and Users. Running our tests, we see that everything is green again.</p>
<p>Before we move on, notice how the circular dependency problem wasn’t immediately noticeable when the classes were linked together using Singletons. Singletons, due to their global nature, make it easy for dependencies to spill between classes. Using the
 dependency injection principle, it is much easier to see a class’s dependencies because most of them are in the constructor and the remainder are method parameters.</p>
<h2>Don’t You Forget about IoC</h2>
<p>With apologies to Billy Idol, we cannot forget about the container. It is responsible for creating and wiring together our dependencies. Looking at ScrewTurnWikiInitializationTask, we see the following:</p>
<pre>Users.Instance = new Users();</pre>
<br>
<p>Classes that take a dependency on IUsers are going to get an instance of Users supplied through their constructor, but classes that access Users.Instance are going to get a different Users instance. We can solve this minor problem by allowing the IoC container
 to supply ScrewTurnWikiInitializationTask with an IUsers instance through its constructor. We now have:</p>
<pre>public ScrewTurnWikiInitializationTask(IHostV30 host, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ISettingsStorageProviderV30 settingsStorageProvider, IUsers users) {&nbsp;&nbsp;&nbsp; this.host = host;&nbsp;&nbsp;&nbsp; this.settingsStorageProvider = settingsStorageProvider;&nbsp;&nbsp;&nbsp; this.users = users;}public void Execute() {&nbsp;&nbsp;&nbsp; ...&nbsp;&nbsp;&nbsp; Users.Instance = users;&nbsp;&nbsp;&nbsp; ....}</pre>
<br>
<p>While we’re talking about the container, let’s look at HostAnProviderRegistration:</p>
<pre>public class HostAndProviderRegistration : IContainerStartupTask {&nbsp;&nbsp;&nbsp; public void Execute(IWindsorContainer container) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; container.Register(&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Component.For&lt;IHostV30&gt;().ImplementedBy&lt;Host&gt;(),&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Component.For&lt;ISettings&gt;().ImplementedBy&lt;Settings&gt;(),&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Component.For&lt;IUsers&gt;().ImplementedBy&lt;Users&gt;());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...&nbsp;&nbsp;&nbsp; }}</pre>
<br>
<p>You’ll notice that we’re starting to get a lot of repetitive code. This is a great place to establish a convention rather than manually configuring each dependency. Let’s create a ScrewTurn.Wiki.Hosting namespace and register each dependency in that namespace
 against its first interface:</p>
<pre>public class HostAndProviderRegistration : IContainerStartupTask {&nbsp;&nbsp;&nbsp; public void Execute(IWindsorContainer container) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; container.Register(&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; AllTypes.FromAssembly(Assembly.GetExecutingAssembly())&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .Where(x =&gt; x.Namespace.StartsWith(&quot;ScrewTurn.Wiki.Hosting&quot;))&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .WithService.FirstInterface()&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; );&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...&nbsp;&nbsp;&nbsp; }}</pre>
<br>
<p>As we refactor dependencies, we need only place them in this namespace (achieved by moving them to the Hosting folder in ScrewTurn.Wiki.Core) and they will automatically be registered correctly in the IoC container.</p>
<h2>The Journey Continues</h2>
<p>Users depends on the Settings.Instance and Pages.Instance Singletons. These are quickly extracted into constructor dependencies as before. Pages gets the same treatment as Users—moving to ScrewTurn.Wiki.Hosting namespace (for automatic IoC registration through
 our convention), interface extraction, and pushing dependent Singletons to constructor parameters. (Additional tests were added to ensure that IPages can be resolved from the IoC container and that Pages.Instance is properly initialized.)</p>
<p>Pages has the same problem as Users in that it uses Host to raise events on its behalf. The same procedure is applied whereby Pages is refactored to raise its own events, which Host then registers for and re-raises to interested listeners. Once again, we’ve
 broken an unnecessary coupling between two classes, Pages and Host this time. For those interested in the details, you can check out the code download associated with the article.</p>
<p>Pages makes use of many other Singletons and the refactoring continues in much the same vein until we get to Users. Once we move Users into a constructor parameter, our tests break. Pages depends on Users and Users depends on Pages. We’ve uncovered another
 circular dependency issue. Let’s take a closer look.</p>
<h2>Other videos from this article</h2>
<ul>
<li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Overview/" shape="rect">Overview</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Dependency/" shape="rect">Dependency</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Host-Users-Dependency-Cycle/" shape="rect">Host Users Dependency Cycle</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Circular-Dependency-Cycle/" shape="rect">Circular Dependency Cycle</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Refactoring-Notification/" shape="rect">Refactoring Notification</a>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/magazine/ee470637.aspx" shape="rect">
http://msdn.microsoft.com/magazine/ee470637.aspx</a></p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:895bc36611cb4b1284079deb002104f1">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Circular-Dependency-Cycle</comments>
      <itunes:summary>
Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready –Circular Dependency Cycle
The only reason for Users to reference Host is to raise events on behalf of the Users class. We can quickly and easily remove this dependency by allowing Users to raise its own events, as shown in
Figure 4. 
Figure 4 Users Raises Its Own Events 
public class Users : IUsers {&amp;nbsp; public event     EventHandler&amp;lt;UserAccountActivityEventArgs&amp;gt; UserAccountChanged;&amp;nbsp; private void OnUserAccountChanged(UserInfo user,    UserAccountActivity activity) {&amp;nbsp; &amp;nbsp;   if(UserAccountChanged != null) {&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;   UserAccountChanged(this,           new UserAccountActivityEventArgs(user, activity));&amp;nbsp;&amp;nbsp;&amp;nbsp;   }  }&amp;nbsp; public event     EventHandler&amp;lt;UserGroupActivityEventArgs&amp;gt; UserGroupChanged;&amp;nbsp; private void OnUserGroupChanged(UserGroup group,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UserGroupActivity activity) {&amp;nbsp;&amp;nbsp;&amp;nbsp; if(UserGroupChanged != null) {&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; UserGroupChanged(this,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new UserGroupActivityEventArgs(group, activity));&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; }}

Host can now subscribe to the Users.UserAccountChanged and Users.UserGroupChanged events and re-broadcast those events to interested listeners without breaking the facade by exposing the Users class directly, as
Figure 5 shows. 
Figure 5 Host Can Subscribe to the Users.UserAccountChanged and Users.UserGroupChanged Events 
public class Host : IHostV30 {&amp;nbsp;&amp;nbsp;&amp;nbsp; public Host(ISettings settings, IUsers users) {&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; customSpecialTags = new Dictionary&amp;lt;string, CustomToolbarItem&amp;gt;(5);&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this.settings = settings;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this.users = users;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; users.UserAccountChanged &amp;#43;= OnUserAccountActivity;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; users.UserGroupChanged &amp;#43;=</itunes:summary>
      <itunes:duration>105</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Circular-Dependency-Cycle</link>
      <pubDate>Fri, 11 Sep 2009 18:17:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Circular-Dependency-Cycle</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/491009_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/491009_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/9/0/0/1/9/4/UsersPagesCircularDependencyProblem_320_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/9/0/0/1/9/4/UsersPagesCircularDependencyProblem_512_ch9.png" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/9/0/0/1/9/4/UsersPagesCircularDependencyProblem_85_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/9/0/0/1/9/4/UsersPagesCircularDependencyProblem_2MB_ch9.wmv" expression="full" duration="105" fileSize="3666772" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/9/0/0/1/9/4/UsersPagesCircularDependencyProblem_ch9.mp3" expression="full" duration="105" fileSize="842623" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/9/0/0/1/9/4/UsersPagesCircularDependencyProblem_ch9.mp4" expression="full" duration="105" fileSize="3013668" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/9/0/0/1/9/4/UsersPagesCircularDependencyProblem_ch9.wma" expression="full" duration="105" fileSize="858113" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/9/0/0/1/9/4/UsersPagesCircularDependencyProblem_ch9.wmv" expression="full" duration="105" fileSize="4631055" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/9/0/0/1/9/4/UsersPagesCircularDependencyProblem_Zune_ch9.wmv" expression="full" duration="105" fileSize="2918983" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/ch9/9/0/0/1/9/4/UsersPagesCircularDependencyProblem_s_ch9.wmv" expression="full" duration="105" fileSize="251" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/9/0/0/1/9/4/UsersPagesCircularDependencyProblem_ch9.wmv" length="4631055" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Circular-Dependency-Cycle/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready - Host Users Dependency Cycle</title>
      <description><![CDATA[
<h1>Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready –Host Users Dependency Cycle</h1>
<br>
<h2>Going Around in Circles</h2>
<p>We successfully refactored away Host’s dependency on Settings.Instance by allowing the IoC container to pass Host an instance of ISettings via its constructor. It seems like a simple matter to continue refactoring away Host’s dependencies on the other Singletons,
 but trouble is brewing just around the corner. The next Singleton we extract is Users.Instance. Following exactly the same procedure as Settings.Instance, we discover a horrible secret - a CircularDependencyException.</p>
<p>Let’s take a look at the constructors for Host and Users:</p>
<pre>public Host(ISettings settings, IUsers users) {&nbsp;&nbsp;&nbsp; customSpecialTags =         new Dictionary&lt;string, CustomToolbarItem&gt;(5);&nbsp;&nbsp;&nbsp; this.settings = settings;&nbsp;&nbsp;&nbsp; this.users = users;}public Users(IHostV30 host) {&nbsp;&nbsp;&nbsp; this.host = host;}</pre>
<br>
<p>So Host depends on Users and Users depends on Host. Before the refactoring, this dependency cycle wasn’t obvious. The two components are in fact much more tightly coupled to one another than expected. Let’s take a deeper look at Users to find out where this
 coupling is coming from.</p>
<h2>Other videos from this article</h2>
<ul>
<li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Overview/" shape="rect">Overview</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Dependency/" shape="rect">Dependency</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Host-Users-Dependency-Cycle/" shape="rect">Host Users Dependency Cycle</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Circular-Dependency-Cycle/" shape="rect">Circular Dependency Cycle</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Refactoring-Notification/" shape="rect">Refactoring Notification</a>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/magazine/ee470637.aspx" shape="rect">
http://msdn.microsoft.com/magazine/ee470637.aspx</a></p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:8ad035b4e603494ea03a9deb002109af">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Host-Users-Dependency-Cycle</comments>
      <itunes:summary>
Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready –Host Users Dependency Cycle

Going Around in Circles
We successfully refactored away Host’s dependency on Settings.Instance by allowing the IoC container to pass Host an instance of ISettings via its constructor. It seems like a simple matter to continue refactoring away Host’s dependencies on the other Singletons,
 but trouble is brewing just around the corner. The next Singleton we extract is Users.Instance. Following exactly the same procedure as Settings.Instance, we discover a horrible secret - a CircularDependencyException. 
Let’s take a look at the constructors for Host and Users: 
public Host(ISettings settings, IUsers users) {&amp;nbsp;&amp;nbsp;&amp;nbsp; customSpecialTags =         new Dictionary&amp;lt;string, CustomToolbarItem&amp;gt;(5);&amp;nbsp;&amp;nbsp;&amp;nbsp; this.settings = settings;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.users = users;}public Users(IHostV30 host) {&amp;nbsp;&amp;nbsp;&amp;nbsp; this.host = host;}

So Host depends on Users and Users depends on Host. Before the refactoring, this dependency cycle wasn’t obvious. The two components are in fact much more tightly coupled to one another than expected. Let’s take a deeper look at Users to find out where this
 coupling is coming from. 
Other videos from this article

Overview
Dependency
Host Users Dependency Cycle
Circular Dependency Cycle
Refactoring Notification

Read the full article at 
http://msdn.microsoft.com/magazine/ee470637.aspx 
</itunes:summary>
      <itunes:duration>81</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Host-Users-Dependency-Cycle</link>
      <pubDate>Fri, 11 Sep 2009 18:17:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Host-Users-Dependency-Cycle</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/491007_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/491007_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/7/0/0/1/9/4/ExaminingHostUsersDependencyCycle_320_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/7/0/0/1/9/4/ExaminingHostUsersDependencyCycle_512_ch9.png" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/7/0/0/1/9/4/ExaminingHostUsersDependencyCycle_85_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/0/0/1/9/4/ExaminingHostUsersDependencyCycle_2MB_ch9.wmv" expression="full" duration="81" fileSize="2364136" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/0/0/1/9/4/ExaminingHostUsersDependencyCycle_ch9.mp3" expression="full" duration="81" fileSize="656844" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/0/0/1/9/4/ExaminingHostUsersDependencyCycle_ch9.mp4" expression="full" duration="81" fileSize="2299663" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/0/0/1/9/4/ExaminingHostUsersDependencyCycle_ch9.wma" expression="full" duration="81" fileSize="668861" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/0/0/1/9/4/ExaminingHostUsersDependencyCycle_ch9.wmv" expression="full" duration="81" fileSize="3446719" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/0/0/1/9/4/ExaminingHostUsersDependencyCycle_Zune_ch9.wmv" expression="full" duration="81" fileSize="2214647" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/ch9/7/0/0/1/9/4/ExaminingHostUsersDependencyCycle_s_ch9.wmv" expression="full" duration="81" fileSize="247" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/7/0/0/1/9/4/ExaminingHostUsersDependencyCycle_ch9.wmv" length="3446719" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Host-Users-Dependency-Cycle/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready - Dependency</title>
      <description><![CDATA[
<h1>Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready –Dependency</h1>
<p>As we saw, the Host class delegates to a whole host of Singletons (bad pun intended), including Settings, Users, Pages, Snippets, NavigationPaths, and AuthWriter. Each of these Singletons refers to other Singletons, creating a morass of dependencies. Before
 we start refactoring Host, we need some tests in place to ensure that we are not breaking anything. Configuration of the application and infrastructure is done by the ApplicationBootstrapper, which we introduced in Part 8. Our tests are going to execute ApplicationBootstrapper.Configure,
 as shown in <b>Figure 2</b>, and then verify that IHostV30 can be resolved from the IoC container as well as that various Singletons are still configured properly. Note that the IoC is initialized to null after every test to ensure that the tests don’t interfere
 with one another.</p>
<p><b>Figure 2 Tests Execute ApplicationBootstrapper.Configure</b></p>
<pre>[TestFixture]public class AfterTheApplicationBootstraperIsExecuted {&nbsp;&nbsp;&nbsp; [Test]&nbsp;&nbsp;&nbsp; public void IHostCanBeResolvedFromTheContainer() {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; IoC.Resolve&lt;IHostV30&gt;();&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; [Test]&nbsp;&nbsp;&nbsp; public void CacheInstanceIsInitialized() {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Assert.That(Cache.Instance, Is.Not.Null);&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; public void SettingsInstanceIsInitialized() {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Assert.That(Settings.Instance, Is.Not.Null);&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; [Test]&nbsp;&nbsp;&nbsp; public void AuthReaderInstanceIsInitialized() {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Assert.That(AuthReader.Instance, Is.Not.Null);&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; [Test]&nbsp;&nbsp;&nbsp; public void AuthWriterInstanceIsInitialized() {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Assert.That(AuthWriter.Instance, Is.Not.Null);&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; [SetUp]&nbsp;&nbsp;&nbsp; public void SetUp() {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new ApplicationBootstrapper().Configure();&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; [TearDown]&nbsp;&nbsp;&nbsp; public void TearDown() {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; IoC.Initialize(null);&nbsp;&nbsp;&nbsp; }}</pre>
<br>
<p>With these tests in place, let’s start refactoring Host to expose its dependency problems.</p>
<h2>Other videos from this article</h2>
<ul>
<li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Overview/" shape="rect">Overview</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Dependency/" shape="rect">Dependency</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Host-Users-Dependency-Cycle/" shape="rect">Host Users Dependency Cycle</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Circular-Dependency-Cycle/" shape="rect">Circular Dependency Cycle</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Refactoring-Notification/" shape="rect">Refactoring Notification</a>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/magazine/ee470637.aspx" shape="rect">
http://msdn.microsoft.com/magazine/ee470637.aspx</a></p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:8796b5b97aa5480bb2e29deb00210e25">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Dependency</comments>
      <itunes:summary>
Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready –Dependency
As we saw, the Host class delegates to a whole host of Singletons (bad pun intended), including Settings, Users, Pages, Snippets, NavigationPaths, and AuthWriter. Each of these Singletons refers to other Singletons, creating a morass of dependencies. Before
 we start refactoring Host, we need some tests in place to ensure that we are not breaking anything. Configuration of the application and infrastructure is done by the ApplicationBootstrapper, which we introduced in Part 8. Our tests are going to execute ApplicationBootstrapper.Configure,
 as shown in Figure 2, and then verify that IHostV30 can be resolved from the IoC container as well as that various Singletons are still configured properly. Note that the IoC is initialized to null after every test to ensure that the tests don’t interfere
 with one another. 
Figure 2 Tests Execute ApplicationBootstrapper.Configure 
[TestFixture]public class AfterTheApplicationBootstraperIsExecuted {&amp;nbsp;&amp;nbsp;&amp;nbsp; [Test]&amp;nbsp;&amp;nbsp;&amp;nbsp; public void IHostCanBeResolvedFromTheContainer() {&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IoC.Resolve&amp;lt;IHostV30&amp;gt;();&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; [Test]&amp;nbsp;&amp;nbsp;&amp;nbsp; public void CacheInstanceIsInitialized() {&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Assert.That(Cache.Instance, Is.Not.Null);&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; public void SettingsInstanceIsInitialized() {&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Assert.That(Settings.Instance, Is.Not.Null);&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; [Test]&amp;nbsp;&amp;nbsp;&amp;nbsp; public void AuthReaderInstanceIsInitialized() {&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Assert.That(AuthReader.Instance, Is.Not.Null);&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; [Test]&amp;nbsp;&amp;nbsp;&amp;nbsp; public void AuthWriterInstanceIsInitialized() {&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Assert.That(AuthWriter.Instance, Is.Not.Null);&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; </itunes:summary>
      <itunes:duration>432</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Dependency</link>
      <pubDate>Fri, 11 Sep 2009 18:17:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Dependency</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/491006_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/491006_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/6/0/0/1/9/4/ExposingTheDependencyProblem_320_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/6/0/0/1/9/4/ExposingTheDependencyProblem_512_ch9.png" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/6/0/0/1/9/4/ExposingTheDependencyProblem_85_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/6/0/0/1/9/4/ExposingTheDependencyProblem_2MB_ch9.wmv" expression="full" duration="432" fileSize="10534940" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/6/0/0/1/9/4/ExposingTheDependencyProblem_ch9.mp3" expression="full" duration="432" fileSize="3464033" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/6/0/0/1/9/4/ExposingTheDependencyProblem_ch9.mp4" expression="full" duration="432" fileSize="11956805" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/6/0/0/1/9/4/ExposingTheDependencyProblem_ch9.wma" expression="full" duration="432" fileSize="3513643" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/6/0/0/1/9/4/ExposingTheDependencyProblem_ch9.wmv" expression="full" duration="432" fileSize="16203627" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/6/0/0/1/9/4/ExposingTheDependencyProblem_Zune_ch9.wmv" expression="full" duration="432" fileSize="11547555" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/ch9/6/0/0/1/9/4/ExposingTheDependencyProblem_s_ch9.wmv" expression="full" duration="432" fileSize="237" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/6/0/0/1/9/4/ExposingTheDependencyProblem_ch9.wmv" length="16203627" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Dependency/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready - Overview</title>
      <description><![CDATA[
<h1>Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready -Overview</h1>
<p>We’re now on the ninth installment of Extreme ASP.NET Makeover. In part 8, we discovered that the ScrewTurn Wiki codebase suffers from dependency problems. Tight coupling of implementation classes caused by singletons and static classes result in a morass
 of objects, which is difficult to refactor. Dependency cycles between objects result in sensitive constructor and method orderings, which can lead to unexpected NullReferenceExceptions after apparently innocuous changes to the code. We refactored AuthorizationChecker
 to eliminate the dependency problems, but we did not address the elephant in the room—ScrewTurn.Wiki.Host. This article confronts the problems of ScrewTurn.Wiki.Host head-on in an effort to tame its wild ways.</p>
<h2>Another Look at Host</h2>
<p>Host’s primary purpose is to act as a facade between ScrewTurn Wiki’s plug-ins (aka “Providers”) and ScrewTurn Wiki itself. Host allows plug-ins to do everything from retrieving settings values to sending emails to handling backups to finding users, Wiki
 pages, namespaces, categories, and more, as shown in <b>Figure 1</b>.</p>
<p>&nbsp;</p>
<p><b>Figure 1 IHostV30</b></p>
<p>The plug-ins, which implement IProviderV30, are initialized with a Host instance and a configuration string through their Init method:</p>
<pre>public interface IProviderV30 {&nbsp;&nbsp;&nbsp; void Init(IHostV30 host, string config);&nbsp;&nbsp;&nbsp; void Shutdown();&nbsp;&nbsp;&nbsp; ComponentInformation Information { get; }&nbsp;&nbsp;&nbsp; string ConfigHelpHtml { get; }}</pre>
<br>
<p>Looking at Host’s constructor, no dependency problems are immediately evident:</p>
<pre>public class Host : IHostV30 {&nbsp;&nbsp;&nbsp; public Host() {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; customSpecialTags = new Dictionary&lt;string, CustomToolbarItem&gt;(5);&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; ...}</pre>
<br>
<p>The plug-in system seems fairly innocuous, but the devil is in the details. Let’s dig a little deeper and see what we find.</p>
<h2>The First Step is Realizing You Have a Problem</h2>
<p>Given Host’s role as a facade object for the plug-in system and its overly simplistic constructor, I suspect that there is a dependency problem lurking beneath the surface. So I have enrolled Host in Dependency-aholics Anonymous. The first step in this twelve-step
 program is to make Host’s dependencies obvious, just as we did in part 8 when working with AuthorizationChecker.</p>
<p>I’m not too concerned at the moment about static helper classes, such as ScrewTurn.Wiki.Tools or ScrewTurn.Wiki.Formatter. Static helper classes are often a rich source of inspiration for domain concepts. For example, if you have helper methods for performing
 arithmetic operations on currency, introduce a Money class to encapsulate the data and behavior. If you have helper methods comparing whole dates, introduce a Date class. Yes, .NET has a DateTime class, but it includes both the date and the time. Don’t be
 afraid to create a Date or Time class that is tailored to the needs of your application. If you deal with financial data, working with a strongly-typed FiscalPeriod class is going to be a lot easier than passing around DateTime objects and remembering to call
 Helpers.ConvertToFiscal(someDate) to ensure that the DateTime is properly aligned to a fiscal period.</p>
<p>But static helpers aren’t our concern at the moment because these are most often simple stateless methods that have little to no coupling to the rest of the application. We are looking for hidden dependencies that wind their tentacles insidiously throughout
 the application. The dependencies that have dependencies that have dependencies ad infinitum, resulting in unnecessary coupling and rigidity in the codebase. To find these, we need look no further than the Singletons to which Host delegates much of its responsibilities.</p>
<h2>Other videos from this article</h2>
<ul>
<li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Overview/" shape="rect">Overview</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Dependency/" shape="rect">Dependency</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Host-Users-Dependency-Cycle/" shape="rect">Host Users Dependency Cycle</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Circular-Dependency-Cycle/" shape="rect">Circular Dependency Cycle</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Refactoring-Notification/" shape="rect">Refactoring Notification</a>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/magazine/ee470637.aspx" shape="rect">
http://msdn.microsoft.com/magazine/ee470637.aspx</a></p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:b8b4eaec3e6847c2babd9deb0021129c">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Overview</comments>
      <itunes:summary>
Extreme ASP.NET Makeover: Mr. Escher, Your Software is Ready -Overview
We’re now on the ninth installment of Extreme ASP.NET Makeover. In part 8, we discovered that the ScrewTurn Wiki codebase suffers from dependency problems. Tight coupling of implementation classes caused by singletons and static classes result in a morass
 of objects, which is difficult to refactor. Dependency cycles between objects result in sensitive constructor and method orderings, which can lead to unexpected NullReferenceExceptions after apparently innocuous changes to the code. We refactored AuthorizationChecker
 to eliminate the dependency problems, but we did not address the elephant in the room—ScrewTurn.Wiki.Host. This article confronts the problems of ScrewTurn.Wiki.Host head-on in an effort to tame its wild ways. 
Another Look at Host
Host’s primary purpose is to act as a facade between ScrewTurn Wiki’s plug-ins (aka “Providers”) and ScrewTurn Wiki itself. Host allows plug-ins to do everything from retrieving settings values to sending emails to handling backups to finding users, Wiki
 pages, namespaces, categories, and more, as shown in Figure 1. 
&amp;nbsp; 
Figure 1 IHostV30 
The plug-ins, which implement IProviderV30, are initialized with a Host instance and a configuration string through their Init method: 
public interface IProviderV30 {&amp;nbsp;&amp;nbsp;&amp;nbsp; void Init(IHostV30 host, string config);&amp;nbsp;&amp;nbsp;&amp;nbsp; void Shutdown();&amp;nbsp;&amp;nbsp;&amp;nbsp; ComponentInformation Information { get; }&amp;nbsp;&amp;nbsp;&amp;nbsp; string ConfigHelpHtml { get; }}

Looking at Host’s constructor, no dependency problems are immediately evident: 
public class Host : IHostV30 {&amp;nbsp;&amp;nbsp;&amp;nbsp; public Host() {&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; customSpecialTags = new Dictionary&amp;lt;string, CustomToolbarItem&amp;gt;(5);&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; ...}

The plug-in system seems fairly innocuous, but the devil is in the details. Let’s dig a little deeper and see what we find. </itunes:summary>
      <itunes:duration>149</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Overview</link>
      <pubDate>Fri, 11 Sep 2009 18:17:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Overview</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/491005_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/491005_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/5/0/0/1/9/4/TheTroubleWithTribblesIMeanSingletons_320_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/5/0/0/1/9/4/TheTroubleWithTribblesIMeanSingletons_512_ch9.png" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/5/0/0/1/9/4/TheTroubleWithTribblesIMeanSingletons_85_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/5/0/0/1/9/4/TheTroubleWithTribblesIMeanSingletons_2MB_ch9.wmv" expression="full" duration="149" fileSize="4201320" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/5/0/0/1/9/4/TheTroubleWithTribblesIMeanSingletons_ch9.mp3" expression="full" duration="149" fileSize="1196183" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/5/0/0/1/9/4/TheTroubleWithTribblesIMeanSingletons_ch9.mp4" expression="full" duration="149" fileSize="4228634" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/5/0/0/1/9/4/TheTroubleWithTribblesIMeanSingletons_ch9.wma" expression="full" duration="149" fileSize="1218593" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/5/0/0/1/9/4/TheTroubleWithTribblesIMeanSingletons_ch9.wmv" expression="full" duration="149" fileSize="6103671" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/5/0/0/1/9/4/TheTroubleWithTribblesIMeanSingletons_Zune_ch9.wmv" expression="full" duration="149" fileSize="4215599" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/ch9/5/0/0/1/9/4/TheTroubleWithTribblesIMeanSingletons_s_ch9.wmv" expression="full" duration="149" fileSize="255" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/5/0/0/1/9/4/TheTroubleWithTribblesIMeanSingletons_ch9.wmv" length="6103671" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Mr-Escher-Your-Software-is-Ready-Overview/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
    </item>
  <item>
      <title>geekSpeak Recording - Composite Application Development with David Kelley</title>
      <description><![CDATA[In this geekSpeak, Microsoft Most Valuable Professional (MVP) David Kelley discusses composite application development in Microsoft Silverlight and Windows Presentation Foundation (WPF). He covers the Silverlight Designer/Developer workflow, tooling, design
 patterns, anti-practices, and working with distributed teams. Your hosts for this geekSpeak are
<a shape="rect" href="http://blogs.msdn.com/glengordon" shape="rect">Glen Gordon</a> and
<a shape="rect" href="http://blogs.msdn.com/mithund" shape="rect">Mithun Dhar</a>. Links and related resources mentioned in this episode can be found
<a shape="rect" href="http://blogs.msdn.com/geekspeak/archive/2009/09/03/resources-for-geekspeak-composite-application-development-with-david-kelley.aspx" shape="rect">
here</a>.<br>
<br>
The geekSpeak webcast series brings you industry experts in a &quot;talk-radio&quot; format hosted by developer evangelists from Microsoft. These experts share their knowledge and experience about a particular developer technology and are ready to answer your questions
 in real time during the webcast. To see upcoming live geekSpeaks, be sure to visit the
<a shape="rect" href="http://blogs.msdn.com/geekspeak/" shape="rect">geekSpeak blog</a>.<br>
<br>
<strong>Guest Info:</strong> David Kelley, Senior Software Architect, IdentityMine
<br>
<div id="details_bio"><br>
David Kelley is a Microsoft Most Valuable Professional (MVP) for Microsoft Silverlight, and he has been building Web-based, distributed applications for more than ten years. He is a Silverlight user experience architect at IdentityMine, and his passion is building
 user experiences that are elegant and easy to use.&nbsp;David's career highlights include a Silverlight demonstration with Bill Gates at TechEd 2008, and developing the &quot;Entertainment Tonight&quot; Web site for the Silverlight 1 launch and Emmy Awards. In his spare
 time, David is the executive officer of the Seattle Designer Developer Interaction Group.</div>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:1c08ad8ff3c74cb3a0919dea00c2502e">]]></description>
      <comments>http://channel9.msdn.com/Shows/geekSpeak/geekSpeak-Recording-Composite-Application-Development-with-David-Kelley</comments>
      <itunes:summary>In this geekSpeak, Microsoft Most Valuable Professional (MVP) David Kelley discusses composite application development in Microsoft Silverlight and Windows Presentation Foundation (WPF). He covers the Silverlight Designer/Developer workflow, tooling, design
 patterns, anti-practices, and working with distributed teams. Your hosts for this geekSpeak are
Glen Gordon and
Mithun Dhar. Links and related resources mentioned in this episode can be found

here.

The geekSpeak webcast series brings you industry experts in a &amp;quot;talk-radio&amp;quot; format hosted by developer evangelists from Microsoft. These experts share their knowledge and experience about a particular developer technology and are ready to answer your questions
 in real time during the webcast. To see upcoming live geekSpeaks, be sure to visit the
geekSpeak blog.

Guest Info: David Kelley, Senior Software Architect, IdentityMine


David Kelley is a Microsoft Most Valuable Professional (MVP) for Microsoft Silverlight, and he has been building Web-based, distributed applications for more than ten years. He is a Silverlight user experience architect at IdentityMine, and his passion is building
 user experiences that are elegant and easy to use.&amp;nbsp;David&#39;s career highlights include a Silverlight demonstration with Bill Gates at TechEd 2008, and developing the &amp;quot;Entertainment Tonight&amp;quot; Web site for the Silverlight 1 launch and Emmy Awards. In his spare
 time, David is the executive officer of the Seattle Designer Developer Interaction Group.
</itunes:summary>
      <itunes:duration>3727</itunes:duration>
      <link>http://channel9.msdn.com/Shows/geekSpeak/geekSpeak-Recording-Composite-Application-Development-with-David-Kelley</link>
      <pubDate>Thu, 03 Sep 2009 21:55:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Shows/geekSpeak/geekSpeak-Recording-Composite-Application-Development-with-David-Kelley</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/320/f4c19b6f-8d5f-41ad-bdbc-b4433d3aa1a6.jpg" height="0" width="0"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/489535_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/489535_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/85/107db419-d793-4746-9d50-e6cdef2d97d7.jpg" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://msbmopod.vo.llnwd.net/d1/webcastaudio/1032422054.mp3" expression="full" duration="3727" fileSize="11290346" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://msbmopod.vo.llnwd.net/d1/webcastaudio/1032422054.wma" expression="full" duration="3727" fileSize="15388385" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://msbmopod.vo.llnwd.net/d1/webcasts/wmv/1032422054_Dnl_L.wmv" expression="full" duration="3727" fileSize="15745088" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://msbmopod.vo.llnwd.net/d1/webcasts/zune/1032422054_Dnl_S.wmv" expression="full" duration="3727" fileSize="18751860" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://msnvideo.wmod.llnwd.net/a392/d1/cmg/events/webcasts/1032422054_Str.wmv" expression="full" duration="3727" fileSize="200" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://msbmopod.vo.llnwd.net/d1/webcasts/wmv/1032422054_Dnl_L.wmv" length="15745088" type="video/x-ms-wmv"></enclosure>
      <dc:creator>glengo</dc:creator>
      <itunes:author>glengo</itunes:author>
      <slash:comments>1</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Shows/geekSpeak/geekSpeak-Recording-Composite-Application-Development-with-David-Kelley/RSS</wfw:commentRss>
      <category>Patterns</category>
      <category>Silverlight</category>
      <category>WPF</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: Disentangling Our Tangled Web-Overview - Refactoring</title>
      <description><![CDATA[
<h2>A Topsy-Turvy World</h2>
<p>The constructor signature for AuthorizationChecker now looks like this:</p>
<pre>public AuthorizationChecker(    ISettingsStorageProviderV30 settingsProvider,     IAuthTools authTools,     IAclEvaluator aclEvaluator) { ... }</pre>
<br>
<p>We can clearly see that AuthorizationChecker depends on implementations of ISettingsStorageProviderV30, IAuthTools, and IAclEvalator, but we are not concerned with the actual implementations. This is the dependency inversion principle at work.</p>
<p><i>&quot;High-level modules should not depend on low-level modules. Both should depend on abstractions.&quot;</i> – Robert C. Martin (<a shape="rect" href="http://objectmentor.com/resources/articles/dip.pdf" shape="rect">http://objectmentor.com/resources/articles/dip.pdf</a>)</p>
<p>In this case, AuthorizationChecker and AuthTools don’t depend on each other, but depend on the abstraction provided by IAuthTools. The same is true for AuthorizationChecker’s other two dependencies, ISettingsStorageProviderV30 and IAclEvaluator.</p>
<p>We have decoupled AuthorizationChecker from its dependencies. The question remains that AuthorizationChecker still needs these dependencies supplied at run-time to actually be able to execute. The simplest way to supply these dependences as default implementations
 via AuthorizationChecker's parameterless constructor:</p>
<pre>public AuthorizationChecker() :     this(Settings.Instance.Provider,         new AuthTools(), new AclEvaluator()) {}</pre>
<br>
<h2>Of Containers and Castles</h2>
<p>A more flexible way to supply dependencies is to use an Inversion of Control container, such as
<a shape="rect" href="http://castleproject.org/container/index.html" shape="rect">
Castle Windsor</a>. Castle Windsor is a set of assemblies that we reference from our code. We simply register all of our dependencies in the container and then ask the container for an implementation. The container walks the dependency chain, creates objects
 in the correct order, supplying dependencies as it creates objects further up the dependency chain until it can finally return us a fully constructed object. Consider the following code:</p>
<pre>var authorizationServices = IoC.Resolve&lt;IAuthorizationServices&gt;();</pre>
<br>
<p>The IoC is a static gateway class that provides an abstraction so that your code is not dependent on a particular IoC container for retrieving dependencies. It is similar in interface and approach to Microsoft’s
<a shape="rect" href="http://commonservicelocator.codeplex.com/" shape="rect">Common Service Locator</a> available on CodePlex. You can read more about the IoC static gateway in
<a shape="rect" href="http://msdn.microsoft.com/en-us/magazine/cc337885.aspx" shape="rect">
“Loosen Up: Tame Your Software Dependencies for More Flexible Apps”</a>.</p>
<p>In order for Castle Windsor to satisfy this request for an implementation of IAuthorizationServices, we’ll need to register the dependencies:</p>
<pre>var ssp = ProviderLoader.LoadSettingsStorageProvider(    WebConfigurationManager.AppSettings[&quot;SettingsStorageProvider&quot;]);container.Register(    AllTypes.FromAssembly(Assembly.GetExecutingAssembly())        .Where(x =&gt; x.Namespace.StartsWith(&quot;ScrewTurn.Wiki.Services&quot;))        .WithService.FirstInterface(),    Component.For&lt;IAclEvaluator&gt;().ImplementedBy&lt;AclEvaluator&gt;(),    Component.For&lt;ISettingsStorageProviderV30&gt;().Instance(ssp));</pre>
<br>
<p>This code is located in the ScrewTurn.Wiki.Core assembly. Rather than manually configuring each dependency individually, we use a convention-based approach whereby any types in the ScrewTurn.Wiki.Services namespace are registered via their first interface.
 This means that AuthorizationServices is registered as IAuthorizationServices, AuthTools is registered as IAuthTools, and similarly for other types in this namespace. This has the advantage that by placing services in the ScrewTurn.Wiki.Services namespace,
 they will automatically be registered in the container without requiring explicit configuration. Other classes can then take dependencies on these services simply by adding the appropriate interface to their own constructor.</p>
<p>AclEvaluator is located in the ScrewTurn.Wiki.AclEngine assembly. Since it is the only dependency in this assembly, we register it explicitly. There isn’t a great deal of value from having a separate assembly for ScrewTurn.Wiki.AclEngine and I would consider
 merging the AclEngine project into Core. AclEvaluator could then be placed in the ScrewTurn.Wiki.Services namespace and auto-registered like the other dependencies. For the moment, AclEvaluator serves as an example of how to explicitly configure dependencies
 in Castle Windsor.</p>
<p>ScrewTurn Wiki has code that dynamically loads a particular ISettingsStorageProviderV30 implementation specified by a fully qualified class name in a configuration file. Although we could use Castle Windsor’s configuration facilities to configure and load
 the appropriate assembly and implementation, that is not the current focus. We can leverage the existing loading mechanism by supplying Castle Windsor with a fully constructed instance via the Component.For&lt;T&gt;().Instance(obj) syntax.</p>
<p>Windsor provides many more configuration options, including overrides, parameters, XML configuration, and more. You can find a lot more information on configuration options in Castle Windsor in my article,
<a shape="rect" href="http://code-magazine.com/Article.aspx?quickid=0906051" shape="rect">
Bricks and Mortar: Building a Castle</a>.</p>
<p>Now that AuthorizationServices and all of its dependencies have been registered with the container, we can successfully resolve it from the container:</p>
<pre>var authorizationServices = IoC.Resolve&lt;IAuthorizationServices&gt;();</pre>
<br>
<p>To service this request, Windsor will look for an implementer of IAuthorizationServices, which is AuthorizationServices. Windsor will then examine AuthorizationServices constructor, specifically the constructor parameters:</p>
<pre>public AuthorizationServices(IAuthorizationChecker authorizationChecker) {    this.authorizationChecker = authorizationChecker;}</pre>
<br>
<p>Windsor will look to see if it has an implementation registered for IAuthorizationChecker, which it does in the form of AuthorizationChecker. Looking at AuthorizationChecker’s constructors:</p>
<pre>public AuthorizationChecker() : this(Settings.Instance.Provider,     new AuthTools(), new AclEvaluator()) {}public AuthorizationChecker(ISettingsStorageProviderV30 settingsProvider,     IAuthTools authTools, IAclEvaluator aclEvaluator) {&nbsp;&nbsp;&nbsp; ...}</pre>
<br>
<p>Windsor has two constructors to choose from. It starts from the constructor with the most overloads. It will see if it has implementations for all of the constructor parameters. (If it can’t find implementations for all constructor parameters, Windsor will
 attempt the next most overloaded constructor.) In this case, it will see that it needs to find an implementation for ISettingsStorageProviderV30, IAuthTools, and IAclEvaluator. Windsor has an instance of ISettingsStorageProviderV30 that we supplied to it earlier.
 It can also create instances of AuthTools and AclEvaluator because they have no further dependencies. Windsor passes the newly created AuthTools and AclEvaluator, as well as the pre-built ISettingsStorageProviderV30 to AuthorizationChecker’s constructor. Windsor
 then passes the newly created AuthorizationChecker to AuthorizationServices’ constructor. Finally, Windsor is able to pass back AuthorizationServices to satisfy the call to IoC.Resolve&lt;IAuthorizationServices&gt;.</p>
<p>Note that Windsor is responsible for managing the lifetime of objects registered in the container. Windsor’s default lifetime strategy is singleton. That means that multiple classes depending on IAuthorizationServices will all receive the same instance of
 AuthorizationServices. This instancing policy is easily changed on a per-service basis and includes options such as per-thread, per-Web-request, transient, and pooled. You can even create your own instancing policies if none of the built-in ones are appropriate.</p>
<p>With the container responsible for wiring dependencies between objects, we can remove the parameterless constructors as they are no longer required:</p>
<pre>public AuthorizationChecker(ISettingsStorageProviderV30 settingsProvider,     IAuthTools authTools, IAclEvaluator aclEvaluator) {     ...}</pre>
<br>
<p>If AuthorizationChecker required another dependency, we would simply declare that fact by adding another constructor parameter with a type of the required service interface. We would then create a concrete class in the ScrewTurn.Wiki.Services namespace that
 implements that service interface.</p>
<h2>Managing the Container</h2>
<p>I have seen many projects place all container configuration into a single XML or C# file. This is especially unwieldy if explicitly configuring dependencies individually, which is why I prefer the convention-over-configuration approach discussed above. By
 placing dependencies in certain assemblies and namespaces, they are automatically registered. (Note that the convention-over-configuration approach is not available with XML files, although XML files are useful for specifying deployment-time overrides if necessary.
 For more information about this technique, see <a shape="rect" href="http://code-magazine.com/Article.aspx?quickid=0906051" shape="rect">
Bricks and Mortar: Building a Castle</a>.) Placing all of our conventions in a single C# file can quickly become cumbersome as we have unrelated conventions bundled together.</p>
<p>Let’s take a look at an approach that allows us to separate our conventions into smaller, simpler classes. It all starts with the ApplicationBootstrapper, which is called during application startup:</p>
<pre>public void Configure() {    container = new WindsorContainer();    IoC.Initialize(new WindsorDependencyResolver(container));&nbsp;&nbsp;&nbsp; RegisterFacilityStartupTasks();&nbsp;&nbsp;&nbsp; ExecuteFacilityStartupTasks();&nbsp;&nbsp;&nbsp; RegisterContainerStartupTasks();&nbsp;&nbsp;&nbsp; ExecuteContainerStartupTasks();&nbsp;&nbsp;&nbsp; RegisterStartupTasks();&nbsp;&nbsp;&nbsp; ExecuteStartupTasks();}</pre>
<br>
<p>We start by creating a new WindsorContainer and using it to initialize the IoC static gateway. We then alternately register and execute FacilityStartup, ContainerStartup, and Startup tasks, as shown in
<b>Figure 2</b>.</p>
<p><b>Figure 2 Execute FacilityStartup, ContainerStartup, and Startup Tasks</b></p>
<pre>private void RegisterFacilityStartupTasks() {&nbsp;&nbsp;&nbsp; RegisterAllTypesBasedOn&lt;IFacilityStartupTask&gt;();}private void RegisterContainerStartupTasks() {    RegisterAllTypesBasedOn&lt;IContainerStartupTask&gt;();}private void RegisterStartupTasks() {&nbsp;&nbsp; RegisterAllTypesBasedOn&lt;IStartupTask&gt;();}private void RegisterAllTypesBasedOn&lt;T&gt;() {&nbsp;&nbsp;&nbsp; assembliesToScan.ForEach(assembly =&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; container.Register(&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; AllTypes.FromAssembly(assembly)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; .BasedOn&lt;T&gt;()&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .WithService.FirstInterface())&nbsp;&nbsp;&nbsp; );}</pre>
<br>
<p>The list of assemblies to scan for startup tasks is provided via AssemblyBootstrapper’s constructor and defaults to Assembly.GetExecutingAssembly if left unspecified. We look through each assembly for types implementing IFacilityStartupTask, IContainerStartupTask,
 and IStartupTask and register them against the appropriate interface. (Facilities are Windsor’s primary extension mechanism. You can use facilities to implement everything from automatic transaction management to logging to array parameter resolution and more.)
 Next, we need to execute each of the startup tasks:</p>
<pre>private void ExecuteFacilityStartupTasks() {&nbsp;&nbsp;&nbsp; var tasks = container.ResolveAll&lt;IFacilityStartupTask&gt;();&nbsp;&nbsp;&nbsp; tasks.ForEach(task =&gt; task.Execute(container));}private void ExecuteContainerStartupTasks() {&nbsp;&nbsp;&nbsp; var tasks = container.ResolveAll&lt;IContainerStartupTask&gt;();&nbsp;&nbsp;&nbsp; tasks.ForEach(task =&gt; task.Execute(container));}private void ExecuteStartupTasks() {&nbsp;&nbsp;&nbsp; var tasks = container.ResolveAll&lt;IStartupTask&gt;();&nbsp;&nbsp;&nbsp; tasks.ForEach(task =&gt; task.Execute());}</pre>
<br>
<p>Note that IFacilityStartupTask|IContainerStartupTask.Execute both take an IWindsorContainer, as their purpose is to configure the container. IStartupTask.Execute is to perform other types of initialization once the container is ready to be used and therefore
 doesn’t accept an IWindsorContainer.</p>
<p>The individual startup tasks are small and self-contained. For example, take a look at the ServiceRegistration class, which is responsible for registering application-related services:</p>
<pre>public class ServicesRegistration : IContainerStartupTask {&nbsp;&nbsp;&nbsp; public void Execute(IWindsorContainer container) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; container.Register(&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; AllTypes.FromAssembly(Assembly.GetExecutingAssembly())&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .Where(x =&gt; x.Namespace.StartsWith(&quot;ScrewTurn.Wiki.Services&quot;))&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .WithService.FirstInterface(),&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Component.For&lt;IAclEvaluator&gt;().ImplementedBy&lt;AclEvaluator&gt;()&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; );&nbsp;&nbsp;&nbsp; }}</pre>
<br>
<p>You can see the convention responsible for registering all services in the ScrewTurn.Wiki.Services namespace. There is also the extra configuration for the AclEvaluator. If we choose to combine the AclEngine project into Core, we could eliminate the extra
 configuration step for AclEvaluator.</p>
<p>We have a completely separate and independent IContainerStartupTask for Host and Provider registration:</p>
<pre>public class HostAndProviderRegistration : IContainerStartupTask {&nbsp;&nbsp;&nbsp; public void Execute(IWindsorContainer container) {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; container.Register(&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Component.For&lt;IHostV30&gt;().ImplementedBy&lt;Host&gt;());&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var ssp = ProviderLoader.LoadSettingsStorageProvider(            WebConfigurationManager.AppSettings[&quot;SettingsStorageProvider&quot;]);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; container.Register(            Component.For&lt;ISettingsStorageProviderV30&gt;().Instance(ssp));&nbsp;&nbsp;&nbsp; }}</pre>
<br>
<p>As we break apart the “God object” that is the Host, we can modify its container registration in one place without affecting the registration of the services. If we need to perform additional unrelated container configuration, we create another class that
 implements the IFacilityStartupTask or IContainerStartupTask without affecting other configuration that is already taking place.</p>
<p>To wrap up, let’s refactor StartupTools.Startup() into a IStartupTask where it belongs:</p>
<h2>Conclusion</h2>
<p>Although it is not initially obvious, the ScrewTurn Wiki codebase suffers from dependency problems. Tight coupling of implementation classes caused by singletons and static classes result in a morass of objects, which is difficult to refactor. Dependency
 cycles between objects result in sensitive constructor and method orderings, which can result in unexpected NullReferenceExceptions after apparently innocuous changes to the code.</p>
<p>In this article, we have made dependencies obvious by changing them into constructor parameters and using an IoC container to wire together the dependencies. Using convention-over-configuration approaches eases the introduction of new functionality, without
 requiring explicit configuration. We have introduced a reusable ApplicationBootstrapper, whereby new startup tasks can be added as the application grows without modifying existing code. The resulting codebase should be more flexible and maintainable over time.</p>
<h2>Other videos from this article</h2>
<ul>
<li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Disentangling-Our-Tangled-Web-Overview-Overview/" shape="rect">Overview</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Disentangling-Our-Tangled-Web-Overview-Refactoring/" shape="rect">Refactoring</a>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/magazine/ee424155.aspx" shape="rect">
http://msdn.microsoft.com/magazine/ee424155.aspx</a> </p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:ade3e4a857ed42b6909d9deb017702ef">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Disentangling-Our-Tangled-Web-Overview-Refactoring</comments>
      <itunes:summary>
A Topsy-Turvy World
The constructor signature for AuthorizationChecker now looks like this: 
public AuthorizationChecker(    ISettingsStorageProviderV30 settingsProvider,     IAuthTools authTools,     IAclEvaluator aclEvaluator) { ... }

We can clearly see that AuthorizationChecker depends on implementations of ISettingsStorageProviderV30, IAuthTools, and IAclEvalator, but we are not concerned with the actual implementations. This is the dependency inversion principle at work. 
&amp;quot;High-level modules should not depend on low-level modules. Both should depend on abstractions.&amp;quot; – Robert C. Martin (http://objectmentor.com/resources/articles/dip.pdf) 
In this case, AuthorizationChecker and AuthTools don’t depend on each other, but depend on the abstraction provided by IAuthTools. The same is true for AuthorizationChecker’s other two dependencies, ISettingsStorageProviderV30 and IAclEvaluator. 
We have decoupled AuthorizationChecker from its dependencies. The question remains that AuthorizationChecker still needs these dependencies supplied at run-time to actually be able to execute. The simplest way to supply these dependences as default implementations
 via AuthorizationChecker&#39;s parameterless constructor: 
public AuthorizationChecker() :     this(Settings.Instance.Provider,         new AuthTools(), new AclEvaluator()) {}

Of Containers and Castles
A more flexible way to supply dependencies is to use an Inversion of Control container, such as

Castle Windsor. Castle Windsor is a set of assemblies that we reference from our code. We simply register all of our dependencies in the container and then ask the container for an implementation. The container walks the dependency chain, creates objects
 in the correct order, supplying dependencies as it creates objects further up the dependency chain until it can finally return us a fully constructed object. Consider the following code: 
var authorizationServices = IoC.Resolve&amp;lt;IAuthorizationS</itunes:summary>
      <itunes:duration>896</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Disentangling-Our-Tangled-Web-Overview-Refactoring</link>
      <pubDate>Tue, 01 Sep 2009 00:10:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Disentangling-Our-Tangled-Web-Overview-Refactoring</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/487028_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/487028_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/8/2/0/7/8/4/RefactoringStartupTools_320_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/8/2/0/7/8/4/RefactoringStartupTools_512_ch9.png" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/8/2/0/7/8/4/RefactoringStartupTools_85_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/8/2/0/7/8/4/RefactoringStartupTools_2MB_ch9.wmv" expression="full" duration="896" fileSize="35996878" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/8/2/0/7/8/4/RefactoringStartupTools_ch9.mp3" expression="full" duration="896" fileSize="7171341" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/8/2/0/7/8/4/RefactoringStartupTools_ch9.mp4" expression="full" duration="896" fileSize="27337695" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/8/2/0/7/8/4/RefactoringStartupTools_ch9.wma" expression="full" duration="896" fileSize="7259631" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/8/2/0/7/8/4/RefactoringStartupTools_ch9.wmv" expression="full" duration="896" fileSize="43586123" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/8/2/0/7/8/4/RefactoringStartupTools_Zune_ch9.wmv" expression="full" duration="896" fileSize="27442051" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/ch9/8/2/0/7/8/4/RefactoringStartupTools_s_ch9.wmv" expression="full" duration="896" fileSize="227" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/8/2/0/7/8/4/RefactoringStartupTools_ch9.wmv" length="43586123" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Disentangling-Our-Tangled-Web-Overview-Refactoring/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
      <category>Singleton</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: Disentangling Our Tangled Web-Overview - Overview</title>
      <description><![CDATA[
<p>We’re now on the eighth installment of Extreme ASP.NET Makeover. In part 7, we examined the singleton pattern and refactored away the AuthChecker singleton. AuthorizationServices, which previously used the AuthChecker singleton, now depends on the IAuthorizationChecker
 interface and simply creates an instance of the AuthorizationChecker class in its constructor by calling the new operator. In this intallment, we will discuss better ways to manage dependencies in our applications using an inversion of control container. If
 you are not familiar with inversion of control containers or the related concepts of dependency inversion and dependency injection, take some time to read James’ article on those topics from the March 2008 issue of
<i>MSDN Magazine</i>, <a shape="rect" href="http://msdn.microsoft.com/en-us/magazine/cc337885.aspx" shape="rect">
“Loosen Up: Tame Your Software Dependencies for More Flexible Apps.”</a></p>
<h2>The Tangled Web we Weave</h2>
<p>Let’s take a closer look at AuthorizationServices. AuthorizationServices depends on IAuthorizationChecker, which is implemented by AuthorizationChecker. In turn, AuthorizationChecker depends on Settings to retrieve the configured ISettingsStorageProviderV30,
 which can be a SettingsStorageProvider, SqlSettingsStorageProvider, or other implementation. Now, SettingsStorageProvider depends on IHostV30 and its default implementation by Host. Host is a “God object” in ScrewTurn Wiki. According to Wikipedia, “a
<a shape="rect" href="http://en.wikipedia.org/wiki/God_object" shape="rect">God object</a> is an object that
<i>knows too much</i> or <i>&nbsp;does too much</i>.” A God object is a software anti-pattern.</p>
<p>Host is a coordinator of a wide variety of unrelated activities in ScrewTurn. It handles everything from retrieving settings values to sending emails to handling backups to finding users, Wiki pages, namespaces, categories, and more.
</p>
<p>Many of these responsibilities are delegated to sub-objects, and Host only acts as the coordinator of these services. This is better than having all that functionality actually coded in Host itself. Host does still present a problem in that its delicate
 coordination of all the other objects in the system, especially during application startup, means that it is difficult to refactor the overall system. Moving startup code from one class to another causes breakages as the ordering of construction is slightly
 changed and previously working code throws NullReferenceExceptions as dependencies are unexpectedly null due to construction orderings.</p>
<p>Let’s take a look at Host’s constructor:</p>
<pre>public Host() {    customSpecialTags = new Dictionary&lt;string, CustomToolbarItem&gt;(5);}</pre>
<br>
<p>In its constructor, Host creates a single Dictionary. There is no indication that Host has a dependency problem. Host’s tangled web of dependencies is hidden due to its overuse of Singletons and static helper classes. For example, let’s take a look at a
 few Host methods:</p>
<pre>public UserInfo[] GetUsers() {     return Users.Instance.GetUsers().ToArray();}public PageContent GetPageContent(PageInfo page) {    return Content.GetPageContent(page, true);}public string Format(string raw) {    return Formatter.Format(raw, FormattingContext.Unknown, null);}</pre>
<br>
<p>Note the use of the Users singleton and the static Content an Formatter classes in the above code. Without actually looking at Host’s implementation code, there is no way to tell that it depends on these other classes. To make matters even more complicated,
 Users (and other dependent classes) depend on Host! If constructors aren’t run in the correct order and before certain methods are called, NullReferenceExceptions will be your reward. All of the construction logic is carefully orchestrated by StartupTools,
 which is responsible for constructing and initializing all singletons within the application in the correct order.</p>
<h2>Seeking Salvation</h2>
<p>God objects lead us down a road unto madness. Host’s dependencies are so tangled and interdependent that the result is only somewhat better than a single, monolithic object. So how do we chart a course back to sanity?</p>
<p>Dependencies in software are not fundamentally the problem here. Without dependencies, we wouldn’t be able to write much more than “Hello, World!”-style applications. (Even a simple application like Hello, World! &nbsp;requires dependencies on System.Console
 and System.String, as well as the CLR.) The problem is unchecked and unfettered dependencies between objects that do not need to know about each other. Before we can solve the problem of unnecessary dependencies, we need to make those dependencies obvious.
 How can we construct our classes/objects so that their dependencies are obvious? Make dependencies apparent by declaring them in the classes constructor. For example, let’s look at AuthorizationServices’ constructor:</p>
<pre>public AuthorizationServices(IAuthorizationChecker authorizationChecker) {    this.authorizationChecker = authorizationChecker;}</pre>
<br>
<p>Simply by looking at the constructor’s signature, we can tell that AuthorizationServices requires an IAuthorizationChecker to perform its work. (You probably already knew that because we implemented it in part 7.) The concrete implementation of IAuthorizationChecker
 is AuthorizationChecker:</p>
<pre>public AuthorizationChecker() {    settingsProvider = Settings.Instance.Provider;}</pre>
<br>
<p>Notice that you don’t know that AuthorizationChecker depends on the static Settings class. You have to read AuthorizationChecker’s constructor implementation to figure this out. While not hard, it is not immediately obvious that AuthorizationChecker depends
 on ISettingsStorageProviderV30, which is the type return by the Provider property. How can we make this more obvious? By declaring our intent in the constructor parameters, like so:</p>
<pre>public AuthorizationChecker() : this(Settings.Instance.Provider) {}public AuthorizationChecker(ISettingsStorageProviderV30 settingsProvider) {    if(settingsProvider == null)        throw new ArgumentNullException(&quot;settingsProvider&quot;);    this.settingsProvider = settingsProvider;}</pre>
<br>
<p>Our other code depends on the parameterless constructor. We will leave it in place for now and chain to an overloaded constructor that takes a ISettingsStorageProviderV30. Our dependency on ISettingsStorageProviderV30 has now been made obvious.</p>
<p>We are not out of the proverbial woods yet. Other dependencies are lurking within AuthorizationChecker, namely the static classes AuthTools and AclEvaluator. We can make them obvious dependencies by changing them from static classes to instances and moving
 their initialization to the constructor.</p>
<h2>Other videos from this article</h2>
<ul>
<li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Disentangling-Our-Tangled-Web-Overview-Overview/" shape="rect">Overview</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Disentangling-Our-Tangled-Web-Overview-Refactoring/" shape="rect">Refactoring</a>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/magazine/ee424155.aspx" shape="rect">
http://msdn.microsoft.com/magazine/ee424155.aspx</a> </p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:41983cd281ff442fbd749deb01770749">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Disentangling-Our-Tangled-Web-Overview-Overview</comments>
      <itunes:summary>
We’re now on the eighth installment of Extreme ASP.NET Makeover. In part 7, we examined the singleton pattern and refactored away the AuthChecker singleton. AuthorizationServices, which previously used the AuthChecker singleton, now depends on the IAuthorizationChecker
 interface and simply creates an instance of the AuthorizationChecker class in its constructor by calling the new operator. In this intallment, we will discuss better ways to manage dependencies in our applications using an inversion of control container. If
 you are not familiar with inversion of control containers or the related concepts of dependency inversion and dependency injection, take some time to read James’ article on those topics from the March 2008 issue of
MSDN Magazine, 
“Loosen Up: Tame Your Software Dependencies for More Flexible Apps.” 
The Tangled Web we Weave
Let’s take a closer look at AuthorizationServices. AuthorizationServices depends on IAuthorizationChecker, which is implemented by AuthorizationChecker. In turn, AuthorizationChecker depends on Settings to retrieve the configured ISettingsStorageProviderV30,
 which can be a SettingsStorageProvider, SqlSettingsStorageProvider, or other implementation. Now, SettingsStorageProvider depends on IHostV30 and its default implementation by Host. Host is a “God object” in ScrewTurn Wiki. According to Wikipedia, “a
God object is an object that
knows too much or &amp;nbsp;does too much.” A God object is a software anti-pattern. 
Host is a coordinator of a wide variety of unrelated activities in ScrewTurn. It handles everything from retrieving settings values to sending emails to handling backups to finding users, Wiki pages, namespaces, categories, and more.
 
Many of these responsibilities are delegated to sub-objects, and Host only acts as the coordinator of these services. This is better than having all that functionality actually coded in Host itself. Host does still present a problem in that its delicate
 coordination of </itunes:summary>
      <itunes:duration>585</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Disentangling-Our-Tangled-Web-Overview-Overview</link>
      <pubDate>Tue, 01 Sep 2009 00:10:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Disentangling-Our-Tangled-Web-Overview-Overview</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/487027_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/487027_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/7/2/0/7/8/4/RefactoringDependenciesIntoTheConstructor_320_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/7/2/0/7/8/4/RefactoringDependenciesIntoTheConstructor_512_ch9.png" height="384" width="512"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/ch9/7/2/0/7/8/4/RefactoringDependenciesIntoTheConstructor_85_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/2/0/7/8/4/RefactoringDependenciesIntoTheConstructor_2MB_ch9.wmv" expression="full" duration="585" fileSize="30333124" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/2/0/7/8/4/RefactoringDependenciesIntoTheConstructor_ch9.mp3" expression="full" duration="585" fileSize="4683433" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/2/0/7/8/4/RefactoringDependenciesIntoTheConstructor_ch9.mp4" expression="full" duration="585" fileSize="19350270" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/2/0/7/8/4/RefactoringDependenciesIntoTheConstructor_ch9.wma" expression="full" duration="585" fileSize="4745289" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/2/0/7/8/4/RefactoringDependenciesIntoTheConstructor_ch9.wmv" expression="full" duration="585" fileSize="34717775" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ecn.channel9.msdn.com/o9/ch9/7/2/0/7/8/4/RefactoringDependenciesIntoTheConstructor_Zune_ch9.wmv" expression="full" duration="585" fileSize="19469703" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/ch9/7/2/0/7/8/4/RefactoringDependenciesIntoTheConstructor_s_ch9.wmv" expression="full" duration="585" fileSize="263" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ecn.channel9.msdn.com/o9/ch9/7/2/0/7/8/4/RefactoringDependenciesIntoTheConstructor_ch9.wmv" length="34717775" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Disentangling-Our-Tangled-Web-Overview-Overview/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
      <category>Singleton</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: Singleton - Refactoring</title>
      <description><![CDATA[
<h1>Extreme ASP.NET Makeover: Death of a Singleton-Refactoring</h1>
<p>Now that we have a new class, complete with functionality, we can start to refactor other parts of the application to use it instead of the AuthChecker singleton.&nbsp; Like all the other refactorings we’ve done thus far in this article, it’s not that big of
 a deal.&nbsp; As our example, we’re going to continue to refactor the AuthorizationServices class (see the
<a shape="rect" href="http://msdn.microsoft.com/en-us/magazine/ee210417.aspx" shape="rect">
previous Separation of Concerns article</a> for the initial refactoring for this).&nbsp; In AuthorizationServices, we want to eliminate the use of AuthChecker and, in its place, use an instance of AuthorizationChecker instead.</p>
<p>To do this, we first need to create a module level variable that provides the same capabilities as the AuthChecker singleton.&nbsp; Earlier in this article, we created an IAuthenticationChecker interface that worked to enforce this for us.&nbsp; Now is another time
 that we can use it.&nbsp; As you can see in the code below, we now have created an instance of the AuthenticationChecker and assigned it to the module level variable:</p>
<pre>public class AuthorizationServices{    private IAuthorizationChecker _authenticationChecker;    public AuthorizationServices()    {        authorizationChecker = new AuthorizationChecker();    }    ...}</pre>
<br>
<p>Now that we have a way to access the authentication checking code, we just need to replace the AuthChecker calls in the RetrieveCurrentStatusFor method with calls to the module level variable.&nbsp; As an example of these changes, here is what the first one would
 look like:</p>
<pre>CanView = _authorizationChecker.CheckActionForPage(currentPage,     Actions.ForPages.ReadPage, currentUsername, currentGroups),</pre>
<br>
<p>With that we have our AuthorizationServices class refactored and we’ve finished the first full round of changes that are required to eliminate the AuthChecker singleton.&nbsp; If we take a look at the usages of the AuthChecker singleton instance, we’ll see that
 there are still a large number of places that it is being used.</p>
<p>Now that you’ve finished this first complete refactoring to use the new AuthorizationChecker class, you’ve also reached the first logical checkpoint in your refactoring exercise.&nbsp; From here you can choose when you want to move from the AuthChecker singleton
 to an AuthorizationChecker instance class in any of the other places that AuthChecker is being used.&nbsp; As you incrementally move through your changes from AuthChecker to AuthorizationChecker, you get closer and closer to the next step in this refactoring: deleting
 the AuthChecker singleton.</p>
<p>Once you have all of the usages of AuthChecker replaced with the AuthorizationChecker class you’re almost ready to remove the AuthChecker class from your code base.&nbsp; Before we can do that, remember that we had the new AuthorizationChecker class delegating
 execution to the AuthChecker singleton.&nbsp; To be able to get rid of AuthChecker completely, we need to move its logic into the new AuthorizationChecker class.&nbsp; There are a couple of small things that we need to address in this refactoring, such as adding using
 statements.&nbsp;&nbsp; </p>
<p>The main change we need is to address the code’s need for an ISettingsStorageProviderV30 typed object.&nbsp; If we look into how that object is being passed into the AuthChecker singleton, we see that it’s actually being provided from another singleton named
 Settings:</p>
<pre>AuthChecker.Instance = new AuthChecker(Settings.Instance.Provider);</pre>
<br>
<p>&nbsp;</p>
<p>Since this value is coming from a singleton, we can easily add a module level variable to AuthorizationChecker that can be used throughout its methods.&nbsp; Assigning that variable is as simple as what you see below.&nbsp; Also note that we no longer need the module
 level AuthChecker variable since we’ve now moved all of the AuthChecker code into this class.&nbsp; Since it’s not needed, we’ve removed it and the code related to it in the constructor:</p>
<pre>private ISettingsStorageProviderV30 _settingsProvider; public AuthorizationChecker(){    _settingsProvider = Settings.Instance.Provider;}</pre>
<br>
<p>The result of this final refactoring is that the public methods on AuthChecker are no longer being executed anywhere in the code base.&nbsp; If you were to do a Find Usages on AuthChecker, you’ll see that the only place it exists is in the StartupTools class
 where it was being initialized.&nbsp; Since it’s not being used anywhere, there’s no need to initialize it, so we’ll just delete that line of code.&nbsp; Now we’re completely free of any use of AuthChecker, so we can delete the class from the project.&nbsp; With that, you’re
 free of your singleton past...or at least one part of it.</p>
<h1>I realized what a ridiculous lie my whole life has been...</h1>
<p>We’ve spent some quality time together on this article and have weaned you from a dependence on singletons in your code base.&nbsp; Singletons often are seen as the “easy” way to code.&nbsp; Just because you don’t have to “new up” a class to make use of its functionality,
 doesn’t mean that you’re not imposing a debt on your code base.&nbsp; While singletons seem like the route of least friction at first, you quickly find out that they’re nothing more than a mirage on the way to software development bliss.&nbsp; You see the ease of development
 that they offer, but every time that you move closer the goal is still just as far away as it was before.</p>
<p>Unless you truly need to ensure that one, and only one, instance of an object exists per application lifecycle, then you should be working to refactor singletons out of your code base.&nbsp; Hopefully, the techniques in this article have pointed you in the right
 direction to be able to do that.</p>
<h2>Other videos from this article</h2>
<ul>
<li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-Overview/" shape="rect">Demoing Different Singleton Implementations</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-Testability/" shape="rect">How Singletons Affect Testability</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-AuthChecker-Class/" shape="rect">Looking At AuthChecker</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-Refactoring/" shape="rect">Walkthrough Of The Entire Refactoring</a>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/magazine/ee343987.aspx" shape="rect">
http://msdn.microsoft.com/magazine/ee343987.aspx</a> </p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:9caf066dd9234821bdd49deb01770b8f">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-Refactoring</comments>
      <itunes:summary>
Extreme ASP.NET Makeover: Death of a Singleton-Refactoring
Now that we have a new class, complete with functionality, we can start to refactor other parts of the application to use it instead of the AuthChecker singleton.&amp;nbsp; Like all the other refactorings we’ve done thus far in this article, it’s not that big of
 a deal.&amp;nbsp; As our example, we’re going to continue to refactor the AuthorizationServices class (see the

previous Separation of Concerns article for the initial refactoring for this).&amp;nbsp; In AuthorizationServices, we want to eliminate the use of AuthChecker and, in its place, use an instance of AuthorizationChecker instead. 
To do this, we first need to create a module level variable that provides the same capabilities as the AuthChecker singleton.&amp;nbsp; Earlier in this article, we created an IAuthenticationChecker interface that worked to enforce this for us.&amp;nbsp; Now is another time
 that we can use it.&amp;nbsp; As you can see in the code below, we now have created an instance of the AuthenticationChecker and assigned it to the module level variable: 
public class AuthorizationServices{    private IAuthorizationChecker _authenticationChecker;    public AuthorizationServices()    {        authorizationChecker = new AuthorizationChecker();    }    ...}

Now that we have a way to access the authentication checking code, we just need to replace the AuthChecker calls in the RetrieveCurrentStatusFor method with calls to the module level variable.&amp;nbsp; As an example of these changes, here is what the first one would
 look like: 
CanView = _authorizationChecker.CheckActionForPage(currentPage,     Actions.ForPages.ReadPage, currentUsername, currentGroups),

With that we have our AuthorizationServices class refactored and we’ve finished the first full round of changes that are required to eliminate the AuthChecker singleton.&amp;nbsp; If we take a look at the usages of the AuthChecker singleton instance, we’ll see that
 there are sti</itunes:summary>
      <itunes:duration>455</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-Refactoring</link>
      <pubDate>Tue, 04 Aug 2009 23:57:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-Refactoring</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/482733_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/482733_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/3/7/2/8/4/WalkthroughOfTheEntireRefactoring_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/3/7/2/8/4/WalkthroughOfTheEntireRefactoring_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/3/7/2/8/4/WalkthroughOfTheEntireRefactoring_2MB_ch9.wmv" expression="full" duration="455" fileSize="16059824" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/3/7/2/8/4/WalkthroughOfTheEntireRefactoring_ch9.mp3" expression="full" duration="455" fileSize="3643708" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/3/7/2/8/4/WalkthroughOfTheEntireRefactoring_ch9.mp4" expression="full" duration="455" fileSize="13461933" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/3/7/2/8/4/WalkthroughOfTheEntireRefactoring_ch9.wma" expression="full" duration="455" fileSize="3687875" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/3/7/2/8/4/WalkthroughOfTheEntireRefactoring_Zune_ch9.wmv" expression="full" duration="455" fileSize="12571877" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/3/7/2/8/4/WalkthroughOfTheEntireRefactoring_2MB_ch9.wmv" length="16059824" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-Refactoring/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
      <category>Singleton</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: Singleton - AuthChecker Class</title>
      <description><![CDATA[
<h1>Extreme ASP.NET Makeover: Death of a Singleton-AuthChecker Class</h1>
<h1>I’ve Got Some Seeds, Right Away</h1>
<p>So where should we start?&nbsp; How about the AuthChecker class, since that’s what we’ve discussed through the first part of this article.&nbsp; Earlier, we decided that there was no reason for it to continue to be a singleton, since there was no compelling reason
 for one, and only one, instance of it to exist for the life of the application.</p>
<p>The process that we’re going to go through will see us move from using the existing AuthChecker class to using instances of an AuthorizationChecker class.&nbsp; Once we’ve made the transition from AuthChecker to AuthorizationChecker, we will delete the AuthChecker
 Singleton from our codebase.</p>
<p>The first challenge that we have to face in this process is how do we create a new class (AuthorizationChecker) which we can guarantee to expose the same functionality as the original (AuthChecker) class.&nbsp; There are two reasonable options for this: abstract
 base class and interface.&nbsp; Abstract base class is a good solution, if we were going to need to use the same AuthChecker functionality in multiple class implementation for the distant future.&nbsp; In this case though, we’ve already determined that we’re going to
 be deleting the AuthChecker Singleton implementation once we’ve completed our refactoring.&nbsp; As a result, using Interfaces makes more sense.</p>
<p>That makes our first step in the process to extract an interface from the AuthChecker class.&nbsp; As you can see below, it’s really a simple interface, called IAuthorizationChecker, that defines the four publically exposed methods on the AuthChecker class:</p>
<pre>public interface IAuthenticationChecker{    bool CheckActionForGlobals(string action, string currentUser,        string[] groups);    bool CheckActionForNamespace(NamespaceInfo nspace, string action,        string currentUser, string[] groups);    bool CheckActionForPage(PageInfo page, string action,        string currentUser, string[] groups);    bool CheckActionForDirectory(IFilesStorageProviderV30 provider,         string directory, string action, string currentUser, string[] groups);}</pre>
<br>
<p>Now that we have that interface we need to get the AuthChecker to implement it.&nbsp; This is pretty easy, but has a couple of small twists.&nbsp; Because we’re applying the interface to a Singleton class, we also have to ensure that the .Instance property is returning
 a type of the IAuthenticationChecker interface.&nbsp; To get the code to compile we also have to change the type of the properties underlying module level variable so that it too is of type IAuthorizationChecker:</p>
<pre>public class AuthorizationChecker : IAuthorizationChecker{    public bool CheckActionForGlobals(string action,         string currentUser, string[] groups)    {        throw new NotImplementedException();    }     public bool CheckActionForNamespace(NamespaceInfo nspace,         string action, string currentUser, string[] groups)    {        throw new NotImplementedException();    }     public bool CheckActionForPage(PageInfo page, string action,         string currentUser, string[] groups)    {        throw new NotImplementedException();    }     public bool CheckActionForDirectory(        IFilesStorageProviderV30 provider, string directory,         string action, string currentUser, string[] groups)    {        throw new NotImplementedException();    }}</pre>
<br>
<p>Interestingly, this is the last of the changes that you’ll have to make to AuthChecker before you delete it from the project.</p>
<p>Now that we’ve established how calling code should expect us to behave (via the IAuthorizationChecker interface), we can go ahead and write a new class that meets that expectation.&nbsp; In this case we’re going to call the class AuthorizationChecker and we’ll
 make it implement the interface.&nbsp; The result, as shown in <b>Figure 6</b>, is a class with the same four public methods on it that the AuthChecker class has.</p>
<p><b>Figure 6 Class With Four Public Methods</b></p>
<pre>public class AuthorizationChecker : IAuthorizationChecker{    public bool CheckActionForGlobals(string action,         string currentUser, string[] groups)    {        throw new NotImplementedException();    }     public bool CheckActionForNamespace(NamespaceInfo nspace,         string action, string currentUser, string[] groups)    {        throw new NotImplementedException();    }     public bool CheckActionForPage(PageInfo page, string action,         string currentUser, string[] groups)    {        throw new NotImplementedException();    }     public bool CheckActionForDirectory(        IFilesStorageProviderV30 provider,         string directory, string action,         string currentUser, string[] groups)    {        throw new NotImplementedException();    }}</pre>
<br>
<p>Now that our new AuthorizationChecker class has a basic shell, we need to get it working with the same functionality as the original AuthChecker singleton.&nbsp;&nbsp; One of the key things when doing refactorings like this is to be able to do them incrementally.&nbsp;&nbsp;
 Big-bang approaches can be successful, but rarely do you have the ability to impose the constraints, such as time and cost, on your project’s current needs.&nbsp; Instead, we want to be able to nibble away at the refactoring as time permits and in a way that won’t
 affect the project.</p>
<p>To do this, we’re going to take our new AuthenticationChecker class and simply pass through the calls to the original AuthChecker code.&nbsp;&nbsp; This may seem like an extraneous step, but it’s one that is necessary to achieve the goal of refactoring little by little.&nbsp;
 To make this happen, we need to get an instance of AuthChecker into the local scope of the newly created AuthenticationChecker class:</p>
<pre>private IAuthorizationChecker _authChecker; public AuthorizationChecker(){    AuthChecker.Instance = new AuthChecker(Settings.Instance.Provider);    _authChecker = AuthChecker.Instance;}</pre>
<br>
<p>Once we have the AuthChecker instance in place, we can have the methods in the class simply delegate execution to the existing methods in the AuthChecker class.&nbsp; Like we said before, this may seem extraneous, but trust us, we’re going somewhere here, as
 shown in <b>Figure 7</b>.</p>
<p><b>Figure 7 Execution of Existing Methods in the AuthChecker Class</b></p>
<pre>public bool CheckActionForGlobals(string action, string currentUser,     string[] groups){    return _authChecker.CheckActionForGlobals(action, currentUser,        groups);} public bool CheckActionForNamespace(NamespaceInfo nspace,     string action, string currentUser, string[] groups){    return _authChecker.CheckActionForNamespace(nspace, action,         currentUser, groups);} public bool CheckActionForPage(PageInfo page, string action,     string currentUser, string[] groups){    return _authChecker.CheckActionForPage(page, action,         currentUser, groups);} public bool CheckActionForDirectory(IFilesStorageProviderV30 provider,     string directory, string action, string currentUser, string[] groups){    return _authChecker.CheckActionForDirectory(provider, directory,         action, currentUser, groups);}</pre>
<br>
<p>One of the key things to note with this approach is that we’ve maintained a single place of change for the code that is related to the AuthChecker/AuthorizationChecker functionality.&nbsp; If we’re going to be tackling this refactoring over a period of time,
 this is key, since we can’t be confidently maintaining multiple pieces of code that represent the same functionality.&nbsp; Don’t be fooled that the maintenance cost of this approach is zero.&nbsp; If you were to change the arguments in the methods, you’d have multiple
 places to change, but, on a positive note, you’d get compile errors from that due to the use of an interface enforcing the publically exposed contract.</p>
<h2>Other videos from this article</h2>
<ul>
<li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-Overview/" shape="rect">Demoing Different Singleton Implementations</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-Testability/" shape="rect">How Singletons Affect Testability</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-AuthChecker-Class/" shape="rect">Looking At AuthChecker</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-Refactoring/" shape="rect">Walkthrough Of The Entire Refactoring</a>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/magazine/ee343987.aspx" shape="rect">
http://msdn.microsoft.com/magazine/ee343987.aspx</a> </p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:19aaf3f4aa2445ada17a9deb01770f66">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-AuthChecker-Class</comments>
      <itunes:summary>
Extreme ASP.NET Makeover: Death of a Singleton-AuthChecker Class
I’ve Got Some Seeds, Right Away
So where should we start?&amp;nbsp; How about the AuthChecker class, since that’s what we’ve discussed through the first part of this article.&amp;nbsp; Earlier, we decided that there was no reason for it to continue to be a singleton, since there was no compelling reason
 for one, and only one, instance of it to exist for the life of the application. 
The process that we’re going to go through will see us move from using the existing AuthChecker class to using instances of an AuthorizationChecker class.&amp;nbsp; Once we’ve made the transition from AuthChecker to AuthorizationChecker, we will delete the AuthChecker
 Singleton from our codebase. 
The first challenge that we have to face in this process is how do we create a new class (AuthorizationChecker) which we can guarantee to expose the same functionality as the original (AuthChecker) class.&amp;nbsp; There are two reasonable options for this: abstract
 base class and interface.&amp;nbsp; Abstract base class is a good solution, if we were going to need to use the same AuthChecker functionality in multiple class implementation for the distant future.&amp;nbsp; In this case though, we’ve already determined that we’re going to
 be deleting the AuthChecker Singleton implementation once we’ve completed our refactoring.&amp;nbsp; As a result, using Interfaces makes more sense. 
That makes our first step in the process to extract an interface from the AuthChecker class.&amp;nbsp; As you can see below, it’s really a simple interface, called IAuthorizationChecker, that defines the four publically exposed methods on the AuthChecker class: 
public interface IAuthenticationChecker{    bool CheckActionForGlobals(string action, string currentUser,        string[] groups);    bool CheckActionForNamespace(NamespaceInfo nspace, string action,        string currentUser, string[] groups);    bool CheckActionForPage(PageInfo page, string action,  </itunes:summary>
      <itunes:duration>93</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-AuthChecker-Class</link>
      <pubDate>Tue, 04 Aug 2009 23:57:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-AuthChecker-Class</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/482732_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/482732_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/2/3/7/2/8/4/LookingAtAuthChecker_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/2/3/7/2/8/4/LookingAtAuthChecker_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/2/3/7/2/8/4/LookingAtAuthChecker_2MB_ch9.wmv" expression="full" duration="93" fileSize="2742502" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/2/3/7/2/8/4/LookingAtAuthChecker_ch9.mp3" expression="full" duration="93" fileSize="752696" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/2/3/7/2/8/4/LookingAtAuthChecker_ch9.mp4" expression="full" duration="93" fileSize="2705278" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/2/3/7/2/8/4/LookingAtAuthChecker_ch9.wma" expression="full" duration="93" fileSize="773995" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/2/3/7/2/8/4/LookingAtAuthChecker_Zune_ch9.wmv" expression="full" duration="93" fileSize="2646809" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/2/3/7/2/8/4/LookingAtAuthChecker_2MB_ch9.wmv" length="2742502" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-AuthChecker-Class/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
      <category>Singleton</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: Singleton - Testability</title>
      <description><![CDATA[
<h1>Extreme ASP.NET Makeover: Death of a Singleton-Testability</h1>
<h1>He’s Liked, But He’s Not Well Liked</h1>
<p>If the current code works, why do we need to get rid of the singleton? What harm is it doing? After all, there’s a reason the pattern has a name. It must be useful.</p>
<p>We have a few issues with singletons. The easiest argument to make is that singletons make your code hard to test. If you make a call to a singleton in a class, then you must make sure the singleton is initialized whenever the test is run. If the singleton
 requires a connection to a database or the existence of a Web service, these must be configured prior to running the test. If you want reasons why this is a bad practice, look no further than our previous article on separation of concerns.</p>
<p>This lack of testability isn’t the only problem. After all, there are ways (usually neither easy nor pleasant) to make singletons testable. Indeed, ScrewTurn uses one of them by exposing a public constructor. Let’s look more closely at the AuthChecker class
 we’ve been working with. Why is it a singleton class? Perhaps so that its members can be accessed throughout the site without having to create a new instance of it? Perhaps to save on resources by reducing object allocation and garbage collection? (This would
 almost certainly be a premature optimization.)</p>
<p>Let’s look at the first public method on the class, CheckActionForGlobals. Where is this being used? If you trace its usages, you’ll find it is used in exactly three other classes: the AdminMaster master page and FileManager.ascx control (both in the WebApplication
 project) and the AuthorizationServices class in the Core project. (The latter is one of the refactorings we did in Part 6; originally, it was being called in Default.aspx in the WebApplication project.)</p>
<p>So this globally accessible method is really only being used in three places. Doesn’t sound all that global to us. One could make an argument that each of these classes could just create an instance of the class instead. That would make them easier to test
 and less fragile overall.</p>
<p>Of course, we’ve been cautiously selective in our example. CheckActionForGlobals is but one method in the AuthChecker singleton. If we look at all cases where we reference AuthChecker.Instance, we’ll find no less than 86 occurrences of it across 21 files.</p>
<p>“Aha!” you say. “Doesn’t that contradict your argument that it’s not really being used globally?” “Pshaw!” say we! What it does is highlight another issue with singletons. The Instance variable is used in 21 files, yet CheckActionForGlobals is used in 3.
 Another method, CheckActionForDirectory, is used in 5, not including calls made from within the AuthChecker class itself.</p>
<p>In short, our singleton has turned into a sort of catch-all bucket, a place to house disparate methods under the loosely-defined category of “authorization checking.” Granted, the AuthChecker class isn’t as messy as it could be, but the tendency with singleton
 classes is to make them more and more generic as you add “helper” methods to them. The ubiquitous Utils singleton often seen in many projects is a good example. Developers see a singleton and it’s just so darned tempting to drop a method in there rather than
 create a separate class with a more specific focus.</p>
<p>The result of those temptations is that you find code bases that are littered with unnecessary singletons.&nbsp; While they may seem innocuous at first, the problems we described earlier will start to haunt your project.&nbsp; To help you with those existing Singletons,
 let’s look at how we can move through our code and remove them.</p>
<h2>Other videos from this article</h2>
<ul>
<li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-Overview/" shape="rect">Demoing Different Singleton Implementations</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-Testability/" shape="rect">How Singletons Affect Testability</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-AuthChecker-Class/" shape="rect">Looking At AuthChecker</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-Refactoring/" shape="rect">Walkthrough Of The Entire Refactoring</a>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/magazine/ee343987.aspx" shape="rect">
http://msdn.microsoft.com/magazine/ee343987.aspx</a> </p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:87d5d81242724247a4269deb01771341">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-Testability</comments>
      <itunes:summary>
Extreme ASP.NET Makeover: Death of a Singleton-Testability
He’s Liked, But He’s Not Well Liked
If the current code works, why do we need to get rid of the singleton? What harm is it doing? After all, there’s a reason the pattern has a name. It must be useful. 
We have a few issues with singletons. The easiest argument to make is that singletons make your code hard to test. If you make a call to a singleton in a class, then you must make sure the singleton is initialized whenever the test is run. If the singleton
 requires a connection to a database or the existence of a Web service, these must be configured prior to running the test. If you want reasons why this is a bad practice, look no further than our previous article on separation of concerns. 
This lack of testability isn’t the only problem. After all, there are ways (usually neither easy nor pleasant) to make singletons testable. Indeed, ScrewTurn uses one of them by exposing a public constructor. Let’s look more closely at the AuthChecker class
 we’ve been working with. Why is it a singleton class? Perhaps so that its members can be accessed throughout the site without having to create a new instance of it? Perhaps to save on resources by reducing object allocation and garbage collection? (This would
 almost certainly be a premature optimization.) 
Let’s look at the first public method on the class, CheckActionForGlobals. Where is this being used? If you trace its usages, you’ll find it is used in exactly three other classes: the AdminMaster master page and FileManager.ascx control (both in the WebApplication
 project) and the AuthorizationServices class in the Core project. (The latter is one of the refactorings we did in Part 6; originally, it was being called in Default.aspx in the WebApplication project.) 
So this globally accessible method is really only being used in three places. Doesn’t sound all that global to us. One could make an argument that each of these classes could just create an</itunes:summary>
      <itunes:duration>504</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-Testability</link>
      <pubDate>Tue, 04 Aug 2009 23:57:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-Testability</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/482731_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/482731_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/3/7/2/8/4/HowSingletonsAffectTestability_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/3/7/2/8/4/HowSingletonsAffectTestability_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/3/7/2/8/4/HowSingletonsAffectTestability_2MB_ch9.wmv" expression="full" duration="504" fileSize="19788520" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/3/7/2/8/4/HowSingletonsAffectTestability_ch9.mp3" expression="full" duration="504" fileSize="4039933" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/3/7/2/8/4/HowSingletonsAffectTestability_ch9.mp4" expression="full" duration="504" fileSize="15747760" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/3/7/2/8/4/HowSingletonsAffectTestability_ch9.wma" expression="full" duration="504" fileSize="4090417" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/3/7/2/8/4/HowSingletonsAffectTestability_Zune_ch9.wmv" expression="full" duration="504" fileSize="14396569" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/3/7/2/8/4/HowSingletonsAffectTestability_2MB_ch9.wmv" length="19788520" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>1</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-Testability/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
      <category>Singleton</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: Singleton - Overview</title>
      <description><![CDATA[
<h1>Extreme ASP.NET Makeover: Death of a Singleton-Overview</h1>
<p>Let’s review one of the changes we made to the code in part 6. In that discussion, we refactored the authorization checking into a separate class, AuthorizationServices. To do that, we moved a lot of code from the Page_Load method of our Default.aspx page
 into it. <b>Figure 1 </b>shows an excerpt from the RetrieveCurrentStatusFor method.</p>
<p><b>Figure 1 Excerpt from the RetrieveCurrentStatusFor Method</b></p>
<pre>return new CurrentCapabilitiesStatus{    CanView = AuthChecker.Instance.CheckActionForPage(        currentPage, Actions.ForPages.ReadPage,        currentUsername, currentGroups),    CanDownloadAttachments = AuthChecker.Instance.CheckActionForPage(        currentPage, Actions.ForPages.DownloadAttachments,        currentUsername, currentGroups),    CanSetPerms = AuthChecker.Instance.CheckActionForGlobals(        Actions.ForGlobals.ManagePermissions,        currentUsername, currentGroups),    CanAdmin = AuthChecker.Instance.CheckActionForPage(        currentPage, Actions.ForPages.ManagePage,        currentUsername, currentGroups),    CanViewDiscussion = AuthChecker.Instance.CheckActionForPage(        currentPage, Actions.ForPages.ReadDiscussion,        currentUsername, currentGroups),    CanPostDiscussion = AuthChecker.Instance.CheckActionForPage(        currentPage, Actions.ForPages.PostDiscussion,        currentUsername, currentGroups),    CanManageDiscussion = AuthChecker.Instance.CheckActionForPage(        currentPage, Actions.ForPages.ManageDiscussion,        currentUsername, currentGroups),    CanEdit = canEdit,    CanEditWithApproval = canEditWithApproval};</pre>
<br>
<p>Notice all the calls to AuthChecker.Instance. This is an example of the Singleton Design Pattern at work. We’ll define it now to get everyone on the same page.</p>
<h1>There Can Be Only One</h1>
<p>The defining characteristic of a singleton class is that there is only one instance of it at any given time (unless it is never used, in which case, there may not be any instances of it depending on how it is implemented).</p>
<p>Implementing a Singleton is not quite as trivial as it sounds. The intuitive approach is to make the constructor private and provide a public static accessor to it, as shown in
<b>Figure 2</b>.</p>
<p><b>Figure 2 Implementing a Singleton </b></p>
<pre>public class MySingleton{    private static MySingleton _instance;     private MySingleton()    {    }     public static MySingleton Instance    {        get        {            if (_instance == null)                _instance = new MySingleton();            return _instance;        }      }     ...}</pre>
<br>
<p>This works fine in single-threaded environments, but not in multi-threaded ones. Two threads could enter the Instance property before the instance variable is instantiated, resulting in two instances of the class. There are a few ways around this,&nbsp; but the
 easiest solution in .NET takes advantage of the CLR and its guarantees around initialization of static variables, as shown in
<b>Figure 3</b>.</p>
<p><b>Figure 3 Dealing With Two Instances of the Class</b></p>
<pre>public class MySingleton{    private static readonly MySingleton _instance = new MySingleton();     private MySingleton()    {    }     public static MySingleton Instance    {        get        {            return _instance;        }      }     ...}</pre>
<br>
<p>The fact that the instance variable is marked static and readonly ensures only one instance can be created, even in multi-threaded environments.&nbsp; Another side effect is that an instance of MySingleton is always going to be created for the _instance variable,
 regardless of if it’s needed or not.&nbsp; This is, however, rarely an issue in real world code.</p>
<h2>Some Background</h2>
<p>A common implementation for singletons is to use double-checked locking, like so:</p>
<pre>if (_instance == null) {</pre>
<pre>&nbsp;&nbsp;&nbsp; lock (_initializationLock) {</pre>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (_instance == null) {</pre>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _instance = new MySingleton();</pre>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </pre>
<pre>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </pre>
<pre>}</pre>
<pre>return _instance;</pre>
<p>&nbsp;</p>
<p>On the surface, double-checked locking appears to offer the best of all worlds. Singletons are instantiated lazily, are never instantiated if never used, and do not take an expensive lock after the singleton is initialized. Unfortunately, double-checked
 locking is subtlely broken in the vast majority of cases. You can read more about the problems in
<a shape="rect" href="http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html" shape="rect">
<i>The “Double-Checked Locking is Broken” Declaration</i></a> by David Bacon, et al. Double-checked locking can be fixed on the CLR (and JDK5&#43;) by declaring the _instance variable with the volatile keyword. See
<a shape="rect" href="http://msdn.microsoft.com/en-us/library/ms998558.aspx" shape="rect">
<i>Implementing Singleton in C#</i></a> and <a shape="rect" href="http://msdn.microsoft.com/en-us/library/ms954629.aspx" shape="rect">
<i>Exploring the Singleton Design Pattern</i></a> in the MSDN Library<i> </i>for more information.</p>
<p>That’s about as detailed as we’re going to get on implementing singletons, because there are a number of good resources already available. Plus, the focus of this article is to move away from them, not add more.</p>
<p>With that background behind us, the “singleton” classes in ScrewTurn aren’t actually singletons.
<b>Figure 4</b> looks at the AuthChecker class first.</p>
<p><b>Figure 4 AuthChecker Class</b></p>
<pre>public class AuthChecker {     private static AuthChecker instance;    public static AuthChecker Instance     {        get { return instance; }        set { instance = value; }    }     private ISettingsStorageProviderV30 settingsProvider;     public AuthChecker(ISettingsStorageProviderV30 settingsProvider)     {        if(settingsProvider == null) throw new             ArgumentNullException(&quot;settingsProvider&quot;);         this.settingsProvider = settingsProvider;    }     public bool CheckActionForGlobals(string action,         string currentUser, string[] groups)     {       }     public bool CheckActionForNamespace(NamespaceInfo nspace,         string action, string currentUser,         string[] groups)     {       }     public bool CheckActionForPage(PageInfo page, string action,     {       }     public bool CheckActionForDirectory(        IFilesStorageProviderV30 provider,         string directory, string action,         string currentUser, string[] groups)     {       }}</pre>
<br>
<p>The most obvious way you can tell this isn’t a singleton is that it has a public constructor. So the client code can create as many of these as it likes. Furthermore, the class doesn’t actually instantiate the instance variable itself. That is done elsewhere
 in the code, in StartupTools.cs, using the public constructor.</p>
<p>That said, it is still used as a singleton within the context of the application. Yes, the code could create more than one instance and re-assign the existing instance and basically treat it like any other class. But in the application’s current state, it
 doesn’t. This half-way status between singleton and non-singleton would be a bone of contention for us at a code review, so let’s see what we can do to fix it. But first, like any refactoring, we need to justify it.</p>
<h2>Other videos from this article</h2>
<ul>
<li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-Overview/" shape="rect">Demoing Different Singleton Implementations</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-Testability/" shape="rect">How Singletons Affect Testability</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-AuthChecker-Class/" shape="rect">Looking At AuthChecker</a>
</li><li><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-Singleton-Refactoring/" shape="rect">Walkthrough Of The Entire Refactoring</a>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/magazine/ee343987.aspx" shape="rect">
http://msdn.microsoft.com/magazine/ee343987.aspx</a> </p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:e9d5d506bb494bfa92669deb01771702">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-Overview</comments>
      <itunes:summary>
Extreme ASP.NET Makeover: Death of a Singleton-Overview
Let’s review one of the changes we made to the code in part 6. In that discussion, we refactored the authorization checking into a separate class, AuthorizationServices. To do that, we moved a lot of code from the Page_Load method of our Default.aspx page
 into it. Figure 1 shows an excerpt from the RetrieveCurrentStatusFor method. 
Figure 1 Excerpt from the RetrieveCurrentStatusFor Method 
return new CurrentCapabilitiesStatus{    CanView = AuthChecker.Instance.CheckActionForPage(        currentPage, Actions.ForPages.ReadPage,        currentUsername, currentGroups),    CanDownloadAttachments = AuthChecker.Instance.CheckActionForPage(        currentPage, Actions.ForPages.DownloadAttachments,        currentUsername, currentGroups),    CanSetPerms = AuthChecker.Instance.CheckActionForGlobals(        Actions.ForGlobals.ManagePermissions,        currentUsername, currentGroups),    CanAdmin = AuthChecker.Instance.CheckActionForPage(        currentPage, Actions.ForPages.ManagePage,        currentUsername, currentGroups),    CanViewDiscussion = AuthChecker.Instance.CheckActionForPage(        currentPage, Actions.ForPages.ReadDiscussion,        currentUsername, currentGroups),    CanPostDiscussion = AuthChecker.Instance.CheckActionForPage(        currentPage, Actions.ForPages.PostDiscussion,        currentUsername, currentGroups),    CanManageDiscussion = AuthChecker.Instance.CheckActionForPage(        currentPage, Actions.ForPages.ManageDiscussion,        currentUsername, currentGroups),    CanEdit = canEdit,    CanEditWithApproval = canEditWithApproval};

Notice all the calls to AuthChecker.Instance. This is an example of the Singleton Design Pattern at work. We’ll define it now to get everyone on the same page. 
There Can Be Only One
The defining characteristic of a singleton class is that there is only one instance of it at any given time (unless it is never used, in which case, t</itunes:summary>
      <itunes:duration>511</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-Overview</link>
      <pubDate>Tue, 04 Aug 2009 23:56:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-Overview</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/482728_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/482728_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/8/2/7/2/8/4/DemoingDifferentSingletonImpls_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/8/2/7/2/8/4/DemoingDifferentSingletonImpls_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/8/2/7/2/8/4/DemoingDifferentSingletonImpls_2MB_ch9.wmv" expression="full" duration="511" fileSize="9579476" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/8/2/7/2/8/4/DemoingDifferentSingletonImpls_ch9.mp3" expression="full" duration="511" fileSize="4089664" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/8/2/7/2/8/4/DemoingDifferentSingletonImpls_ch9.mp4" expression="full" duration="511" fileSize="13314207" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/8/2/7/2/8/4/DemoingDifferentSingletonImpls_ch9.wma" expression="full" duration="511" fileSize="4138475" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/8/2/7/2/8/4/DemoingDifferentSingletonImpls_Zune_ch9.wmv" expression="full" duration="511" fileSize="12508647" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/8/2/7/2/8/4/DemoingDifferentSingletonImpls_2MB_ch9.wmv" length="9579476" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-Singleton-Overview/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
      <category>Singleton</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: SoC - The Big Picture</title>
      <description><![CDATA[
<h1>Extreme ASP.NET Makeover: Separation of Concerns – The Big Picture</h1>
<p>&nbsp;</p>
<p>Let’s summarize what we’ve done. We removed code from Page_Load using cut and paste, and we created two new classes. It doesn’t seem like much as far as refactoring is concerned. But that’s because we aren’t actually finished with the task. In order to consider
 the work complete, we must now go to every page that made use of AuthChecker and do the same refactoring as we did here. It will be a lot of work, but the method we used to separate the authorization-specific code can be incrementally applied to other code
 behind files. Let’s take another look at the refactoring, but this time we’ll see how automated refactoring tools can assist with the changes.</p>
<h1>The Big Picture</h1>
<p>Once all of the uses of AuthChecker have been removed and AuthorizationService is being used in its place, you will have made the codebase much simpler to work with. Consider now what is involved when we change how permissions are retrieved. Instead of having
 to find and change the many places that AuthChecker was originally being used (over 130, by our count), you can work only in the AuthorizationServices class. This single point of change shows that you are more likely to be separating the concerns in your codebase.</p>
<p>In the end, a few things have happened from when we first looked at the Default.aspx.cs Page_Load method. First, we have been able to clearly define an area in code for the authorization concern. When anything related to determining a user’s authorization
 arises, we know that it will be taken care of by the AuthorizationServices. No longer will we continually suffer the ripple effects of modifying or fixing the functionality related to this concern.</p>
<p>Second, we have reduced the number of lines in the Page_Load method, yet through the use of revealing variable and property names, we haven’t reduced the ability for developers to decipher the intentions of the code. This is quite important when doing this
 type of refactoring. You never want to leave code less understandable than when you found it. (And considering how quickly comments become obsolete, leaving a trail of them behind you to ease understanding is not an optimal approach.)&nbsp; Instead, think about
 how you will use variables, properties, and methods in the code and name them so that they read and convey ideas easily.</p>
<h1>Conclusion</h1>
<p>The final achievement is that we have started a trend of reducing repetition in our codebase. This is a side effect of separating our concerns, but by implementing an isolated class whose sole responsibility is to determine user authorization for a given
 page, we are allowing ourselves to eliminate any repetitive code that is also doing this. A simple Find search for “AuthChecker” in the entire solution shows that many locations can benefit from using the new AuthorizationServices class.</p>
<p>Taking care of the authorization concern is just one of many refactoring tasks that are available in the Page_Load method of Default.aspx.cs. Others include the URL redirection, the URL builders, Content.GetPageContent, and Settings. If you look through
 the code provided with this article, you can see how we have refactored those concerns out of Page_Load so that it has one, and only one, reason to change: how we are displaying the contents of the page.</p>
<p>&nbsp;</p>
<h2>Other videos from this article</h2>
<ul>
<li>
<div><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-SoC-Overview/" shape="rect">Initial Examination Of Default AspxCs</a></div>
</li><li>
<div><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-SoC-Principles-to-Practice/" shape="rect">Refactoring To AuthorizationServices The Long Way</a></div>
</li><li>
<div><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-SoC-The-Big-Picture/" shape="rect">Refactoring To AuthorizationServices The Short Way</a></div>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/en-us/magazine/ee210417" shape="rect">
http://msdn.microsoft.com/en-us/magazine/ee210417</a></p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:7e0677cc387f410eaceb9deb01771ac4">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-SoC-The-Big-Picture</comments>
      <itunes:summary>
Extreme ASP.NET Makeover: Separation of Concerns – The Big Picture
&amp;nbsp; 
Let’s summarize what we’ve done. We removed code from Page_Load using cut and paste, and we created two new classes. It doesn’t seem like much as far as refactoring is concerned. But that’s because we aren’t actually finished with the task. In order to consider
 the work complete, we must now go to every page that made use of AuthChecker and do the same refactoring as we did here. It will be a lot of work, but the method we used to separate the authorization-specific code can be incrementally applied to other code
 behind files. Let’s take another look at the refactoring, but this time we’ll see how automated refactoring tools can assist with the changes. 
The Big Picture
Once all of the uses of AuthChecker have been removed and AuthorizationService is being used in its place, you will have made the codebase much simpler to work with. Consider now what is involved when we change how permissions are retrieved. Instead of having
 to find and change the many places that AuthChecker was originally being used (over 130, by our count), you can work only in the AuthorizationServices class. This single point of change shows that you are more likely to be separating the concerns in your codebase. 
In the end, a few things have happened from when we first looked at the Default.aspx.cs Page_Load method. First, we have been able to clearly define an area in code for the authorization concern. When anything related to determining a user’s authorization
 arises, we know that it will be taken care of by the AuthorizationServices. No longer will we continually suffer the ripple effects of modifying or fixing the functionality related to this concern. 
Second, we have reduced the number of lines in the Page_Load method, yet through the use of revealing variable and property names, we haven’t reduced the ability for developers to decipher the intentions of the code. This is quite important when doi</itunes:summary>
      <itunes:duration>673</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-SoC-The-Big-Picture</link>
      <pubDate>Fri, 10 Jul 2009 23:40:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-SoC-The-Big-Picture</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/477841_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/477841_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/4/8/7/7/4/RefactoringToAuthorizationServicesTheShortWay_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/4/8/7/7/4/RefactoringToAuthorizationServicesTheShortWay_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/4/8/7/7/4/RefactoringToAuthorizationServicesTheShortWay_2MB_ch9.wmv" expression="full" duration="673" fileSize="24898444" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/4/8/7/7/4/RefactoringToAuthorizationServicesTheShortWay_ch9.mp3" expression="full" duration="673" fileSize="5390373" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/4/8/7/7/4/RefactoringToAuthorizationServicesTheShortWay_ch9.mp4" expression="full" duration="673" fileSize="20782546" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/4/8/7/7/4/RefactoringToAuthorizationServicesTheShortWay_ch9.wma" expression="full" duration="673" fileSize="10903501" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/4/8/7/7/4/RefactoringToAuthorizationServicesTheShortWay_Zune_ch9.wmv" expression="full" duration="673" fileSize="19225461" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/1/4/8/7/7/4/RefactoringToAuthorizationServicesTheShortWay_2MB_ch9.wmv" length="24898444" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-SoC-The-Big-Picture/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: SoC - Principles to Practice</title>
      <description><![CDATA[
<h1>Extreme ASP.NET Makeover: Separation of Concerns – Principles to Practice</h1>
<p>&nbsp;</p>
<p>When looking at the code, the first thing that our attention was drawn to was the repetitive nature of the authorization code.&nbsp; As you can see in the code in
<b>Figure 1</b>, there are a large number of calls to retrieve single permission values.</p>
<p><b>Figure 1 Default.aspx Page_Load Code</b></p>
<pre>string currentUsername = SessionFacade.GetCurrentUsername();</pre>
<pre>string[] currentGroups = SessionFacade.GetCurrentGroupNames();</pre>
<pre>&nbsp;</pre>
<pre>bool canView = AuthChecker.Instance.CheckActionForPage(currentPage, Actions.ForPages.ReadPage, currentUsername, currentGroups);</pre>
<pre>bool canEdit = false;</pre>
<pre>bool canEditWithApproval = false;</pre>
<pre>Pages.CanEditPage(currentPage, currentUsername, currentGroups, out canEdit, out canEditWithApproval);</pre>
<pre>if(canEditWithApproval &amp;&amp; canEdit) canEditWithApproval = false;</pre>
<pre>bool canDownloadAttachments = AuthChecker.Instance.CheckActionForPage(currentPage, Actions.ForPages.DownloadAttachments, currentUsername, currentGroups);</pre>
<pre>bool canSetPerms = AuthChecker.Instance.CheckActionForGlobals(Actions.ForGlobals.ManagePermissions, currentUsername, currentGroups);</pre>
<pre>bool canAdmin = AuthChecker.Instance.CheckActionForPage(currentPage, Actions.ForPages.ManagePage, currentUsername, currentGroups);</pre>
<pre>bool canViewDiscussion = AuthChecker.Instance.CheckActionForPage(currentPage, Actions.ForPages.ReadDiscussion, currentUsername, currentGroups);</pre>
<pre>bool canPostDiscussion = AuthChecker.Instance.CheckActionForPage(currentPage, Actions.ForPages.PostDiscussion, currentUsername, currentGroups);</pre>
<pre>bool canManageDiscussion = AuthChecker.Instance.CheckActionForPage(currentPage, Actions.ForPages.ManageDiscussion, currentUsername, currentGroups);</pre>
<pre>&nbsp;</pre>
<p>Now, we certainly can’t look at this code and simply say, “Get rid of all that stuff”, because it is necessary for the page to properly function. But how permissions are retrieved, whether from the AuthChecker or Pages or even hard-coding, is the responsibility
 of some other class, not this one's responsibility.&nbsp; All Page_Load needs are the final values.
</p>
<p>Since we have decided that the Page_Load no longer needs to have intimate knowledge of these details, we can refactor them out. Our first refactoring step is to create a class that is responsible solely for providing the authorization information to the
 Default.aspx.cs file. We’ll call this class AuthorizationServices. Instead of diving straight into the contents of AuthorizationServices, let’s look at how we want to use it in the Default.aspx.cs Page_Load method. What we want to do is eliminate all of the
 individual calls to the AuthChecker class and replace them with a single call that returns all of the same authorization information, but in a consolidated fashion. That is, we are looking for something like this:</p>
<pre>AuthorizationServices authorizationServices = new AuthorizationServices();</pre>
<pre>CurrentCapabilitiesStatus currentUser = authorizationServices.RetrieveCurrentStatusFor(CurrentPage);</pre>
<pre>&nbsp;</pre>
<p>That single call to AuthorizationServices is what we want to determine what levels of permission are available for the current user. The results of making that method call are returned in a CurrentCapabilitiesStatus object. That object is quite simple and
 has only properties containing the different authorization values.</p>
<p>&nbsp;</p>
<p>SIDEBAR—When refactoring a brownfield application, it often helps to look at things from the client perspective, as we did here. We determined how we want the code to look from the perspective of the Page_Load method in an ideal scenario, and then worked
 toward making it happen. This is an effective way of isolating the responsibility of a class and separating other responsibilities into other classes.</p>
<p>&nbsp;</p>
<p>Now that we know what we want the usage of the code to look like, we can move on to creating those classes and filling them out. Since our refactoring step is to remove the detailed information about the authorization concern out of the Page_Load method,
 let’s start there. In this case, the simplest refactoring task is to cut and paste the existing AuthChecker calls in the Page_Load code into the RetrieveCurrentStatusFor method.&nbsp; To make the AuthChecker code compile and function, we will need to move some
 other code as well. This will include:</p>
<pre>string currentUsername = SessionFacade.GetCurrentUsername();</pre>
<pre>string[] currentGroups = SessionFacade.GetCurrentGroupNames();</pre>
<pre>&nbsp;</pre>
<pre>var canEdit = false;</pre>
<pre>var canEditWithApproval = false;</pre>
<pre>Pages.CanEditPage(currentPage, currentUsername, currentGroups, out canEdit, out canEditWithApproval);</pre>
<pre>&nbsp;</pre>
<p>Now that we have all of that code in the RetrieveCurrentStatusFor method, the final step is to create and populate the output object type of CurrentCapabilitiesStatus. As we mentioned before, this is a simple class that contains only properties in it. You
 may have noticed in an earlier code snippet that we assigned an instance of this object to a variable named “currentUser”. At the time, this may have seemed odd, but when we combine that with the property names, we see that the resulting code in Page_Load
 becomes more intention-revealing. Since we don’t know what the intended use of the properties are when we’re inside the CurrentCapabilitiesStatus class, let’s step back to the Page_Load method and look at how we intend to use them there.</p>
<p>Chances are, if you did a complete cut and paste from Page_Load to AuthorizationServices.RetrieveCurrentStatusFor, there will be noncompiling code in the Page_Load method now.&nbsp; This should be limited to the variables that used to be in the method, but are
 now being moved to the CurrentCapabilitiesStatus class as properties. These are the points of usage that we’re looking for. The first one that you will see is an &quot;if&quot; statement that checks to see if the current user cannot view the current page. Let’s change
 this to use our “currentUser” variable now.</p>
<pre>if(!currentUser.CanView) {</pre>
<pre>&nbsp;&nbsp;&nbsp; // body of method remains unchanged</pre>
<pre>}</pre>
<pre>&nbsp;</pre>
<p>This is where you see how using the name currentUser starts to come into play. When scanning this code, it should be clear exactly what we are doing in this method. We have decided to name the property “CanView”, since we are predominantly working with positive
 questions when using the CurrentCapabilitiesStatus variable type. If you were to go through the rest of the authorization information used, you would end up with properties for CanDownloadAttachments, CanSetPerms, CanAdmin, CanViewDiscussion, CanEditDiscussion,
 CanManageDiscussion, CanEdit, and CanEditWithApproval, all defined on the CurrentCapabilitiesStatus object.</p>
<p>Once you have those properties added to the CurrentCapabilitiesStatus object and being used in the Page_Load method where needed, we still have one remaining loose end to tie up. While we moved the authorization code from Page_Load to the RetrieveCurrentStatusFor
 method in AuthorizationServices, we didn’t actually create a CurrentCapabilitiesStatus object and populate it. Doing that property value assignment is the final step in this refactoring.</p>
<h2>Other videos from this article</h2>
<ul>
<li>
<div><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-SoC-Overview/" shape="rect">Initial Examination Of Default AspxCs</a></div>
</li><li>
<div><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-SoC-Principles-to-Practice/" shape="rect">Refactoring To AuthorizationServices The Long Way</a></div>
</li><li>
<div><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-SoC-The-Big-Picture/" shape="rect">Refactoring To AuthorizationServices The Short Way</a></div>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/en-us/magazine/ee210417" shape="rect">
http://msdn.microsoft.com/en-us/magazine/ee210417</a></p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:89e13d841c4848acb47e9deb017721e4">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-SoC-Principles-to-Practice</comments>
      <itunes:summary>
Extreme ASP.NET Makeover: Separation of Concerns – Principles to Practice
&amp;nbsp; 
When looking at the code, the first thing that our attention was drawn to was the repetitive nature of the authorization code.&amp;nbsp; As you can see in the code in
Figure 1, there are a large number of calls to retrieve single permission values. 
Figure 1 Default.aspx Page_Load Code 
string currentUsername = SessionFacade.GetCurrentUsername();
string[] currentGroups = SessionFacade.GetCurrentGroupNames();
&amp;nbsp;
bool canView = AuthChecker.Instance.CheckActionForPage(currentPage, Actions.ForPages.ReadPage, currentUsername, currentGroups);
bool canEdit = false;
bool canEditWithApproval = false;
Pages.CanEditPage(currentPage, currentUsername, currentGroups, out canEdit, out canEditWithApproval);
if(canEditWithApproval &amp;amp;&amp;amp; canEdit) canEditWithApproval = false;
bool canDownloadAttachments = AuthChecker.Instance.CheckActionForPage(currentPage, Actions.ForPages.DownloadAttachments, currentUsername, currentGroups);
bool canSetPerms = AuthChecker.Instance.CheckActionForGlobals(Actions.ForGlobals.ManagePermissions, currentUsername, currentGroups);
bool canAdmin = AuthChecker.Instance.CheckActionForPage(currentPage, Actions.ForPages.ManagePage, currentUsername, currentGroups);
bool canViewDiscussion = AuthChecker.Instance.CheckActionForPage(currentPage, Actions.ForPages.ReadDiscussion, currentUsername, currentGroups);
bool canPostDiscussion = AuthChecker.Instance.CheckActionForPage(currentPage, Actions.ForPages.PostDiscussion, currentUsername, currentGroups);
bool canManageDiscussion = AuthChecker.Instance.CheckActionForPage(currentPage, Actions.ForPages.ManageDiscussion, currentUsername, currentGroups);
&amp;nbsp;
Now, we certainly can’t look at this code and simply say, “Get rid of all that stuff”, because it is necessary for the page to properly function. But how permissions are retrieved, whether from the AuthChecker or Pages or even hard-coding, is the responsibility</itunes:summary>
      <itunes:duration>945</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-SoC-Principles-to-Practice</link>
      <pubDate>Fri, 10 Jul 2009 23:40:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-SoC-Principles-to-Practice</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/477840_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/477840_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/4/8/7/7/4/RefactoringToAuthorizationServicesTheLongWay_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/4/8/7/7/4/RefactoringToAuthorizationServicesTheLongWay_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/4/8/7/7/4/RefactoringToAuthorizationServicesTheLongWay_2MB_ch9.wmv" expression="full" duration="945" fileSize="43259090" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/4/8/7/7/4/RefactoringToAuthorizationServicesTheLongWay_ch9.mp3" expression="full" duration="945" fileSize="7564820" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/4/8/7/7/4/RefactoringToAuthorizationServicesTheLongWay_ch9.mp4" expression="full" duration="945" fileSize="32025636" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/4/8/7/7/4/RefactoringToAuthorizationServicesTheLongWay_ch9.wma" expression="full" duration="945" fileSize="15301357" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/4/8/7/7/4/RefactoringToAuthorizationServicesTheLongWay_ch9.wmv" expression="full" duration="945" fileSize="52795113" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/4/8/7/7/4/RefactoringToAuthorizationServicesTheLongWay_Zune_ch9.wmv" expression="full" duration="945" fileSize="28011093" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/ch9/0/4/8/7/7/4/RefactoringToAuthorizationServicesTheLongWay_s_ch9.wmv" expression="full" duration="945" fileSize="269" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/4/8/7/7/4/RefactoringToAuthorizationServicesTheLongWay_ch9.wmv" length="52795113" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-SoC-Principles-to-Practice/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
    </item>
  <item>
      <title>Extreme ASP.NET Makeover: SoC - Overview</title>
      <description><![CDATA[
<h1>Extreme ASP.NET Makeover: Separation of Concerns - Overview</h1>
<p>&nbsp;</p>
<p>Separation of concerns is a concept that, when applied to software development, deals with creating distance between dissimilar aspects of your code. This may seem like a complicated statement, but we all have dealt with it in the past, even if we haven’t
 known it.&nbsp; You’ve probably heard that you shouldn’t have your data access code in your Web page.&nbsp; That is separation of concerns.&nbsp; The Web page shouldn’t directly know how to deal with database concerns like connection strings, command objects, and so on.</p>
<p>Why do we care? Well, separation of concerns is one of the concepts that allows us to work on a specific aspect of an application without having significant impact on other parts of the application.&nbsp; Think of it this way: Should I be able to work on the
 engine in my car without having to deal with the wheels?&nbsp; In our software, we shouldn’t have to deal with the database infrastructure when we’re working in aspx.cs (or aspx.vb) files.</p>
<p>If we aren’t paying attention to separation of concerns, we would start seeing some common issues while working on our codebases.&nbsp; We’ve all been in a situation where you try to change what appears to be a little thing and end up having to dive deep into
 the bowels of your application’s infrastructure.&nbsp; To take a quick example, say you wanted to change how you determine what the user is authorized to do on a page.&nbsp; In ScrewTurn, permissions are determined through a call to the AuthChecker singleton class.
 (We’ll discuss how to cure “singletonitis” in an upcoming article. For now, we’ll focus on separation of concerns.) To determine if the user has permission to download an attachment, for example, we make the following call:</p>
<p>AuthChecker.Instance.CheckActionForPage(currentPage, </p>
<p>Actions.ForPages.DownloadAttachments,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p>currentUsername, currentGroups)</p>
<p>&nbsp;</p>
<p>If we look at this one line of code on its own, nothing immediately appears to be a problem. But let’s imagine that this call exists in many, or all, of the Web pages in the application.&nbsp; What we see then is that changing how you determine a user’s ability
 to download attachments will require you to modify each and every one of those Web pages.&nbsp; That is, there is a ripple effect of one change imposing the need to modify nonrelated code.</p>
<p>There is another issue at play here. Consider the amount of intimate detail about authorization that exists in the application.&nbsp; A good example is the Page_Load method in the Default.aspx.cs file.&nbsp; In Page_Load, there are calls for security information for
 a given user, including the following:</p>
<ul>
<li>
<div>Can the user view a page?</div>
</li><li>
<div>Can the user download attachments on a page?</div>
</li><li>
<div>Can the user set permissions?</div>
</li><li>
<div>Can the user administer a page?</div>
</li><li>
<div>Can the user view discussions on a page?</div>
</li><li>
<div>Can the user post to discussions on a page?</div>
</li><li>
<div>Can the user manage discussions on a page?</div>
</li><li>
<div>Can the user edit a page?</div>
</li></ul>
<p>This is a lot of authorization for the Page_Load method to have to know about. Of course, the Page_Load method
<i>does</i> need to retrieve and use this information. But our question is this: Does it need to know
<i>how</i> to retrieve all of those pieces of information? And just as important, does it need to be done for each individual task that could be performed?&nbsp; Asked a different way, does Page_Load need to have a full understanding of how security is being handled?
 No, it doesn’t. Can it simply ask some other class to have all security information given to it? Yes, it can! Page_Load simply needs to get the permissions, and it shouldn’t know or care about the mechanics of how this is accomplished.
</p>
<h1>Warning: Code Maintenance Ahead</h1>
<p>The ultimate goal when applying separation of concerns is maintainability. This being a brownfield application, ScrewTurn Wiki likely has areas that are hard to work with because classes are doing too much and have become fragile. The slightest change to
 one class has ripple effects throughout the code. By separating concerns, we can break apart the code into its individual pieces so that when you look at a class, you aren’t distracted by extra code that is not part of its responsibility.</p>
<p>This is a good segue into one of the ways you can start separating concerns in your classes. Like many things in our craft, knowing when separation of concerns has been broken is not easy to see. There is one simple thing you can ask yourself when you look
 at any piece of code:</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Does this code belong in this class?</p>
<p>Or put another way:</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Is this part of the class’s immediate responsibility?</p>
<p>The idea of responsibility is an important one. When we start thinking of separation of concerns and of classes having responsibility, we gravitate toward the Single Responsibility Principle:</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A class should have only one reason to change. – Robert C. Martin in
<i>Agile Software Development: Principles, Patterns, and Practices</i> </p>
<p>Earlier, when we were discussing the contents of the Page_Load method in the Default.aspx.cs file, we proposed asking the question, “Does it need to know how to retrieve all of those pieces of information individually?” In our case, the answer should be
 no.&nbsp; The Page_Load method should know only that it needs to retrieve authorization information, not the gory details of how that information is retrieved.&nbsp; Separating those two needs is at the root of determining separation of concerns.</p>
<p>There’s yet another good reason to try to separate concerns in your application. In a previous article, we mentioned user interface testing with WatiN. If you’ve tried setting up UI testing, you’ll quickly discover that it can become cumbersome to create
 this safety net. The tests are slow and often need to be reworked as the UI changes. By moving code out of the ASPX pages and into separate classes, we open up the testing arena and are able to write true unit tests, ones that test only a single class in isolation,
 without having to fire up a browser instance, Web server, and database. These tests are faster, less fragile, and can lead us to a place where the code in the ASPX pages is limited to interaction between the various UI widgets.
</p>
<h1>From Principles to Practice</h1>
<p>Enough talk. Let’s take this and apply it to the ScrewTurn Wiki codebase. First, we’ll start with the Default.aspx page’s code behind file. To make things easy, we will start at the top and look at the contents of the Page_Load. This is a busy method and
 not uncommon for a brownfield application. In this method alone, we can see several responsibilities:</p>
<ul>
<li>
<div>Redirect the page if necessary</div>
</li><li>
<div>Determine the user’s rights for the page</div>
</li><li>
<div>Set up various UI widgets</div>
</li><li>
<div>Display the contents of the requested wiki page</div>
</li></ul>
<p>&nbsp;</p>
<h2>Other videos from this article</h2>
<ul>
<li>
<div><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-SoC-Overview/" shape="rect">Initial Examination Of Default AspxCs</a></div>
</li><li>
<div><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-SoC-Principles-to-Practice/" shape="rect">Refactoring To AuthorizationServices The Long Way</a></div>
</li><li>
<div><a shape="rect" href="http://channel9.msdn.com/posts/howarddierking/Extreme-ASPNET-Makeover-SoC-The-Big-Picture/" shape="rect">Refactoring To AuthorizationServices The Short Way</a></div>
</li></ul>
<p>Read the full article at <a shape="rect" href="http://msdn.microsoft.com/en-us/magazine/ee210417" shape="rect">
http://msdn.microsoft.com/en-us/magazine/ee210417</a></p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:711c044050904a98b8c99deb01772612">]]></description>
      <comments>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-SoC-Overview</comments>
      <itunes:summary>
Extreme ASP.NET Makeover: Separation of Concerns - Overview
&amp;nbsp; 
Separation of concerns is a concept that, when applied to software development, deals with creating distance between dissimilar aspects of your code. This may seem like a complicated statement, but we all have dealt with it in the past, even if we haven’t
 known it.&amp;nbsp; You’ve probably heard that you shouldn’t have your data access code in your Web page.&amp;nbsp; That is separation of concerns.&amp;nbsp; The Web page shouldn’t directly know how to deal with database concerns like connection strings, command objects, and so on. 
Why do we care? Well, separation of concerns is one of the concepts that allows us to work on a specific aspect of an application without having significant impact on other parts of the application.&amp;nbsp; Think of it this way: Should I be able to work on the
 engine in my car without having to deal with the wheels?&amp;nbsp; In our software, we shouldn’t have to deal with the database infrastructure when we’re working in aspx.cs (or aspx.vb) files. 
If we aren’t paying attention to separation of concerns, we would start seeing some common issues while working on our codebases.&amp;nbsp; We’ve all been in a situation where you try to change what appears to be a little thing and end up having to dive deep into
 the bowels of your application’s infrastructure.&amp;nbsp; To take a quick example, say you wanted to change how you determine what the user is authorized to do on a page.&amp;nbsp; In ScrewTurn, permissions are determined through a call to the AuthChecker singleton class.
 (We’ll discuss how to cure “singletonitis” in an upcoming article. For now, we’ll focus on separation of concerns.) To determine if the user has permission to download an attachment, for example, we make the following call: 
AuthChecker.Instance.CheckActionForPage(currentPage,  
Actions.ForPages.DownloadAttachments,&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;</itunes:summary>
      <itunes:duration>250</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-SoC-Overview</link>
      <pubDate>Fri, 10 Jul 2009 23:39:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-SoC-Overview</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/477839_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/477839_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/3/8/7/7/4/InitialExaminationOfDefaultAspxCs_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/3/8/7/7/4/InitialExaminationOfDefaultAspxCs_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/3/8/7/7/4/InitialExaminationOfDefaultAspxCs_2MB_ch9.wmv" expression="full" duration="250" fileSize="6791010" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/3/8/7/7/4/InitialExaminationOfDefaultAspxCs_ch9.mp3" expression="full" duration="250" fileSize="2006980" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/3/8/7/7/4/InitialExaminationOfDefaultAspxCs_ch9.mp4" expression="full" duration="250" fileSize="7289575" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/3/8/7/7/4/InitialExaminationOfDefaultAspxCs_ch9.wma" expression="full" duration="250" fileSize="4060389" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/3/8/7/7/4/InitialExaminationOfDefaultAspxCs_Zune_ch9.wmv" expression="full" duration="250" fileSize="6342923" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/3/8/7/7/4/InitialExaminationOfDefaultAspxCs_2MB_ch9.wmv" length="6791010" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Howard Dierking</dc:creator>
      <itunes:author>Howard Dierking</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/howarddierking/Extreme-ASPNET-Makeover-SoC-Overview/RSS</wfw:commentRss>
      <category>ASP.NET</category>
      <category>Brownfield Development</category>
      <category>MSDN Magazine</category>
      <category>Patterns</category>
    </item>
  <item>
      <title>Mickey Mouse pattern by Ward Bell : At the p&amp;p summit</title>
      <description><![CDATA[You have heard of and probably used&nbsp;patterns in your projects. But have you heard of the &quot;Mickey Mouse&quot; pattern. In this short video,
<a href="http://pnpsummit.com/west2009/west2009presenters.aspx#wardb" title="Ward's bio">
Ward Bell</a>, gives you a quick overview of this unheard of pattern.<br /><br />Ward delivered a great&nbsp;session at the last summit and is coming back to present at this year's
<a href="http://tinyurl.com/pnpsummit">p&amp;p summit</a>.<br /><br />For more information on p&amp;p summit and to register, check out <a href="http://tinyurl.com/pnpsummit">
http://tinyurl.com/pnpsummit</a>. To become a fan of p&amp;p summit in Facebook, click
<a href="http://www.facebook.com/pages/Microsoft-patterns-practices-Summit/#/pages/Microsoft-patterns-practices-Summit/79454152413?ref=ts" title="FB p&amp;p summit page">
here</a>. <br /><br />Happy Watching!  <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:67d4eb43266f4de1910c9df800427141">]]></description>
      <comments>http://channel9.msdn.com/Blogs/akMSFT/Mickey-Mouse-pattern-by-Ward-Bell--At-the-pp-summit</comments>
      <itunes:summary>You have heard of and probably used&amp;nbsp;patterns in your projects. But have you heard of the &amp;quot;Mickey Mouse&amp;quot; pattern. In this short video,

Ward Bell, gives you a quick overview of this unheard of pattern.Ward delivered a great&amp;nbsp;session at the last summit and is coming back to present at this year&#39;s
p&amp;amp;p summit.For more information on p&amp;amp;p summit and to register, check out 
http://tinyurl.com/pnpsummit. To become a fan of p&amp;amp;p summit in Facebook, click

here. Happy Watching! </itunes:summary>
      <itunes:duration>55</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/akMSFT/Mickey-Mouse-pattern-by-Ward-Bell--At-the-pp-summit</link>
      <pubDate>Tue, 07 Jul 2009 18:58:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/akMSFT/Mickey-Mouse-pattern-by-Ward-Bell--At-the-pp-summit</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/477279_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/477279_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/7/2/7/7/4/PnPSummitWardPromo_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/7/2/7/7/4/PnPSummitWardPromo_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/7/2/7/7/4/PnPSummitWardPromo_2MB_ch9.wmv" expression="full" duration="55" fileSize="21686381" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/7/2/7/7/4/PnPSummitWardPromo_ch9.mp3" expression="full" duration="55" fileSize="445514" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/7/2/7/7/4/PnPSummitWardPromo_ch9.mp4" expression="full" duration="55" fileSize="5422546" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/7/2/7/7/4/PnPSummitWardPromo_ch9.wma" expression="full" duration="55" fileSize="918205" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/7/2/7/7/4/PnPSummitWardPromo_ch9.wmv" expression="full" duration="55" fileSize="7861773" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/7/2/7/7/4/PnPSummitWardPromo_Zune_ch9.wmv" expression="full" duration="55" fileSize="7829753" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/ch9/9/7/2/7/7/4/PnPSummitWardPromo_s_ch9.wmv" expression="full" duration="55" fileSize="217" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/9/7/2/7/7/4/PnPSummitWardPromo_ch9.wmv" length="7861773" type="video/x-ms-wmv"></enclosure>
      <dc:creator>ajoy krishnamoorthy</dc:creator>
      <itunes:author>ajoy krishnamoorthy</itunes:author>
      <slash:comments>1</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/akMSFT/Mickey-Mouse-pattern-by-Ward-Bell--At-the-pp-summit/RSS</wfw:commentRss>
      <category>Fun</category>
      <category>P&amp;P</category>
      <category>p&amp;p summit</category>
      <category>Patterns</category>
      <category>Patterns and Practices</category>
      <category>promo</category>
    </item>
  <item>
      <title>ARCast.TV - Implementing a Hybrid Architecture Based on SOA and ROA in the Enterprise</title>
      <description><![CDATA[In this interview, <a shape="rect" href="http://tinyurl.com/kevinisrael" target="_blank" shape="rect">
Kevin Israel</a>, Visual Studio Team System <a shape="rect" href="http://vsteamsystemcentral.com/cs21/blogs/kevin_israel/default.aspx" shape="rect">
MVP</a>, shares with <a shape="rect" href="http://blogs.msdn.com/zxue/" shape="rect">
Zhiming Xue </a>his thoughts on implementation of a hybrid architecture based on SOA and ROA in the enterprise space. Kevin explains what Resource Oriented Architecture (ROA) is and, through examples, highlights its key differences from Service Oriented Architecture
 (SOA). He argues that while the two architectural patterns share the same common problem domains such as versioning and application manageability, they work differently in practice. ROA services or RESTful services may be used to bring resources to the user,
 whereas SOA services are typically created to process business logic. Therefore, the crux of the hybrid architecture implementation is to use them together and use them for their intended purposes. Kevin believes that as cloud computing and enterprise meshup
 applications start to emerge, more applications based on the hybrid architecture of SOA and ROA may be seen in the enterprise.
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:7b9f95e8023b4e179ad29dea00c0d4f6">]]></description>
      <comments>http://channel9.msdn.com/Shows/ARCast.TV/ARCastTV-Implementing-a-Hybrid-Architecture-Based-on-SOA-and-ROA-in-the-Enterprise</comments>
      <itunes:summary>In this interview, 
Kevin Israel, Visual Studio Team System 
MVP, shares with 
Zhiming Xue his thoughts on implementation of a hybrid architecture based on SOA and ROA in the enterprise space. Kevin explains what Resource Oriented Architecture (ROA) is and, through examples, highlights its key differences from Service Oriented Architecture
 (SOA). He argues that while the two architectural patterns share the same common problem domains such as versioning and application manageability, they work differently in practice. ROA services or RESTful services may be used to bring resources to the user,
 whereas SOA services are typically created to process business logic. Therefore, the crux of the hybrid architecture implementation is to use them together and use them for their intended purposes. Kevin believes that as cloud computing and enterprise meshup
 applications start to emerge, more applications based on the hybrid architecture of SOA and ROA may be seen in the enterprise.
</itunes:summary>
      <itunes:duration>991</itunes:duration>
      <link>http://channel9.msdn.com/Shows/ARCast.TV/ARCastTV-Implementing-a-Hybrid-Architecture-Based-on-SOA-and-ROA-in-the-Enterprise</link>
      <pubDate>Mon, 06 Jul 2009 19:56:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Shows/ARCast.TV/ARCastTV-Implementing-a-Hybrid-Architecture-Based-on-SOA-and-ROA-in-the-Enterprise</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/469900_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/469900_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/0/9/9/6/4/ARCastImplementingAHybridArchitecture_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/0/9/9/6/4/ARCastImplementingAHybridArchitecture_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/0/9/9/6/4/ARCastImplementingAHybridArchitecture_2MB_ch9.wmv" expression="full" duration="991" fileSize="309852000" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/0/9/9/6/4/ARCastImplementingAHybridArchitecture_ch9.mp3" expression="full" duration="991" fileSize="7932688" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/0/9/9/6/4/ARCastImplementingAHybridArchitecture_ch9.mp4" expression="full" duration="991" fileSize="97477528" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/0/9/9/6/4/ARCastImplementingAHybridArchitecture_ch9.wma" expression="full" duration="991" fileSize="16040341" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/0/9/9/6/4/ARCastImplementingAHybridArchitecture_ch9.wmv" expression="full" duration="991" fileSize="60043389" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/0/9/9/6/4/ARCastImplementingAHybridArchitecture_Zune_ch9.wmv" expression="full" duration="991" fileSize="140507369" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/ch9/0/0/9/9/6/4/ARCastImplementingAHybridArchitecture_s_ch9.wmv" expression="full" duration="991" fileSize="255" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/0/0/9/9/6/4/ARCastImplementingAHybridArchitecture_ch9.wmv" length="60043389" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Bob Familiar</dc:creator>
      <itunes:author>Bob Familiar</itunes:author>
      <slash:comments>1</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Shows/ARCast.TV/ARCastTV-Implementing-a-Hybrid-Architecture-Based-on-SOA-and-ROA-in-the-Enterprise/RSS</wfw:commentRss>
      <category>ARCast</category>
      <category>Architects</category>
      <category>Architecture</category>
      <category>Patterns</category>
      <category>Resource Oriented Architecture</category>
      <category>REST</category>
      <category>RESTful Services</category>
      <category>ROA</category>
      <category>Service Oriented Architecture </category>
      <category>Web Services</category>
    </item>
  <item>
      <title>p&amp;p SharePoint Development Guidance v2 - What&#39;s in Drop 10?</title>
      <description><![CDATA[
<p>As we mentioned in our <a href="http://channel9.msdn.com/posts/akMSFT/What-is-in-pnp-SharePoint-Guidance-v20/" title="Blog post">
earlier post</a>, we release a drop from our SharePoint Guidance project every two weeks which is the duration of our iteration.&nbsp;We released&nbsp;Drop&nbsp;10 to our&nbsp;<a href="http://spg.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=26609">CodePlex project site</a>
 last week. In this webcast<a href="http://www.erwinvandervalk.net/">, Erwin van der Valk</a> and
<a href="http://blogs.msdn.com/francischeung/">Francis Cheung</a>&nbsp;are discussing the changes that have been made in iteration 10 of the SharePoint developer Guidance. The primary focus of iteration 10 was to create and extend couple of reusable assets that
 can help you to create better SharePoint applications:</p>
<ul>
<li>A Hierarchical configuration manager, that allows you to store configuration values at the Farm level, allow you to override them in lower levels.
</li><li>A generic Service Locator for sharepoint that stores it’s typemappings in config.
</li><li>A Sitemap provider that stores it’s sitemap in hierarchical config. </li><li>Reusable workflow activities for SubSite creation, that help you to implement your own SubSite creation process.
</li></ul>
<p>With the conclusion of this iteration, the SharePoint Guidance v2.0 project is now feature complete. The next iterations will focus primarily on bug fixes, documentation and quickstarts.<br />&nbsp;</p>
<p>Happy Watching!</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:be707be755aa4e4b81259df800428626">]]></description>
      <comments>http://channel9.msdn.com/Blogs/akMSFT/pp-SharePoint-Development-Guidance-v2-Whats-in-Drop-10</comments>
      <itunes:summary>
As we mentioned in our 
earlier post, we release a drop from our SharePoint Guidance project every two weeks which is the duration of our iteration.&amp;nbsp;We released&amp;nbsp;Drop&amp;nbsp;10 to our&amp;nbsp;CodePlex project site
 last week. In this webcast, Erwin van der Valk and
Francis Cheung&amp;nbsp;are discussing the changes that have been made in iteration 10 of the SharePoint developer Guidance. The primary focus of iteration 10 was to create and extend couple of reusable assets that
 can help you to create better SharePoint applications: 

A Hierarchical configuration manager, that allows you to store configuration values at the Farm level, allow you to override them in lower levels.
A generic Service Locator for sharepoint that stores it’s typemappings in config.
A Sitemap provider that stores it’s sitemap in hierarchical config. Reusable workflow activities for SubSite creation, that help you to implement your own SubSite creation process.

With the conclusion of this iteration, the SharePoint Guidance v2.0 project is now feature complete. The next iterations will focus primarily on bug fixes, documentation and quickstarts.&amp;nbsp; 
Happy Watching! 
</itunes:summary>
      <itunes:duration>1857</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/akMSFT/pp-SharePoint-Development-Guidance-v2-Whats-in-Drop-10</link>
      <pubDate>Wed, 03 Jun 2009 04:50:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/akMSFT/pp-SharePoint-Development-Guidance-v2-Whats-in-Drop-10</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/471663_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/471663_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/6/6/1/7/4/SPGVideoDrop10_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/6/6/1/7/4/SPGVideoDrop10_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/6/6/1/7/4/SPGVideoDrop10_2MB_ch9.wmv" expression="full" duration="1857" fileSize="58004823" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/6/6/1/7/4/SPGVideoDrop10_ch9.mp3" expression="full" duration="1857" fileSize="14861774" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/6/6/1/7/4/SPGVideoDrop10_ch9.mp4" expression="full" duration="1857" fileSize="65190171" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/6/6/1/7/4/SPGVideoDrop10_ch9.wma" expression="full" duration="1857" fileSize="30054001" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/6/6/1/7/4/SPGVideoDrop10_Zune_ch9.wmv" expression="full" duration="1857" fileSize="75184565" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/3/6/6/1/7/4/SPGVideoDrop10_2MB_ch9.wmv" length="58004823" type="video/x-ms-wmv"></enclosure>
      <dc:creator>ajoy krishnamoorthy</dc:creator>
      <itunes:author>ajoy krishnamoorthy</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/akMSFT/pp-SharePoint-Development-Guidance-v2-Whats-in-Drop-10/RSS</wfw:commentRss>
      <category>Configuration</category>
      <category>Configuration Manager</category>
      <category>generic service locator</category>
      <category>guidance</category>
      <category>P&amp;P</category>
      <category>Patterns</category>
      <category>Patterns &amp; Practices</category>
      <category>Patterns and Practices</category>
      <category>reference implementation</category>
      <category>service locator</category>
      <category>SharePoint</category>
      <category>sitemap provider</category>
      <category>SubSite creation</category>
    </item>
  <item>
      <title>p&amp;p SharePoint Development Guidance v2 - What&#39;s in Drop 9?</title>
      <description><![CDATA[
<p>As we mentioned in our <a href="http://channel9.msdn.com/posts/akMSFT/What-is-in-pnp-SharePoint-Guidance-v20/" title="Blog post">
earlier post</a>, we release a drop from our SharePoint Guidance project every two weeks which is the duration of our iteration.&nbsp;We released&nbsp;Drop&nbsp;9 to our&nbsp;<a href="http://spg.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=26609">CodePlex project site</a>
 last week. In this webcast<a href="http://www.erwinvandervalk.net/">, Erwin van der Valk</a> and
<a href="http://blogs.msdn.com/francischeung/">Francis Cheung</a>&nbsp;discuss the improvements that have been made in iteration 9 of the SharePoint Developer Guidance V2. In this iteration&nbsp;the team&nbsp;focused mainly on improving the code. &nbsp;For example, the fake SSO
 provider has been replaced by a solution that follows the <a href="http://msdn.microsoft.com/en-us/library/aa355058.aspx">
trusted façade</a> pattern. Also, the WCF proxies and their repositories have been refactored and improved quite a bit. This video guides you through many of the improvements that have been made in the iteration.
</p>
<p>Happy Watching!</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:9b434961dd6b405fa3a59df80042985d">]]></description>
      <comments>http://channel9.msdn.com/Blogs/akMSFT/pp-SharePoint-Development-Guidance-v2-Whats-in-Drop-9</comments>
      <itunes:summary>
As we mentioned in our 
earlier post, we release a drop from our SharePoint Guidance project every two weeks which is the duration of our iteration.&amp;nbsp;We released&amp;nbsp;Drop&amp;nbsp;9 to our&amp;nbsp;CodePlex project site
 last week. In this webcast, Erwin van der Valk and
Francis Cheung&amp;nbsp;discuss the improvements that have been made in iteration 9 of the SharePoint Developer Guidance V2. In this iteration&amp;nbsp;the team&amp;nbsp;focused mainly on improving the code. &amp;nbsp;For example, the fake SSO
 provider has been replaced by a solution that follows the 
trusted fa&#231;ade pattern. Also, the WCF proxies and their repositories have been refactored and improved quite a bit. This video guides you through many of the improvements that have been made in the iteration.
 
Happy Watching! 
</itunes:summary>
      <itunes:duration>1266</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/akMSFT/pp-SharePoint-Development-Guidance-v2-Whats-in-Drop-9</link>
      <pubDate>Wed, 20 May 2009 17:23:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/akMSFT/pp-SharePoint-Development-Guidance-v2-Whats-in-Drop-9</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/469916_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/469916_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/6/1/9/9/6/4/SPGv2Drop9Video_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/6/1/9/9/6/4/SPGv2Drop9Video_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/6/1/9/9/6/4/SPGv2Drop9Video_2MB_ch9.wmv" expression="full" duration="1266" fileSize="40133219" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/6/1/9/9/6/4/SPGv2Drop9Video_ch9.mp3" expression="full" duration="1266" fileSize="10136517" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/6/1/9/9/6/4/SPGv2Drop9Video_ch9.mp4" expression="full" duration="1266" fileSize="48703702" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/6/1/9/9/6/4/SPGv2Drop9Video_ch9.wma" expression="full" duration="1266" fileSize="20504285" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/6/1/9/9/6/4/SPGv2Drop9Video_Zune_ch9.wmv" expression="full" duration="1266" fileSize="57069019" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/6/1/9/9/6/4/SPGv2Drop9Video_2MB_ch9.wmv" length="40133219" type="video/x-ms-wmv"></enclosure>
      <dc:creator>ajoy krishnamoorthy</dc:creator>
      <itunes:author>ajoy krishnamoorthy</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/akMSFT/pp-SharePoint-Development-Guidance-v2-Whats-in-Drop-9/RSS</wfw:commentRss>
      <category>guidance</category>
      <category>P&amp;P</category>
      <category>Patterns</category>
      <category>Patterns &amp; Practices</category>
      <category>Patterns and Practices</category>
      <category>SharePoint</category>
      <category>SSO</category>
      <category>trusted facade</category>
      <category>WCF Proxies</category>
    </item>
  <item>
      <title>p&amp;p SharePoint Development Guidance v2 - What&#39;s in Drop 8?</title>
      <description><![CDATA[
<p>As we mentioned in our <a href="http://channel9.msdn.com/posts/akMSFT/What-is-in-pnp-SharePoint-Guidance-v20/" title="Blog post">
earlier post</a>, we release a drop from our SharePoint Guidance project every two weeks which is the duration of our iteration.&nbsp;We released&nbsp;Drop 8 to our&nbsp;<a href="http://spg.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=26609">CodePlex project site</a>
 on April 24th. In this webcast<a href="http://www.erwinvandervalk.net/">, Erwin van der Valk</a> and
<a href="http://blogs.msdn.com/francischeung/">Francis Cheung</a> guide you through what’s new in drop 8 of the SharePoint Developer Guidance V2. They show how to do exception handling in Webparts and in ListItemEventReceivers and also walk you through the
 other changes that have been made to their reference implementation. Also check out this
<a href="http://blogs.msdn.com/erwinvandervalk/archive/2009/04/27/sharepoint-guidance-v2-drop-8.aspx">
blog post</a> about the drop.<br /><br />Happy Watching!</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Tags/patterns/RSS&WT.dl=0&WT.entryid=Entry:RSSView:70818f6821a5456c95c29df800429ea7">]]></description>
      <comments>http://channel9.msdn.com/Blogs/akMSFT/pp-SharePoint-Development-Guidance-v2-Whats-in-Drop-8</comments>
      <itunes:summary>
As we mentioned in our 
earlier post, we release a drop from our SharePoint Guidance project every two weeks which is the duration of our iteration.&amp;nbsp;We released&amp;nbsp;Drop 8 to our&amp;nbsp;CodePlex project site
 on April 24th. In this webcast, Erwin van der Valk and
Francis Cheung guide you through what’s new in drop 8 of the SharePoint Developer Guidance V2. They show how to do exception handling in Webparts and in ListItemEventReceivers and also walk you through the
 other changes that have been made to their reference implementation. Also check out this

blog post about the drop.Happy Watching! 
</itunes:summary>
      <itunes:duration>888</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/akMSFT/pp-SharePoint-Development-Guidance-v2-Whats-in-Drop-8</link>
      <pubDate>Thu, 30 Apr 2009 16:52:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/akMSFT/pp-SharePoint-Development-Guidance-v2-Whats-in-Drop-8</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/100/467414_100x75.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/previewImages/220/467414_220x165.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/4/1/4/7/6/4/pnpSPGv2Drop8video_large_ch9.png" height="240" width="320"></media:thumbnail>
      <media:thumbnail url="http://mschnlnine.vo.llnwd.net/d1/ch9/4/1/4/7/6/4/pnpSPGv2Drop8video_small_ch9.png" height="64" width="85"></media:thumbnail>
      <media:group>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/4/1/4/7/6/4/pnpSPGv2Drop8video_2MB_ch9.wmv" expression="full" duration="888" fileSize="28414335" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/4/1/4/7/6/4/pnpSPGv2Drop8video_ch9.mp3" expression="full" duration="888" fileSize="7110998" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/4/1/4/7/6/4/pnpSPGv2Drop8video_ch9.mp4" expression="full" duration="888" fileSize="35852024" type="video/mp4" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/4/1/4/7/6/4/pnpSPGv2Drop8video_ch9.wma" expression="full" duration="888" fileSize="14382133" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/4/1/4/7/6/4/pnpSPGv2Drop8video_ch9.wmv" expression="full" duration="888" fileSize="40378771" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://mschnlnine.vo.llnwd.net/d1/ch9/4/1/4/7/6/4/pnpSPGv2Drop8video_Zune_ch9.wmv" expression="full" duration="888" fileSize="38346751" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="mms://mschnlnine.wmod.llnwd.net/a1809/d1/ch9/4/1/4/7/6/4/pnpSPGv2Drop8video_s_ch9.wmv" expression="full" duration="888" fileSize="216" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://mschnlnine.vo.llnwd.net/d1/ch9/4/1/4/7/6/4/pnpSPGv2Drop8video_ch9.wmv" length="40378771" type="video/x-ms-wmv"></enclosure>
      <dc:creator>ajoy krishnamoorthy</dc:creator>
      <itunes:author>ajoy krishnamoorthy</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/akMSFT/pp-SharePoint-Development-Guidance-v2-Whats-in-Drop-8/RSS</wfw:commentRss>
      <category>exception handling</category>
      <category>guidance</category>
      <category>P&amp;P</category>
      <category>Patterns</category>
      <category>Patterns &amp; Practices</category>
      <category>Patterns and Practices</category>
      <category>reference implementation</category>
      <category>service locator</category>
      <category>SharePoint</category>
    </item>    
</channel>
</rss>