<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>AJ's blog</title>
	<atom:link href="http://ajdotnet.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ajdotnet.wordpress.com</link>
	<description>Thoughts and informations I think worthwhile to share...</description>
	<lastBuildDate>Thu, 22 Dec 2011 17:56:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ajdotnet.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>AJ's blog</title>
		<link>http://ajdotnet.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ajdotnet.wordpress.com/osd.xml" title="AJ&#039;s blog" />
	<atom:link rel='hub' href='http://ajdotnet.wordpress.com/?pushpress=hub'/>
		<item>
		<title>RIA with Silverlight&#8211;The Business Perspective</title>
		<link>http://ajdotnet.wordpress.com/2011/08/14/ria-with-silverlightthe-business-perspective/</link>
		<comments>http://ajdotnet.wordpress.com/2011/08/14/ria-with-silverlightthe-business-perspective/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 11:40:26 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SDX]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=966</guid>
		<description><![CDATA[If you read this, chances are that you are a developer and that you like Silverlight. And why not? Exciting platform, great features, outstanding tooling. But! If you’re a corporate developer, have you sold it to your management yet? If not, this post is for you. Silverlight is for RIA, and the domain of RIA [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=966&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you read this, chances are that you are a developer and that you like Silverlight. And why not? Exciting platform, great features, outstanding tooling. But! If you’re a corporate developer, <em>have you sold it to your management yet</em>? If not, this post is for you.</p>
<p><img style="display:inline;float:right;" src="http://ajdotnet.files.wordpress.com/2011/08/ria-developers.png" alt="" align="right" />Silverlight is for <a href="http://en.wikipedia.org/wiki/Rich_Internet_application" target="_blank">RIA</a>, and the domain of RIA applications is largely intranet or closed/controlled extranet user groups. This again is what is usually found in larger enterprise companies. Companies that usually have a vested interest in controlling their environment. And in terms of bringing software into production and of operations and maintenance afterwards, every new platform is one platform to many.</p>
<p>So, the odd developer comes along and talks about this great new technology. Does the management care? Probably not. What does it care about? Simple. <strong>Money!</strong> Money, as in <strong>costs</strong> for deployment and user support, hardware and licenses to get the stuff up and running, operations and developer training, maintenance. And money as in <strong>savings</strong> in the respective areas and – the cornerstone, as the business usually pays the bill – impact on the business. All usually subsumed under the term <strong>ROI</strong>.</p>
<p>About a year ago, I finished an analysis looking into RIA with Silverlight, conducted for a major customer. Not from the point of view of the developer, but that of business people, operations, and IT management:</p>
<blockquote><p><img src="http://ajdotnet.files.wordpress.com/2011/08/ria-perspectives.png" alt="" /></p></blockquote>
<p>So, let’s look briefly at each aspect…</p>
<p><strong>User/Business perspective…</strong></p>
<p>The business doesn’t exactly care for the platform Silverlight itself; it cares for its business benefits. Benefits as in<strong> improved user experience, streamlined business workflows, office integration, and so on</strong>. And since we had some lighthouse projects with Silverlight we were able to collect some customers’ voices:</p>
<blockquote><p>“This [streamlining with Silverlight] would reduce a [...] business process [...] from ~10 min to less than a minute.”</p>
<p>“Advanced user experience of Silverlight UI helps raising acceptance of new CRM system in business units”</p>
<p>“I was very impressed of the prototype implementation […] with Silverlight 3. Having analyzed the benefits of this technology I came to the conclusion that I want the […] development team to start using Silverlight as soon as possible. [...]”</p></blockquote>
<p>This is also confirmed by the typical research companies, like Gartner or Forrester:</p>
<blockquote><p>“Firms that measure the business impact of their RIAs say that rich applications meet or exceed their goals” (Forrester)</p>
<p><img src="http://ajdotnet.files.wordpress.com/2011/08/ria-forrester.png" alt="" /></p></blockquote>
<p><strong>Operations perspective…</strong></p>
<p>In production, the benefit of Silverlight applications (compared with respective conventional web based applications) is <strong>reduced server and network utilization</strong>.</p>
<p>For example, we had a (small but none-trivial) reference application at our disposal, which was implemented in ASP.NET as well as Silverlight (as part of an analysis to check the feasibility of Silverlight for LOB applications). We measured a particular use case with both implementations – starting the application and going through 10 steps, including navigation, searches, and selections. Both applications were used after a warm-up phase, meaning that the .xap file, as well as images and other static files had already been cached.</p>
<p>The particular numbers don’t matter, what matters is the difference between the amount of data that has been exchanged for each step (in case of navigations none at all for Silverlight). For the single steps:</p>
<blockquote><p><img src="http://ajdotnet.files.wordpress.com/2011/08/ria-netload1.png" alt="" /></p></blockquote>
<p>And accumulated over time:</p>
<blockquote><p><img src="http://ajdotnet.files.wordpress.com/2011/08/ria-netload2.png" alt="" /></p></blockquote>
<p>A ratio of roughly a tenth of the network utilization is quite some achievement – considering that the Silverlight application wasn’t even optimized to use local session state and caching, it should be even higher.</p>
<p>This should have a direct impact on the number of machines you need in your web farm. Add the fact that session state management on the client drastically reduces the demand for ASP.NET session state – usually realized with a SQL Server (Cluster) – there is yet another entry on the savings list.</p>
<p>On the down side is the deployment of the Silverlight plugin. For managed clients – especially if outsourcing the infrastructure comes into play – this may very well become a showstopper.</p>
<p><strong>IT Management perspective…</strong></p>
<p>With respect to development and maintenance, what IT Management should care about includes things like <strong>ability to deliver the business demands, development productivity, bug rates in production, costs for developer training, and so on</strong>.</p>
<p>Actually all areas in which Silverlight can shine, compared with other RIA technologies, and with the typical mix of web technologies as well:</p>
<ul>
<li>Rich, consistent, homogenous platform
<ul>
<li>.NET Framework (client and server), Visual Studio, Debugger, C#</li>
<li>Reduced technology mix, less technology gaps, less broad skill demands</li>
</ul>
</li>
<li>Improved code correctness and quality…
<ul>
<li>compiler checks, unit testing, code coverage, debugging, static code analysis, in-source-documentation, &#8230;</li>
</ul>
</li>
<li>Improved architecture and code
<ul>
<li>Clean concepts, coding patterns, clear separation of client code, lead to better architectures</li>
<li>Powerful abstractions lead to less code (up to 50% in one project), less complexity, less errors</li>
</ul>
</li>
</ul>
<p>Customers’ voices in this area:</p>
<blockquote><p>“between our desktop app and the website, we estimate 50% re-use of code”</p>
<p>“a .NET developer can pretty much be dropped into a SL project. […] This is a huge deal […]”</p>
<p>“As alternative for Silverlight we considered Flash. […] only Silverlight could provide a consistent development platform (.NET/C#). […]”</p></blockquote>
<p><strong> </strong></p>
<p><strong>Conclusion…</strong></p>
<p>Taking all this together, and considering that enterprise companies usually have the tooling and test environments (well…) readily available, this all adds up to something like the following bill:</p>
<blockquote><p><img title="RIA Return on Invest" src="http://ajdotnet.files.wordpress.com/2011/08/ria-roi.png" alt="RIA Return on Invest" /></p></blockquote>
<p>Whether the bill looks the same for your company or for one particular project, of course, depends on many things. Especially nowadays with all the hubbub around <a href="http://ajdotnet.wordpress.com/2011/03/12/html5-part-iii-the-limits/" target="_blank">HTML5</a> and mobile applications (without any relevant Silverlight support). But if RIA is what you need, the Silverlight will quite often yield far more benefits than any other option.</p>
<p>Still, you need to do your own evaluation. However, I hope to have given you some hints on what you might focus on, if you want to sell technology to the people who make platform decisions in your company.</p>
<p>The actual analysis was fairly detailed and customer specific. But we also prepared a neutralized/anonymized version, which we just made available for <a href="http://ajdotnet.files.wordpress.com/2011/08/ria-with-silverlight.pdf" target="_blank">download (pdf)</a>. (Also directly at <a href="http://www.sdx-ag.de/experts/ria.aspx" target="_blank">SDX</a>.)</p>
<p><span style="color:#008000;">That’s all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2011/08/14/ria-with-silverlightthe-business-perspective/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2011/08/14/ria-with-silverlightthe-business-perspective/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://ajdotnet.wordpress.com/category/c/'>C#</a>, <a href='http://ajdotnet.wordpress.com/category/sdx/'>SDX</a>, <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://ajdotnet.wordpress.com/category/software-architecture/'>Software Architecture</a>, <a href='http://ajdotnet.wordpress.com/category/software-developers/'>Software Developers</a>, <a href='http://ajdotnet.wordpress.com/category/software-development/'>Software Development</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/966/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/966/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/966/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=966&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2011/08/14/ria-with-silverlightthe-business-perspective/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2011/08/ria-developers.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2011/08/ria-perspectives.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2011/08/ria-forrester.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2011/08/ria-netload1.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2011/08/ria-netload2.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2011/08/ria-roi.png" medium="image">
			<media:title type="html">RIA Return on Invest</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2011/08/14/ria-with-silverlightthe-business-perspective/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>HTML5 &#8211; Part III: The Limits</title>
		<link>http://ajdotnet.wordpress.com/2011/03/12/html5-part-iii-the-limits/</link>
		<comments>http://ajdotnet.wordpress.com/2011/03/12/html5-part-iii-the-limits/#comments</comments>
		<pubDate>Sat, 12 Mar 2011 15:26:20 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=953</guid>
		<description><![CDATA[Alternative title: HTML5 – Still HTML, not a RIA platform The last post was about the chances and benefits of HTML5. But there are also some exaggerated expectations that HTML5 cannot fulfill. Mainly this concerns the term “RIA”, and the effect HTML5 will have in this area. Or as someone wrote: “Will HTML 5 one [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=953&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Alternative title: HTML5 – Still HTML, not a RIA platform</p>
<p>The <a href="http://ajdotnet.wordpress.com/2011/03/10/html5-part-ii-new-standard-for-web-applications/" target="_blank">last post</a> was about the chances and benefits of HTML5. But there are also some exaggerated expectations that HTML5 cannot fulfill. Mainly this concerns the term “RIA”, and the effect HTML5 will have in this area.</p>
<p>Or as someone wrote:</p>
<blockquote><p>“Will HTML 5 one day make Flash, Silverlight and other plug-in technologies obsolete?” (<a href="http://www.theregister.co.uk/2009/08/28/html_5_dream/" target="_blank">link</a>)</p>
</blockquote>
<p>Actually this is a very regular question I have to answer. (Often enough it doesn’t come as question, but as statement. Or accusation. Sic!)</p>
<p>I already detailed how HTML5’s video and canvas will take over tasks that have formerly been solved by other technologies, namely Flash. And some people seem to infer that if Flash is a RIA technology, and HTML5 obsoletes Flash, then HTML5 must obviously make RIA technologies obsolete in general.</p>
<p>Quite wrong. Actually the fact that Flash is used for video and 2D graphics has nothing to do with Flash being a RIA technology. Flash simply happened to be able to delivering these features, both in terms of technical capability as well as broad availability. That it also happens to be a RIA technology is more or less happenstance.</p>
<p>But before moving on we need to clarify the terms “RIA” and “RIA technology”…</p>
<p>My personal definition of RIA technologies relates to the following attributes: Stateful programming model, with some kind of page model, for applications running in a browser sandbox. This includes Flash, JavaFx, Silverlight as a browser plugin (but not in its WP7-platform variation). </p>
<p>Wikipedia <a href="http://en.wikipedia.org/w/index.php?title=Rich_Internet_application&amp;oldid=417575667" target="_blank">applies the terms</a> to Flash, Java (not JavaFx! Sic!), and Silverlight. Sill, this is debatable, and a year ago even Wikipedia had a <a href="http://en.wikipedia.org/w/index.php?title=Rich_Internet_application&amp;oldid=335407612" target="_blank">far broader definition</a>, but in my experience this actually covers the common understanding. Curiously Adobe claims that AIR is their RIA technology, not Flash. But me, Wikipedia, and general consensus agree that Flash indeed <em>is </em>a valid RIA technology.</p>
<p>By the way: Leaving HTML+AJAX out of this picture is by no means meant to be deprecatory, it just reflects common understanding. Wikipedia actually <a href="http://en.wikipedia.org/w/index.php?title=Rich_Internet_application&amp;oldid=417575667" target="_blank">makes the distinction</a> based on the (lack of) necessity to install an additional software framework.</p>
<p>And a final tidbit: Once upon a time Microsoft advertised Silverlight as Flash replacement, addressing video and graphics, just like in the typical Flash use cases. However, even with growing adoption of the Silverlight plugin, Silverlight never became a serious competitor for Flash in that area. (This may actually have played a role in Microsoft’s <a href="http://www.microsoft.com/presspass/press/2010/nov10/11-01Statement.mspx" target="_blank">commitment to HTML5</a>…) Still, Silverlight has long outgrown this narrow definition and later versions has put more emphasis on business features.</p>
<p>So, let’s have a look at where HTML5 reaches its limits and where RIA technologies might kick in. I’ll look at regular web applications before moving on to RIA applications.</p>
<p><strong>Web Applications</strong></p>
<p>HTML5 is going to address standard demands of web applications, including those addressed today by Flash. This will have a crowding-out effect on Flash and RIA technologies in general. But once the demands go beyond being “standard”, RIA technologies will find their niche even in web applications. </p>
<p>On example could be premium video delivery: Some vendors will probably be eager to offer unique selling propositions in the emerging markets of WebTV and high quality HD video content (probably involving DRM).</p>
<blockquote><p>Since Flash can no longer play the trump of being the only or the broadest available platform in this area, this will also change the picture among the RIA technologies. Especially Silverlight has been very successful in this area recently. Take the <a href="http://www.microsoft.com/silverlight/nbcolympicsonmsn/getsilverlight.html" target="_blank">Olympic Games</a> or <a href="http://www.maxdome.de/special/silverlight/" target="_blank">maxdome</a>.</p>
</blockquote>
<p>Other examples include complex user interactions that are not feasible with canvas and script, e.g. <a href="http://www.mazda.de/buyingamazda/Konfigurator/" target="_blank">Mazda</a>’s car configurator, and similarly <a href="http://pivot.metia.com/worldcup/" target="_blank">dynamic data visualizations</a>.</p>
<p>Finally there is the support of additional features. RIA technology vendors certainly have shorter innovation cycles than standards bodies. This especially includes hardware support (camera, game controller, hardware accelerated animations and 3D).</p>
<p>These scenarios all require the user to accept the plugin – which might become a more severe issue if this necessity is less ubiquitous. Thus for the web site provider this always incurs the question whether he can compel his users to use his offering despite that nuisance, or whether he may have to provide a (perhaps simplified and less capable) HTML based version. </p>
<p><strong>RIA Applications</strong></p>
<p>HTML5 won’t turn HTML into a RIA technology. It doesn’t come with a new programming model, doesn’t change server side processing, page model, and postbacks, doesn’t change that fact that the HTML ecosystem really is a conglomerate of diverse technologies.</p>
<p>Many applications – be it multimedia, some kind of hardware dependency, or line of business – simply require the potential of rich client applications. For these, HTML simply cannot deliver what is necessary. Typical demands include:</p>
<ul>
<li>Data centric applications: Large amounts of data; data input with complex validations, lists with extended feature sets, … </li>
<li>Usability: Immediate feedback (not possible with postbacks), dynamic UIs with forms built dynamically or changing depending on user input, … </li>
<li>Business features: Printing, graphical presentation, Office integration, … </li>
<li>Offline capability… </li>
<li>Connectivity: Communication patterns such as peer-to-peer, server pushes, … </li>
<li>Multimedia and hardware support: Animations, camera, microphone, multitouch, … </li>
<li>Rich platform: Stateful programming model, component model, feature rich controls, rich databinding capabilities, … </li>
</ul>
<p>While these are certainly not the demands for typical web applications. But intranet applications and applications addressing some distinct or closed user group on the web are very well within this category. Prominent example is <a href="http://flurfunk.sdx-ag.de/2010/10/sap-setzt-auf-silverlight.html" target="_blank">SAP</a>, one can also think of WebTV portals, home banking, or other. </p>
<p>In the past java applets were often used to cover these demands. Recently AJAX approach have spread, but while this worked to some degree, it often falls short of meeting the demands completely. From a technical perspective, RIA technologies are the adequate choice in these scenarios. And (in my opinion), Microsoft Silverlight is currently the best technology available in that area. Adobe AIR lacks availability and adoption, Flash alone is not sufficient, and JavaFx seems to <a href="http://www.pushing-pixels.org/2010/07/14/javafx-is-a-train-wreck.html" target="_blank">die a slow death</a>.&#160; </p>
<p><strong>Conclusion</strong></p>
<p>HTML5 will push RIA technologies out of their makeshift role (video and canvas). However this doesn’t affect the feasibility of employing RIA technologies on their own turf, i.e. beyond-HTML-capability demands in web applications and fully fledged RIA applications.</p>
<p>However, since this “pushing out of RIA technologies” mainly affects Flash, HTML5 has an interesting effect on the RIA market: Broad availability is no longer a strong USP for Flash, which is to the benefit of Silverlight. Add the hazy prospect of JavaFx and the fact that Silverlight is not only a RIA platform, but also enters devices (<a href="http://weblogs.asp.net/scottgu/archive/2010/11/04/silverlight-questions.aspx" target="_blank">WP7, WebTV</a>), and HTML5 may actually <em>further</em> the adoption of Silverlight – not as cross-platform tool, as it was once intended, but in all areas not covered by HTML5.</p>
<p>The one argument in favor of HTML5 – which no RIA technology is likely to ever achieve – is its universal availability across all platforms, even if that comes at a cost. </p>
<p><strong>Where are we?</strong></p>
<p>The conclusion of this little series may be as follows: The conflict, or enmity, between HTML5 and RIA that some people see (or exaggerate) doesn’t really exist. There may be a competition between HTML5 and Flash, but even that may turn out <a href="http://www.flashplatform.de/index.php?q=node/27" target="_blank">differently form what people expect</a>. </p>
<p>Actually HTML5 and RIA complement each other. There are areas in which one technology certainly make more sense than the other, other areas in which there is a choice, again other areas in which a combination of both may work best; even areas in which neither is an ideal choice. E.g.…</p>
<ul>
<li>A web application addressing the broadest available audience? HTML5. </li>
<li>An LOB application with high usability demands? Silverlight. </li>
<li>A mobile application addressing a broad audience? HTML5. As long as not tighter device integration is necessary, in which case one has to address several mobile OSes… </li>
</ul>
<p>And between these black-and-white examples there’s a lot gray areas, to be decided on a case-by-case basis. And usually the important thing is not exactly which technology you favor. The important thing is to make an <em>informed </em>decision, aware of the pros and cons, and not solely based on political opinions of certain apologists.</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p> <a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2011/03/12/html5-part-iii-the-limits/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2011/03/12/html5-part-iii-the-limits/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/html5/'>HTML5</a>, <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://ajdotnet.wordpress.com/category/software-architecture/'>Software Architecture</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/953/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/953/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/953/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/953/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/953/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/953/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/953/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/953/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/953/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/953/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/953/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/953/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/953/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/953/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=953&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2011/03/12/html5-part-iii-the-limits/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2011/03/12/html5-part-iii-the-limits/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>HTML5 &#8211; Part II: New Standard for Web Applications</title>
		<link>http://ajdotnet.wordpress.com/2011/03/10/html5-part-ii-new-standard-for-web-applications/</link>
		<comments>http://ajdotnet.wordpress.com/2011/03/10/html5-part-ii-new-standard-for-web-applications/#comments</comments>
		<pubDate>Thu, 10 Mar 2011 16:35:57 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=947</guid>
		<description><![CDATA[As I laid out in the first post, a lot of people talk about HTML5, but there are also a lot of misconceptions – and misguided expectations – about HTML5. So, what is HTML5, anyway? And for whom? HTML5 is a lot of things for a lot of people. For some it is a vehicle [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=947&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As I laid out in the <a href="http://ajdotnet.wordpress.com/2011/03/07/html5-part-i-the-hype/" target="_blank">first post</a>, a lot of people talk about HTML5, but there are also a lot of misconceptions – and misguided expectations – about HTML5. So, what is HTML5, anyway? And for whom?</p>
<p>HTML5 is a lot of things for a lot of people. For some it is a vehicle to rid the web of patent laden <a href="http://www.fsf.org/blogs/community/google-free-on2-vp8-for-youtube" target="_blank">video formats</a>. For Apple it is a means to <a href="http://www.apple.com/hotnews/thoughts-on-flash/" target="_blank">keep Flash off iPhone and iPad</a>. Microsoft uses it to <a href="http://www.microsoft.com/presspass/press/2010/mar10/03-16mix10day2pr.mspx" target="_blank">push IE9</a>. Some people are using it to – at least try to – <a href="http://www.theregister.co.uk/2009/08/28/html_5_dream/" target="_blank">bury RIA</a>. Anything else…? Oh yes, some people actually look into HTML5 technologies.</p>
<p>In an attempt to join the last group, here is my opinion on what HTML5 is and what it will mean.</p>
<p><strong>The Standard</strong></p>
<p>Formally, HTML5 is just the next version of <a href="http://de.wikipedia.org/wiki/Hypertext_Markup_Language" target="_blank">HTML</a>. (Period!) In terms of scope however it covers some more ground than “HTML” did before. Included is not only the markup language we know as HTML 4.1, but also the formerly distinct standards XHTML and DOM.</p>
<blockquote><p>Given that HTML 4.0 became a recommendation in 1997 one can only say (shout!) “It’s about time!”. The fact that HTML 4.x cannot be considered “state of the art” for quite some time now is exactly the reason why browser vendors chose to implement proprietary extensions and why technologies like Flash – even ActiveX – have to fill in the gaps.</p>
</blockquote>
<p>HTML5 is available as <a href="http://www.w3.org/TR/html5/" target="_blank">working draft</a> (latest version today from January 2011) and all major browser venders are more or less committed to implementing it:</p>
<ul>
<li><a href="http://www.apple.com/html5/" target="_blank">Apple Safari</a> </li>
<li><a href="http://www.google.com/events/io/2010/sessions/html5-status-chrome.html" target="_blank">Google Chrome</a> </li>
<li><a href="http://msdn.microsoft.com/en-us/ie/ff468705.aspx" target="_blank">Microsoft Internet Explorer</a> </li>
<li><a href="https://developer.mozilla.org/en/HTML/HTML5" target="_blank">Mozilla Firefox</a> </li>
<li><a href="http://dev.opera.com/articles/tags/html5/" target="_blank">Opera</a> </li>
</ul>
<p>Regarding general support for HTML5, the industry for once agrees on something. Surprising enough. Regarding the details however, one has to be careful, which part of HTML5 is supported by which browser to what degree. It may be going to take some time – and more than one version number – until we get broad HTML5 support on all browsers.</p>
<blockquote><p>For some time the critics gloated at the fact that HTML5 has barely reached “working draft” status and that “recommendation” status is <a href="http://en.wikipedia.org/wiki/HTML5#W3C_standardization_process" target="_blank">not expected before 2022</a>. Even if that were the case, it would have been totally irrelevant, as the industry is implementing and therefore standardizing parts of HTML5 right now. Additionally the W3C group is just now reconsidering its approach and looking for a more timely “delivery”. TODO</p>
</blockquote>
<p>So far for the term, now for the content…</p>
<p><strong>The Details</strong></p>
<p>In the details, HTML5 is a conglomerate of different – and not necessarily related – improvements and new features. Of course this includes the two features mentioned mostly: video and 2D graphics (a.k.a. “canvas”).</p>
<p><strong>Video </strong>is nothing spectacular: It simply displays a video, albeit without depending on some 3<sup>rd</sup> party plugin (namely Flash). Benefit for web developers: a standardized API based on HTML and JavaScript (rather than having to learn another technology). Benefit for the user: He can watch the video, independently on the device and plugin availability. </p>
<p><strong>Canvas </strong>allows 2D graphics, even (with JavaScript) animated. This again allows (in principle) to address use cases formerly the domain of Flash. Diagrams for usage statistics, stock exchange rates, and so on. Contrary to simple (server rendered) images this could be including user interaction. This even may include more complex things, like web games; the technology is up to it, as this <a href="http://www.elizium.nu/scripts/lemmings/" target="_blank">classic</a> proves.</p>
<p>Regarding multimedia, one probably hast to mention <strong>audio </strong>support for a complete picture.</p>
<p>Video and canvas are mentioned quite often, probably because they constitute the use cases today most often addressed using Flash. Still, it would be unfair to reduce HTML5 to these two.</p>
<p>If it comes to plain old markup code HTML5 offers some improvements regarding <strong>java script control</strong>, as well as <strong>semantic tags </strong>like “header” and “footer”.</p>
<p>Regarding user interaction HTML5 offers new types of <strong>input fields </strong>(e.g. date picker), complete with validations (e.g. textbox with email address). Also add APIs for <strong>drag-and-drop</strong>, <strong>browser history management</strong>, and some other.</p>
<p>You may find this in more detail at the <a href="http://www.w3.org/TR/html5/" target="_blank">W3C</a> or on <a href="http://en.wikipedia.org/wiki/HTML5" target="_blank">Wikipedia</a>. A nicely illustrated introduction can be found <a href="http://www.drweb.de/magazin/html5-ueberblick/" target="_blank">here</a> (German, but the pictures shouldn’t need translation <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ).</p>
<p>Yet this still doesn’t conclude the list. For a complete picture one has to name topics closely related to (even if not formally part of) HTML5: <strong><a href="http://css3-html5.de/" target="_blank">CSS3</a></strong>, <strong><a href="http://en.wikipedia.org/wiki/Web_Storage" target="_blank">Web Storage</a></strong>, and (especially for mobile applications) <strong><a href="http://en.wikipedia.org/wiki/W3C_Geolocation_API" target="_blank">Geolocation</a></strong>.</p>
<p>It should be noted that the recent improvements in <strong>JavaScript execution </strong>in all major browsers (well… – IE starting with IE9) also contribute to HTML5: Many of the features unfold their full potential only with scripting. It’s a fair assumption that HTML5 will cause a further growth in scripting in general, and probably the adoption of respective AJAX frameworks.</p>
<p><strong>The Impact</strong></p>
<p>At a closer look HTML5 is a mixture of rather different and unrelated things – none of them especially outstanding. Basically HTML is only upgraded to accommodate current state-of-the-art technologies. All together a (long overdue and therefore a little extensive) evolution, but certainly no revolution or “groundbreaking upgrade”, as some like to <a href="http://www.infoworld.com/d/developer-world/html-5-could-it-kill-flash-and-silverlight-291" target="_blank">think</a>.</p>
<p>Therefor the relevance of HTML5 is not the functionality itself. It stems from two facts:</p>
<ol>
<li><strong>The broad support from all major browser vendors.</strong> No matter why they do it, that fact that they agree on HTML5 in such an unequivocal and joined fashion is without precedence. This will likely ensure that all browsers level on comparable features and capabilities. Which is important to break todays disparities and incompatibilities. HTML5 shows all promises of becoming a platform for the web that is state-of-the-art as well as broadly available. Something HTML has increasingly failed at in recent years. </li>
<li><strong>The timely appearance together with the emerging mobile ecosystem (smart phones, pads).</strong> In this area we have a far more diverse and inhomogeneous platform landscape than on desktops (iOS, Android, WP7, other mobile OSes, desktop OS adaptions). No platform has a dominance similar to Windows, thus vendors need to address more than one platform. And web applications built for mobile devices are the only feasible cross platform approach available. Even if HTML5 lacks full device integration (e.g. phone integration or multitouch), it goes a long way with web storage, geolocation, and rudimentary offline capabilities. </li>
</ol>
<p>To conclude: HTML5 is not going to be some academic standard, it will be a true and broadly supported industry standard. Together with browser improvements, especially regarding script engines, HTML will become an adequate development platform for state-of-the-art web applications and the emerging mobile area.</p>
<p>For web developers HTML5 is a good thing. At least as long as the agreement among the browser vendors holds – and as long as we don’t have to wait another 10 years for the next version.</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p> <a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2011/03/10/html5-part-ii-new-standard-for-web-applications/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2011/03/10/html5-part-ii-new-standard-for-web-applications/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/html5/'>HTML5</a>, <a href='http://ajdotnet.wordpress.com/category/software-architecture/'>Software Architecture</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/947/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/947/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/947/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/947/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/947/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/947/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/947/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/947/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/947/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/947/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/947/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/947/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/947/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/947/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=947&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2011/03/10/html5-part-ii-new-standard-for-web-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2011/03/10/html5-part-ii-new-standard-for-web-applications/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>HTML5 &#8211; Part I: The Hype</title>
		<link>http://ajdotnet.wordpress.com/2011/03/07/html5-part-i-the-hype/</link>
		<comments>http://ajdotnet.wordpress.com/2011/03/07/html5-part-i-the-hype/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 15:17:18 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2011/03/07/html5-part-i-the-hype/</guid>
		<description><![CDATA[META: This blog got a little sleepy recently. But actually I’ve been spending quite some time writing blog posts, albeit for our company blog. And I’m planning to reuse some of that content here (this post is actually the first one). Also I’ve been busy in several new areas, including WP7, and I may have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=946&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>META: This blog got a little sleepy recently. But actually I’ve been spending quite some time writing blog posts, albeit for our <a href="http://flurfunk.sdx-ag.de/search?q=alexander+jung" target="_blank">company blog</a>. And I’m planning to reuse some of that content here (this post is actually the first one). Also I’ve been busy in several new areas, including WP7, and I may have something to say about those, too. So, this blog is still alive and kicking. </p>
</blockquote>
<p>There’s a small hype around HTML5 for some time now. Ironically the reason were more political than for technical ones, since browsers begin to support HTML5 only just now. Be it <a href="http://dig.csail.mit.edu/breadcrumbs/node/166" target="_blank">organizational hassles</a>, <a href="http://blogs.msdn.com/b/ie/archive/2010/04/29/html5-video.aspx" target="_blank">discussions</a> about a <a href="http://www.webmproject.org/" target="_blank">video format</a>, or a certain company having <a href="http://www.apple.com/hotnews/thoughts-on-flash/" target="_blank">issues with Flash</a> on their iPlatform. And since Microsoft has announced its decision to make HTML5 their cross platform strategy, the last big browser vendor has joined the camp.</p>
<p>And this is a good thing! Not only homogenizes HTML5 the web platform again, it is also the only feasible platform for cross platform development in the mobile world, which is much more diverse than our desktop eco system.</p>
<p>On the other hand I am regularly irritated about what people think HTML5 will be able to accomplish. Especially in the relation to RIA applications that are all but dead, according to various sources:</p>
<blockquote><p>“HTML5, a groundbreaking upgrade to the prominent Web presentation specification, could become a game-changer in Web application development, one that might even make obsolete such plug-in-based rich Internet application (RIA) technologies as Adobe Flash, Microsoft Silverlight, and Sun JavaFX.” (<a href="http://www.infoworld.com/d/developer-world/html-5-could-it-kill-flash-and-silverlight-291" target="_blank">link</a>)</p>
</blockquote>
<blockquote><p>“Will HTML 5 one day make Flash, Silverlight and other plug-in technologies obsolete? Most likely, but unfortunately that day is still quite a way off.” (<a href="http://www.theregister.co.uk/2009/08/28/html_5_dream/" target="_blank">link</a>)</p>
</blockquote>
<blockquote><p>“Sure maybe today, we have to rely on these proprietary browser plugins to deliver content to users, but the real innovative developers and companies are going to standard on HTML 5 and in turn revolutionize how users interact with data.&#160; We all want faster web applications and the only way to deliver this is to use HTML 5.” (<a href="http://www.spatiallyadjusted.com/2009/06/16/html-5-should-kill-flash-and-silverlight/" target="_blank">link</a>)</p>
</blockquote>
<p>To put it bluntly: HTML is no RIA technology and HTML5 is not going to change that. Thus Silverlight is a valid choice for any RIA application today, and it will be one tomorrow.</p>
<p>On the other hand, HTML5 is certainly going to deliver features that today are the domain of RIA technologies, namely Flash. And this will affect RIA technologies in <em>some </em>way.</p>
<p>Then how will HTML5 affect RIA? Well, I’m afraid, it’s not that simple and there is no short <i>and</i><i> </i>sufficient answer that I’m aware of. In order to decide – probably on a case by case basis – what HTML5 can do, in which use cases HTML5 is the right answer, and in which cases RIA technologies still are the better choices, we need to take a closer look at some details…</p>
<p>To keep it a little more concise, I’m going to break with my usual habit of very long posts. I’m splitting the remainder into two additional not-quite-so-long posts:</p>
<ul>
<li><a href="http://ajdotnet.wordpress.com/2011/03/10/html5-part-ii-new-standard-for-web-applications/" target="_blank">Part II: HTML5 – New Standard for Web Applications</a> </li>
<li><a href="http://ajdotnet.wordpress.com/2011/03/12/html5-part-iii-the-limits/" target="_blank">Part III: HTML5 – The Limits</a> </li>
</ul>
<p><font color="#008000">Stay tuned,      <br /><strong>AJ.NET</strong></font></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/html5/'>HTML5</a>, <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://ajdotnet.wordpress.com/category/software-architecture/'>Software Architecture</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/946/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/946/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/946/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/946/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/946/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/946/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/946/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/946/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=946&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2011/03/07/html5-part-i-the-hype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>2010 in review</title>
		<link>http://ajdotnet.wordpress.com/2011/01/12/2010-in-review/</link>
		<comments>http://ajdotnet.wordpress.com/2011/01/12/2010-in-review/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 19:45:07 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=939</guid>
		<description><![CDATA[The following post is by courtesy of wordpress. The reported content is by courtesy of my readers &#8212; in other words: YOU! Thank you. And a happy new year. The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here&#8217;s a high level summary of its overall blog health: The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=939&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><em>The following post is by courtesy of wordpress. The reported content is by courtesy of my readers &#8212; in other words: YOU! </em></p>
<p><em>Thank you. And a happy new year.</em></p></blockquote>
<p>The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here&#8217;s a high level summary of its overall blog health:</p>
<p><img style="border:1px solid #ddd;background:#f5f5f5;padding:20px;" src="http://s0.wp.com/i/annual-recap/meter-healthy5.gif" alt="Healthy blog!" width="250" height="183" /></p>
<p>The <em>Blog-Health-o-Meter™</em> reads Wow.</p>
<h2>Crunchy numbers</h2>
<p><a href="http://ajdotnet.files.wordpress.com/2010/02/validation.jpg"><img style="max-height:230px;float:right;border:1px solid #ddd;background:#fff;margin:0 0 1em 1em;padding:6px;" src="http://ajdotnet.files.wordpress.com/2010/02/validation.jpg?w=288" alt="Featured image" /></a></p>
<p>About 3 million people visit the Taj Mahal every year. This blog was viewed about <strong>40,000</strong> times in 2010. If it were the Taj Mahal, it would take about 5 days for that many people to see it.</p>
<p>In 2010, there were <strong>21</strong> new posts, growing the total archive of this blog to 130 posts. There were <strong>81</strong> pictures uploaded, taking up a total of 2mb. That&#8217;s about 2 pictures per week.</p>
<p>The busiest day of the year was May 21st with <strong>453</strong> views. The most popular post that day was <a style="color:#08c;" href="http://ajdotnet.wordpress.com/2009/03/29/visual-studio-2010-architecture-edition/">Visual Studio 2010 Architecture Edition</a>.</p>
<h2>Where did they come from?</h2>
<p>The top referring sites in 2010 were <strong>forums.silverlight.net</strong>, <strong>dotnetkicks.com</strong>, <strong>forums.asp.net</strong>, <strong>google.com</strong>, and <strong>google.co.in</strong>.</p>
<p>Some visitors came searching, mostly for <strong>silverlight 4 validation</strong>, <strong>visual studio 2010 class diagram</strong>, <strong>visual studio 2010 architecture</strong>, <strong>visual studio 2010 modeling project</strong>, and <strong>visual studio 2010 architecture explorer</strong>.</p>
<h2>Attractions in 2010</h2>
<p>These are the posts and pages that got the most views in 2010.</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">1</div>
<p><a style="margin-right:10px;" href="http://ajdotnet.wordpress.com/2009/03/29/visual-studio-2010-architecture-edition/">Visual Studio 2010 Architecture Edition</a> <span style="color:#999;font-size:8pt;">March 2009</span><br />
12 comments</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">2</div>
<p><a style="margin-right:10px;" href="http://ajdotnet.wordpress.com/2010/02/28/understanding-validation-in-silverlight/">Understanding Validation in Silverlight</a> <span style="color:#999;font-size:8pt;">February 2010</span><br />
4 comments</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">3</div>
<p><a style="margin-right:10px;" href="http://ajdotnet.wordpress.com/2006/07/17/aspnet-20-databinding-examined/">ASP.NET 2.0 DataBinding Examined</a> <span style="color:#999;font-size:8pt;">July 2006</span><br />
7 comments</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">4</div>
<p><a style="margin-right:10px;" href="http://ajdotnet.wordpress.com/2010/01/24/silverlight-bitspieces-the-first-steps-with-visual-state-manager/">Silverlight Bits&amp;Pieces: The First Steps with Visual State Manager</a> <span style="color:#999;font-size:8pt;">January 2010</span><br />
3 comments and 1 Like on WordPress.com,</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">5</div>
<p><a style="margin-right:10px;" href="http://ajdotnet.wordpress.com/2008/01/19/command-line-tool-vs-powershell-cmdlet/">Command line tool vs. PowerShell Cmdlet</a> <span style="color:#999;font-size:8pt;">January 2008</span><br />
3 comments</p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/miscellaneous/'>Miscellaneous</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/939/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/939/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/939/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/939/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/939/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/939/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/939/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/939/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/939/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/939/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/939/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/939/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/939/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/939/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=939&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2011/01/12/2010-in-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://s0.wp.com/i/annual-recap/meter-healthy5.gif" medium="image">
			<media:title type="html">Healthy blog!</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/02/validation.jpg?w=288" medium="image">
			<media:title type="html">Featured image</media:title>
		</media:content>
	</item>
		<item>
		<title>Visual Studio Async CTP &#8211; An Analysis</title>
		<link>http://ajdotnet.wordpress.com/2010/12/23/visual-studio-async-ctp-an-analysis/</link>
		<comments>http://ajdotnet.wordpress.com/2010/12/23/visual-studio-async-ctp-an-analysis/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 10:21:40 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=886</guid>
		<description><![CDATA[OK, buckle up. This is going to be a long one, even by my standards… During the last PDC Microsoft announced a next innovation: Async C#, currently available as CTP. There is also a respective white paper; I recommend reading it, if you need an introduction. Just for the record, here’s what we are talking [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=886&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>OK, buckle up. This is going to be a long one, even by my standards…</p>
<p>During the last PDC Microsoft <a href="http://player.microsoftpdc.com/Session/1b127a7d-300e-4385-af8e-ac747fee677a" target="_blank">announced</a> a next innovation: Async C#, currently <a href="http://go.microsoft.com/fwlink/?LinkId=203690" target="_blank">available as CTP</a>. There is also a respective <a href="http://go.microsoft.com/fwlink/?LinkId=204844" target="_blank">white paper</a>; I recommend reading it, if you need an introduction.</p>
<p>Just for the record, here’s what we are talking about:</p>
<blockquote><p><img alt="" src="http://ajdotnet.files.wordpress.com/2010/12/code_intro_async.jpg" /></p>
</blockquote>
<p>This roughly translates to:</p>
<blockquote><p><img alt="" src="http://ajdotnet.files.wordpress.com/2010/12/code_intro_task.jpg" /></p>
</blockquote>
<p>As you can see, the compiler mainly translates an <em>await</em> into a new task and the remainder of the method into a continuation for that task. </p>
<blockquote><p>To tell the truth, the actual generated code looks quite different; this is semantically equal, though.</p>
</blockquote>
<p>Simple enough, but that’s only a simple case. Actually there’s more:</p>
<ul>
<li>If we are talking about a UI thread, the runtime ensures that the continuation runs on the UI thread as well. The task version would need to marshal the call to the UI thread explicitly, e.g. by calling <em>Dispatcher.BeginInvoke</em>. </li>
<li>If the wait is contained within a loop of some kind, the compiler also handles that, cutting the loop into asynchronous bits and pieces. Similarly for conditional calls. </li>
</ul>
<p>That’s a nice set of features and there is no doubt that this approach works (there is a CTP after all). And reception within the community so far has been very positive.</p>
<p><em>However!</em></p>
<p>If this is really such a compelling feature, it should be quite easy to present a bunch of examples in which it pays off. Instead, what I found was a bunch of examples that made me wonder. Therefore I decided to put it to some…</p>
<p><strong>Litmus tests&#8230;</strong></p>
<p>To test whether <em>async/await</em> actually merits the praise, I set out to recheck and question the examples provided by various Microsoft people:</p>
<ul>
<li>Soma Segar’s <a href="http://blogs.msdn.com/b/somasegar/archive/2010/10/28/making-asynchronous-programming-easy.aspx" target="_blank">introduction</a> (actually taken from the white paper mentioned above) </li>
<li>Netflix (used by Anders Hejlsberg during his PDC talk and available as sample within the CTP) </li>
<li>Eric Lippert’s <a href="http://blogs.msdn.com/b/ericlippert/archive/2010/10/28/asynchrony-in-c-5-part-one.aspx" target="_blank">discussion</a> </li>
</ul>
<blockquote><p>Note: Examples have a tendency to oversimplify. I chose this set to overcome that effect: Soma provides a simple introduction, Netflix is more “real world”, and Eric looks at it form a language designer point of view. Three different samples, three different people, three different perspectives.</p>
<p>Note 2: The code I present is from my test solution (download link at the end), thus it is not exactly a citation, rather it’s complemented with my bookkeeping code. I also didn’t address every question that may arise (such as exception handling) explicitly. This post got long enough as it is. </p>
</blockquote>
<p><strong>Soma Segar’s blog</strong></p>
<p>Let’s begin with Soma’s <a href="http://blogs.msdn.com/b/somasegar/archive/2010/10/28/making-asynchronous-programming-easy.aspx" target="_blank">introduction</a>, as it is the most simple one:</p>
<p>He provides a „conventional“ asynchronous solution, that looks… quite convoluted, actually. Note that I prepended the necessary code to synchronize the call.</p>
<blockquote><p><img title="code_soma_taskasproposed_a" alt="code_soma_taskasproposed_a" src="http://ajdotnet.files.wordpress.com/2010/12/code_soma_taskasproposed_a.jpg?w=599&#038;h=325" width="599" height="325" /></p>
<p><img title="code_soma_taskasproposed_b" alt="code_soma_taskasproposed_b" src="http://ajdotnet.files.wordpress.com/2010/12/code_soma_taskasproposed_b.jpg?w=590&#038;h=474" width="590" height="474" /></p>
</blockquote>
<p>And his respective solution using the <em>async/await</em> looks quite nice in comparison:</p>
<blockquote><p><img title="code_soma_withasync" alt="code_soma_withasync" src="http://ajdotnet.files.wordpress.com/2010/12/code_soma_withasync.jpg?w=538&#038;h=296" width="538" height="296" /></p>
</blockquote>
<p>Easier to write, and easier to understand, no question about that.</p>
<p>However: Looking at the awfully convoluted task based version, I asked myself: „Who would write such code in the first place?“.</p>
<p>The use case is to load some web pages and sum up their size. And to do this asynchronously, probably to avoid freezing the main thread. And the solution – awful and <em>async/await </em>alike – insists on getting the value for one web page asynchronously, but coming back to the UI thread to update the sum. Then starting the next fetch asynchronously, and again come back to the UI thread to update the sum.</p>
<p>But then, why not put the whole loop in a separate thread? The only caveat would be the marshaling of UI calls (i.e. a call to <em>Dispatcher.BeginInvoke</em>, which I left out here in favor of simple tracing, but it’s addressed in the next example). Somewhat like this:</p>
<blockquote><p><img title="code_soma_mytask" alt="code_soma_mytask" src="http://ajdotnet.files.wordpress.com/2010/12/code_soma_mytask.jpg?w=544&#038;h=293" width="544" height="293" /></p>
</blockquote>
<p>This is very close to the <em>await/async </em>version, nearly equally easy to write, and certainly as easy to understand. And it did not need a language addition, merely a little thinking about what it is that shall actually be accomplished.</p>
<p>OK, one example that didn’t really convince me.</p>
<p><strong>Netflix (sample in the CTP)</strong></p>
<p>The Netflix sample is part of the CTP and was also used by Anders Hejlsberg during <a href="http://player.microsoftpdc.com/Session/1b127a7d-300e-4385-af8e-ac747fee677a" target="_blank">his PDC talk</a>. The sample solution comes with synchronous version, conventional asynchronous version, and new async/await version.</p>
<p>The synchronous version looks straight forward, with 43 of relatively harmless LOC for the relevant two methods (<em>LoadMovies </em>and <em>QueryMovies</em>):</p>
<blockquote><p><img title="code_netflix_sync_a" alt="code_netflix_sync_a" src="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_sync_a.jpg?w=633&#038;h=426" width="633" height="426" /></p>
<p><img title="code_netflix_sync_b" alt="code_netflix_sync_b" src="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_sync_b.jpg?w=639&#038;h=267" width="639" height="267" /></p>
</blockquote>
<p>The conventional asynchronous version – do I even have to mention it? – is in comparison an ugly little piece of code. For the sake of completeness:</p>
<blockquote><p><img title="code_netflix_taskasproposed_a" alt="code_netflix_taskasproposed_a" src="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_taskasproposed_a.jpg?w=590&#038;h=399" width="590" height="399" /></p>
<p><img title="code_netflix_taskasproposed_b" alt="code_netflix_taskasproposed_b" src="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_taskasproposed_b.jpg?w=577&#038;h=468" width="577" height="468" /></p>
<p><img title="code_netflix_taskasproposed_c" alt="code_netflix_taskasproposed_c" src="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_taskasproposed_c.jpg?w=638&#038;h=533" width="638" height="533" /></p>
</blockquote>
<p>Twice as much code (85 LOC), a mixture of event handler registrations with nested lambdas and invokes. It takes considerable time to fully understand it. No one in his right mind would want to have to write this.</p>
<p>The <em>async/await </em>version – again – turns the synchronous version into a similarly straight forward looking asynchronous version:</p>
<blockquote><p><img title="code_netflix_async_a" alt="code_netflix_async_a" src="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_async_a.jpg?w=635&#038;h=397" width="635" height="397" /></p>
<p><img title="code_netflix_async_b" alt="code_netflix_async_b" src="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_async_b.jpg?w=638&#038;h=264" width="638" height="264" /></p>
</blockquote>
<p>Again the initial verdict: The <em>async/await </em>version looks nice and clean compared to the ugly task based version, and very similar to the synchronous one. Hail to <em>async/await</em>.</p>
<p>But again, looking at the ugly asynchronous version, I asked myself, “Who would actually write such code? And why? Masochistic tendencies?”</p>
<p>Let’s take a step back and look at the use case: Call a web service asynchronously to avoid freezing the UI (as the synchronous version does), update the UI with the result, and call the web service again if there is more information available.</p>
<p>The task based version tries to manually dismantle this loop into a sequence of asynchronous call followed by callback on the main thread to update the UI, followed again by the next asynchronous call. Add cancelation and exception handling and it is surprising that it isn’t even more ugly than it already is.</p>
<p>But! Why even try to dismantle the loop? Why not put the whole loop in a separate thread? Yes, that would solve the use case, and yes, it would be just as clean as the synchronous version. The only caveat is that each interaction with the UI has to be marshaled into the main thread, but I can live with that. Here it is:</p>
<blockquote><p><img title="code_netflix_mytask_a" alt="code_netflix_mytask_a" src="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_mytask_a.jpg?w=629&#038;h=554" width="629" height="554" /></p>
<p><img title="code_netflix_mytask_b" alt="code_netflix_mytask_b" src="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_mytask_b.jpg?w=563&#038;h=156" width="563" height="156" /></p>
</blockquote>
<p>I left the <em>QueryMovies </em>Method out for brevity, as it is similar to the synchronous version above.</p>
<p>Again this is very close to the <em>await/async </em>version, again nearly equally easy to write, and – again – certainly as easy to understand. And – again <em>(pardon the repetition) </em>– it did not need a language addition. Merely – ag… ok, ok – a little thinking about what it is that shall actually be accomplished.</p>
<p>Another example that didn’t convince me. But two is still coincidence.</p>
<p><strong>Eric Lippert‘s discussion</strong></p>
<p>Eric has a slightly different use case: For a list of web addresses, fetch the web page and archive it. There should be only one fetch at a time, and only one archive operation, but fetch and archive may overlap (described <a href="http://blogs.msdn.com/b/ericlippert/archive/2010/10/27/continuation-passing-style-revisited-part-five-cps-and-asynchrony.aspx" target="_blank">here</a>). This is more about overlapping different operations, rather than avoid freezing the UI, as in the previous examples.</p>
<p>The synchronous version is this simple:</p>
<blockquote><p><img title="code_lippert_synchronous" alt="code_lippert_synchronous" src="http://ajdotnet.files.wordpress.com/2010/12/code_lippert_synchronous.jpg?w=388&#038;h=88" width="388" height="88" /></p>
</blockquote>
<p>He constructed the asynchronous version (not even mentioning <em>async/await</em>) as state machine, described in the post I just <a href="http://blogs.msdn.com/b/ericlippert/archive/2010/10/27/continuation-passing-style-revisited-part-five-cps-and-asynchrony.aspx" target="_blank">mentioned</a>. I’ll spare you the reiteration this time; follow the link if you have doubts that it is far more convoluted than the simple loop above. But of course, <em>async/await </em>comes to the <a href="http://blogs.msdn.com/b/ericlippert/archive/2010/10/28/asynchrony-in-c-5-part-one.aspx" target="_blank">rescue</a>:</p>
<blockquote><p><img title="code_lippert_withasync" alt="code_lippert_withasync" src="http://ajdotnet.files.wordpress.com/2010/12/code_lippert_withasync.jpg?w=471&#038;h=388" width="471" height="388" /></p>
</blockquote>
<p>Nice and simple. But can you deduce the logic behind this? I have to admit it required some mind twists on my part. Now, to make it short, here is the task version:</p>
<blockquote><p><img title="code_lippert_mytasks1" alt="code_lippert_mytasks1" src="http://ajdotnet.files.wordpress.com/2010/12/code_lippert_mytasks1.jpg?w=559&#038;h=326" width="559" height="326" /></p>
</blockquote>
<p>Not quite as simple as the <em>async/await</em> version, but if you look closely, it’s actually a very close translation into continuations. And… equally inefficient. You may have noticed the comments I put in there, stating that there is some unnecessary synchronization between a fetch and an earlier archive operation.</p>
<p>So, this time I actually went a little bit further: This is why I complemented a little test data, bookkeeping, and a nice little printout to visualize the sequence. Here’s what the <em>async/await </em>version (and similarly the task version) produces:</p>
<p><img title="app_lippert_async" alt="app_lippert_async" src="http://ajdotnet.files.wordpress.com/2010/12/app_lippert_async.jpg?w=800&#038;h=440" width="800" height="440" /></p>
<p>“‘f” stands for fetch, “a” for archive. The lower part shows the operations according to their start and end time. You can depict nicely how tasks follow other tasks, and how <em>fetch </em>and <em>archive </em>run in parallel. No <em>fetch </em>overlaps another, no <em>archive </em>overlaps another <em>archive </em>operation. Well. Have a look at line 3. See how the <em>fetch </em>starts after the <em>archive </em>in line 1 was finished? It could have started earlier, couldn’t it? Same in line 6. That’s the unnecessary synchronization I mentioned above.</p>
<p>A little working on the task version solves that by chaining the fetches and archives onto their respective tasks:</p>
<blockquote><p><img title="code_lippert_mytasks2" alt="code_lippert_mytasks2" src="http://ajdotnet.files.wordpress.com/2010/12/code_lippert_mytasks2.jpg?w=535&#038;h=427" width="535" height="427" /></p></blockquote>
<p>However, now I becomes a little more complex and hard to understand. </p>
<p>Going back to the drawing-board. What again is the use case? It’s actually a pipeline, with multiple stages (two in this case), each stage throttled to process only a certain amount of input values (one in this case). The cookbook solution is to put a queue in front of each stage, and have separate workers (again, in our case just one) take input from this queue, process it, and place the result in the next stages queue. Like this:</p>
<blockquote><p><img title="code_lippert_myqueues" alt="code_lippert_myqueues" src="http://ajdotnet.files.wordpress.com/2010/12/code_lippert_myqueues.jpg?w=629&#038;h=548" width="629" height="548" /></p>
</blockquote>
<p>Two queues of lambdas, two tasks processing these queues, the first lambda placing new entries into the second queue upon completion. If you ask me, this is way closer to the proposed use case than either the task based versions or the <em>async/await </em>version. And the logic behind it – intention as well as control flow –, which in this case is a little more complicated than in the previous examples, is also far easier to comprehend. And the best part: Look at the output:</p>
<p><img title="app_lippert_queues" alt="app_lippert_queues" src="http://ajdotnet.files.wordpress.com/2010/12/app_lippert_queues.jpg?w=800&#038;h=440" width="800" height="440" /></p>
<p><em>Fetch </em>and <em>archive </em>start independently of each other, making the solution more effective than the <em>async/await </em>version. Why? Because I actually <em>thought</em> about the problem and the solution, rather than simply throwing asynchronicity on the code.</p>
<p>If anything, this example raises even more concerns than the other ones.</p>
<p><strong>Verdict</strong></p>
<p>Three different samples. Three times presenting some conventional task based asynchronous code – code that is rather convoluted, ugly, and hard to understand. Three times a nice <em>async/await </em>version that clearly makes the code nicer.</p>
<p>But also three times it “only” took a little thinking to come up with a far nicer task based version than the proposed convolution. Two times very close to the <em>async/await </em>version. The third time actually more efficient than that. </p>
<blockquote><p>One could actually get the impression that the convoluted task based code has been <em>deliberately </em>made ugly in order to provide a better motivation for the new features. I wouldn’t go that far, but still, it raises some questions, as to how these examples came into being. Perhaps a back-port of what the compiler produces for <em>async/await</em>?</p>
</blockquote>
<p>Granted, each example I examined may have its own compromises which slightly invalidates it (as is often the case with examples); had I only found one, I wouldn’t have bothered writing this post. But: One is an incident, two is coincidence, three is a trend. And I did not stumble over one example yielding a different result.</p>
<p>So, to summarize my concerns:</p>
<ol>
<li>I showed that the value of <em>async/await </em>is less compelling than presented. This <em>does</em> raise the question, whether it is still compelling enough to merit a language extension.<br />
<blockquote>
<p>I judge that value by its ability to making code shorter, easier to write, easier to comprehend. Or to quote Eric Lippert:</p>
<p>“Features have to be so compelling that they are worth the enormous dollar costs of designing, implementing, testing, documenting and shipping the feature. They have to be worth the cost of complicating the language and making it more difficult to design other features in the future.” <a title="http://blogs.msdn.com/b/ericlippert/archive/2008/10/08/the-future-of-c-part-one.aspx" href="http://blogs.msdn.com/b/ericlippert/archive/2008/10/08/the-future-of-c-part-one.aspx" target="_blank">http://blogs.msdn.com/b/ericlippert/archive/2008/10/08/the-future-of-c-part-one.aspx</a></p>
</blockquote>
</li>
<li>The way I verified my concerns was actually to take one step back and <em>think </em>about the demand. I hate to think that <em>async/await </em>actually <em>encourages </em>developers to think less and in turn write less than optimal code – especially the less experienced developers who’ll have a hard time understanding the implications of those keywords in the first place. </li>
</ol>
<p>To make that clear: I did not show anything that suggests that the <em>async/await </em>language feature is <em>per se </em>wrong. Nor did I prove that there is no use case that does not suffer from my concerns (only that Microsoft failed to present them yet – or I failed to find them).</p>
<p><strong>Conclusion</strong></p>
<p>Here my conclusion: I could live with concern #1, but #2 is something that gives me the creeps. There’s two things I would like Microsoft to do to make the feature work (or drop it altogether):</p>
<ol>
<li>Make more obvious what the code actually does (e.g. see the comments <a href="http://blogs.msdn.com/b/ericlippert/archive/2010/10/29/asynchronous-programming-in-c-5-0-part-two-whence-await.aspx#comments" target="_blank">here</a> for some naming suggestions – although my concern goes beyond simple naming issues). </li>
<li>Rethink the task based samples you are basing your reasoning on. We don’t need a feature that makes convoluted code simpler; we need features that make code simple, we would write in the first place. </li>
</ol>
<p>BTW: Whether <em>async/await </em>is backed into the language or not, this endeavor showed one thing quite clearly: Asynchronicity is <a href="http://ajdotnet.wordpress.com/2009/03/21/going-parallel/" target="_blank">important</a>, and becoming even more so. And Microsoft certainly did accomplish something great with the TPL, on which all these discussions built without even mentioning it anymore. And as Reed <a href="http://reedcopsey.com/2010/10/28/c-5-async-part-1-simplifying-asynchrony-that-for-which-we-await/" target="_blank">pointed out</a>, Tasks play a major role in the CTP as well.</p>
<p>Finally: Here is the <a href="http://alexander-jung.net/download/TestNewAsyncFeatures.zip" target="_blank">download link</a> for those who’d like to recheck my findings.</p>
<p>Merry Christmas!</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p> <a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2010/12/23/visual-studio-async-ctp-an-analysis/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/12/23/visual-studio-async-ctp-an-analysis/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://ajdotnet.wordpress.com/category/c/'>C#</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/886/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/886/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/886/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/886/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/886/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/886/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/886/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/886/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/886/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/886/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/886/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/886/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/886/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/886/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=886&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/12/23/visual-studio-async-ctp-an-analysis/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_intro_async.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_intro_task.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_soma_taskasproposed_a.jpg?w=599" medium="image">
			<media:title type="html">code_soma_taskasproposed_a</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_soma_taskasproposed_b.jpg?w=590" medium="image">
			<media:title type="html">code_soma_taskasproposed_b</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_soma_withasync.jpg?w=538" medium="image">
			<media:title type="html">code_soma_withasync</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_soma_mytask.jpg?w=544" medium="image">
			<media:title type="html">code_soma_mytask</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_sync_a.jpg?w=633" medium="image">
			<media:title type="html">code_netflix_sync_a</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_sync_b.jpg?w=639" medium="image">
			<media:title type="html">code_netflix_sync_b</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_taskasproposed_a.jpg?w=590" medium="image">
			<media:title type="html">code_netflix_taskasproposed_a</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_taskasproposed_b.jpg?w=577" medium="image">
			<media:title type="html">code_netflix_taskasproposed_b</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_taskasproposed_c.jpg?w=638" medium="image">
			<media:title type="html">code_netflix_taskasproposed_c</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_async_a.jpg?w=635" medium="image">
			<media:title type="html">code_netflix_async_a</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_async_b.jpg?w=638" medium="image">
			<media:title type="html">code_netflix_async_b</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_mytask_a.jpg?w=629" medium="image">
			<media:title type="html">code_netflix_mytask_a</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_netflix_mytask_b.jpg?w=563" medium="image">
			<media:title type="html">code_netflix_mytask_b</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_lippert_synchronous.jpg?w=388" medium="image">
			<media:title type="html">code_lippert_synchronous</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_lippert_withasync.jpg?w=471" medium="image">
			<media:title type="html">code_lippert_withasync</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_lippert_mytasks1.jpg?w=559" medium="image">
			<media:title type="html">code_lippert_mytasks1</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/app_lippert_async.jpg?w=800" medium="image">
			<media:title type="html">app_lippert_async</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_lippert_mytasks2.jpg?w=535" medium="image">
			<media:title type="html">code_lippert_mytasks2</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/code_lippert_myqueues.jpg?w=629" medium="image">
			<media:title type="html">code_lippert_myqueues</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/12/app_lippert_queues.jpg?w=800" medium="image">
			<media:title type="html">app_lippert_queues</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/12/23/visual-studio-async-ctp-an-analysis/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight. What if?</title>
		<link>http://ajdotnet.wordpress.com/2010/11/07/silverlight-what-if/</link>
		<comments>http://ajdotnet.wordpress.com/2010/11/07/silverlight-what-if/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 16:39:07 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=875</guid>
		<description><![CDATA[PDC happened and Microsoft fouled up the Silverlight message big time. The talk was that Silverlight is dead on the client, based on Steve Ballmer not mentioning Silverlight, and an interview with Bob Muglia published at Mary-Jo’s blog. Actually even we got irritated emails from our own customers, whom we had just convinced that Silverlight [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=875&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>PDC happened and Microsoft fouled up the Silverlight message big time. The talk was that Silverlight is dead on the client, based on Steve Ballmer <em>not </em>mentioning Silverlight, and an interview with Bob Muglia <a href="http://www.zdnet.com/blog/microsoft/microsoft-our-strategy-with-silverlight-has-shifted/7834" target="_blank">published</a> at Mary-Jo’s blog. Actually even we got irritated emails from our own customers, whom we had just convinced that Silverlight is the right choice for RIA applications.</p>
<p>It took some time for Microsoft to realize what fatal message they had sent, but eventually Muglia <a href="http://team.silverlight.net/announcement/pdc-and-silverlight/" target="_blank">backpedaled</a>, and from there one it seems that every other Microsoftie and close associate came out to deny the imminent death of Silverlight. So far I’ve stumbled over:</p>
<ul>
<li>Steve Ballmer (CEO): <a title="http://www.microsoft.com/presspass/press/2010/nov10/11-01Statement.mspx" href="http://www.microsoft.com/presspass/press/2010/nov10/11-01Statement.mspx">http://www.microsoft.com/presspass/press/2010/nov10/11-01Statement.mspx</a> </li>
<li>Bob Muglia (President, Server and Tools Business): <a href="http://team.silverlight.net/announcement/pdc-and-silverlight/" target="_blank">http://team.silverlight.net/announcement/pdc-and-silverlight/</a> </li>
<li>S. Somasegar (Senior Vice President, Developer Division): <a title="http://blogs.msdn.com/b/somasegar/archive/2010/11/01/silverlight-lighting-up-the-client.aspx" href="http://blogs.msdn.com/b/somasegar/archive/2010/11/01/silverlight-lighting-up-the-client.aspx" target="_blank">http://blogs.msdn.com/b/somasegar/archive/2010/11/01/silverlight-lighting-up-the-client.aspx</a> </li>
<li>Scott Guthrie (Corporate Vice President, .NET Developer Platform): <a title="http://weblogs.asp.net/scottgu/archive/2010/11/04/silverlight-questions.aspx" href="http://weblogs.asp.net/scottgu/archive/2010/11/04/silverlight-questions.aspx" target="_blank">http://weblogs.asp.net/scottgu/archive/2010/11/04/silverlight-questions.aspx</a> </li>
<li>Tim Heuer (Program Manager for Microsoft Silverlight): <a href="http://timheuer.com/blog/archive/2010/11/01/silverlight-is-dead-long-live-silverlight.aspx" target="_blank">http://timheuer.com/blog/archive/2010/11/01/silverlight-is-dead-long-live-silverlight.aspx</a> </li>
<li>Jesse Liberty (Senior Community Program Manager in Microsoft Developer Guidance): <a title="http://jesseliberty.com/2010/11/02/silverlight-alive-and-well/" href="http://jesseliberty.com/2010/11/02/silverlight-alive-and-well/" target="_blank">http://jesseliberty.com/2010/11/02/silverlight-alive-and-well/</a> </li>
</ul>
<p>Among the non-Microsofties where</p>
<ul>
<li>Mary-Jo herself: <a title="http://www.zdnet.com/blog/microsoft/microsofts-muglia-reconfirms-html-is-microsofts-cross-platform-play/7854" href="http://www.zdnet.com/blog/microsoft/microsofts-muglia-reconfirms-html-is-microsofts-cross-platform-play/7854" target="_blank">http://www.zdnet.com/blog/microsoft/microsofts-muglia-reconfirms-html-is-microsofts-cross-platform-play/7854</a> </li>
<li>Dan Wahlin (MVP ASP.NET): <a title="http://weblogs.asp.net/dwahlin/archive/2010/11/01/silverlight-is-dead-the-moon-is-made-of-cheese-and-html-5-is-ready-for-prime-time.aspx" href="http://weblogs.asp.net/dwahlin/archive/2010/11/01/silverlight-is-dead-the-moon-is-made-of-cheese-and-html-5-is-ready-for-prime-time.aspx" target="_blank">http://weblogs.asp.net/dwahlin/archive/2010/11/01/silverlight-is-dead-the-moon-is-made-of-cheese-and-html-5-is-ready-for-prime-time.aspx</a> </li>
<li>Jeremy Likness (MVP Silverlight): <a title="http://csharperimage.jeremylikness.com/2010/11/silverlight-and-html5-microsofts.html" href="http://csharperimage.jeremylikness.com/2010/11/silverlight-and-html5-microsofts.html" target="_blank">http://csharperimage.jeremylikness.com/2010/11/silverlight-and-html5-microsofts.html</a> </li>
<li>Oh, me, by the way: <a title="http://flurfunk.sdx-ag.de/2010/11/silverlight-technologie-abkundigung.html" href="http://flurfunk.sdx-ag.de/2010/11/silverlight-technologie-abkundigung.html" target="_blank">http://flurfunk.sdx-ag.de/2010/11/silverlight-technologie-abkundigung.html</a> (German) </li>
</ul>
<p>So, just for the record: I sincerely believe that <strong><u>Microsoft is still very much committed to Silverlight as RIA technology</u></strong> for regular (read <em>non-WP7</em>) clients. </p>
<p>&#160;</p>
<p>Still, as relieved as I am that this mess unfolded that way, it kept me thinking. What if? I mean, what <em>if </em>Microsoft actually had dropped Silverlight on the client…? </p>
<p><strong>What if?</strong></p>
<p>Just imagine… What would happen if Microsoft actually <em>had </em>changed their strategy? What if Silverlight was really dead on the client, and “only” the development platform for WP7?</p>
<ul>
<li>For <strong>the vast majority of regular web applications</strong>: Nothing much would have happened. Use cases here include mostly video and advertisement. And due to the availability of the plugin this is the domain of Adobe Flash. With the advent of HTML5, and it’s coverage of video and graphics (canvas) – and none the least the backing it gets from Apple – it should have been clear to everybody with open eyes that HTML5 will be the future in that area. But that will happen at the expense of Flash, not Silverlight! </li>
</ul>
<p>But from there it would go downhill, and Microsoft would start losing…</p>
<ul>
<li>Microsoft would lose <strong>a platform for non-typical demands on the web</strong>. Demands that go far beyond what HTML5 can deliver. Complex UIs such as car configurators (<a href="http://www.mazda.de/buyingamazda/Konfigurator/" target="_blank">Mazda</a>), HD video streaming (<a href="http://www.maxdome.de/special/silverlight/" target="_blank">maxdome</a>). And Silverlight it gaining momentum in the market, not Flash or some other technology.       <br />&#160; </li>
<li>Microsoft would lose their <strong>platform for RIA <i>applications</i></strong>. In this area HTML5 is of no further relevance at all, rather Adobe AIR and JavaFx are the competition. And in this area Silverlight is way ahead of the completion, both technically in terms of business features, as well as by adoption (usually intranet applications, but also <a href="http://flurfunk.sdx-ag.de/2010/10/sap-setzt-auf-silverlight.html" target="_blank">SAP</a>).       <br />&#160; </li>
<li>Microsoft would lose <strong>the developer base it relies on for Windows Phone 7, and with it WP7 itself</strong>. One of the big selling points for WP7 is the fact that WP7 uses the very same platform as is used for RIA, thus every developer using Silverlight instantly becomes a WP7 developer. Ironically, focusing Silverlight on WP7 would take away that advantage. Silverlight would become a platform you have to learn before doing phone development. And since WP7 is just taking off, the future not yet certain, why take the risk? Why not learn Android instead? Who would then build the apps Microsoft needs?       <br />&#160; </li>
<li>It gets worse: Microsoft would lose <strong>credibility, and the trust of the developer community</strong>. This is not a technology at the end of its life cycle we’re talking about. It’s a technology just beginning to take off, and a technology <em>that they told us were strategic</em>! A technology more and more developers are just beginning to adopt, to invest in. If Microsoft dropped Silverlight – without any warning I might add –, how would those developers react? How could they trust Microsoft to be true to what they call “strategic” in the future? I know what I would think.       <br />&#160; </li>
<li>Needless to say that this would affect their <strong>partners and customers</strong> in the same way. Who would invest in any platform if he cannot be sure the platform is maintained for a reasonable time (rather than being dropped at the spur of a moment). And if the vendor cannot be trusted? The platform may be as good as it wants, the first thing to care about is to protect my investments.       <br />&#160; </li>
<li>In the end this would include <strong>every API, every platform, every offering </strong>they have. This specially includes <strong>Azure – </strong>the very platform Microsoft is betting the company on. Which developer would work against that API? Which ISV would build his software on Azure? Which partner would counsel his customers to use Azure? Which enterprise would rely on Azure with his applications and his data? It’s a strategic platform for Microsoft, sure. But with dropping Silverlight they would just have taught us what that means. </li>
</ul>
<p>Ultimately Microsoft could lose… <strong>Microsoft</strong>. Because at the end of the day, credibility is the most important thing. That’s what made this whole thing a marketing fiasco. Not the fact that a bunch of developers and companies sat on the wrong bandwagon. Lose credibility and you lose the company.</p>
<p>Now, all this is hypothetical – I hope I made that clear with my statement above. And it is also just an opinion and certainly exaggerated in some points. But it may very well be the kind of trash and <a href="http://en.wikipedia.org/wiki/Fear,_uncertainty_and_doubt" target="_blank">FUD</a> that Microsoft will be experiencing for some time. Which is why I believe that Microsoft will continue to have to do damage control for quite some time to come.</p>
<p><font color="#008000">Yours sincerely,      <br /><strong>AJ.NET </strong></font></p>
<p> <a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2010/11/07/silverlight-what-if/"><img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/11/07/silverlight-what-if/" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://ajdotnet.wordpress.com/category/software-development/'>Software Development</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/875/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/875/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/875/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/875/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/875/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/875/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/875/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/875/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/875/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/875/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/875/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/875/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/875/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/875/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=875&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/11/07/silverlight-what-if/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/11/07/silverlight-what-if/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>The Cost of String.Split</title>
		<link>http://ajdotnet.wordpress.com/2010/09/04/the-cost-of-string-split/</link>
		<comments>http://ajdotnet.wordpress.com/2010/09/04/the-cost-of-string-split/#comments</comments>
		<pubDate>Sat, 04 Sep 2010 18:13:40 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=869</guid>
		<description><![CDATA[Some code I wrote a while ago came back to haunt me. You may know the feeling. The use case was simple: A tool chain, processing some files and spitting out others (host service descriptions as input and configuration and proxy code as output – is doesn’t really matter though). At one stage I needed [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=869&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Some code I wrote a while ago came back to haunt me. You may know the feeling.</p>
<p>The use case was simple: A tool chain, processing some files and spitting out others (host service descriptions as input and configuration and proxy code as output – is doesn’t really matter though). At one stage I needed to process a file line by line. And, as usually, my code was nice, clean, tested, maintainable, performing quite well, robust, and unbreakable. In one word: Just perfect. Well, until someone broke it. All he did was feeding a “slightly” larger code fragment — about 5MB file size for a corresponding text file — and he encountered <em><a href="http://msdn.microsoft.com/en-us/library/system.outofmemoryexception.aspx" target="_blank">OutOfMemoryException</a></em>s. Sik!</p>
<p>So, what on earth could have happened here? Well, one of the least things I would have expected: <em><a href="http://msdn.microsoft.com/en-us/library/system.string.split.aspx" target="_blank">string.Split</a> </em>and <em><a href="http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx" target="_blank">StringBuilder</a></em> – despite the fact that I of course had employed them correctly, concise with the general recommendations!&#160; </p>
<p><strong>The Cost of String.Split</strong></p>
<p>It turned out that <em>string.Split </em>trades memory for performance…. Take a string of a certain length, say 100, and split into, say, 10 parts. The result you’ll get will consist of the array (4 bytes per entry, 10 entries in our example), and the content fragments. This is roughly the same memory consumption for the result as for the input string (see also on <a href="http://msdn.microsoft.com/en-us/library/b873y76a.aspx" target="_blank">MSDN</a>).</p>
<blockquote><p>Note: I‘m leaving out the overhead for internal management of strings and memory allocation in general.</p>
</blockquote>
<p>That’s the memory consumption that is obvious and cannot be avoided (OK, I’ll get back to that one!). But what does <em>String.Split </em>add to that cost, if only temporarily?</p>
<p><em>String.Split </em>internally creates an array of integers, with the length of the string as size. In other words for an input string of 100 characters it creates an <em>int[100]</em>, using up 400 bytes! This array is used to remember the index of the found separator, by writing the found index at the next free position. That implies that only the first slots are actually used, the same number as the number of parts the string is split into. In our example 90 slots are simply wasted. This is a usage ratio of 10%! It would only need this array completely in the extreme case of a string only consisting of separators. </p>
<blockquote><p>In case of <em><a href="http://msdn.microsoft.com/en-us/library/system.stringsplitoptions.aspx" target="_blank">StringSplitOptions.RemoveEmptyEntries</a></em> and at least one empty entry, another temporary array for the result is created, add another array the size of the number of parts. Seems things can only get worse.</p>
</blockquote>
<p>Once more: For a any given string as input <em>String.Split </em>returns something more than that as result – and on top of that it needs twice as much memory temporarily! </p>
<p>OK, so 100 characters, 200 bytes, produce 240 bytes result (40 bytes for the array) and 400 bytes temporarily on top. Who cares? But wait, remember the 5MB text file? The resulting string needed 10MB and the result ~11MB. Additionally ~20MB temporarily, of which only 4% – less than 1MB – where actually used. And all this is subject to the <a href="http://msdn.microsoft.com/en-us/magazine/cc534993.aspx" target="_blank">Large Object Heap</a>. Well? Who cares now?</p>
<p><em>Mending…</em></p>
<p>Granted, that’s an extreme case. But how often did I use <em>String.Split </em>in other cases? How often within loops? How big where the input strings? How much unnecessary overhead and memory pressure did that introduce?</p>
<p>What if I could get rid of the temporary overhead? Great. What if I could even get rid of the result? Wait&#8230; what?</p>
<p>Matter of fact, quite often the result from <em>String.Split </em>is processed once, entry per entry, in a loop. And that’s what enumerators are for. So, if I had a respective implementation, instead of writing</p>
<blockquote><p><font face="Courier New">string[] lines = text.Split(Environment.NewLine[0]);        <br />foreach(string line in lines)         <br />&#160;&#160;&#160; &#8230;</font></p>
</blockquote>
<p>I could call a method that returns an enumerator:</p>
<blockquote><p><font face="Courier New">var lines= text.SplitString(Environment.NewLine[0]);        <br />foreach(string line in lines)         <br />&#160;&#160;&#160; &#8230;</font></p>
</blockquote>
<p>And with the lazy evaluation of enumerators I would get one part at a time. And once I’m done processing it, I drop it before going on to the next part. Granted, I still need to touch every part, but no longer all at once. When memory get’s tight, chances are all those parts are in gen 0 when the GC hits.</p>
<p>Meaning I would do no longer consume <em>more than three times </em>the memory of the input string at once. A string of 100 characters/200 bytes as input would <em>not </em>acquire additional 600 bytes. A 10MB string would <em>not </em>need additional 31MB (and only using 12MB of that anyway, subject to the LOH).</p>
<p>Well, I had a minute to spare… . I wrote a helper class for this post, tested to behave exactly like <em>String.Split</em>, so it should be possible to just replace every call to <em>Split </em>with the <em>SplitString </em>extension method, like above. You can find the code for download <a href="http://www.alexander-jung.net/download/StringSplit.zip" target="_blank">here</a>. </p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p> <a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2010/09/04/the-cost-of-string-split/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/09/04/the-cost-of-string-split/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://ajdotnet.wordpress.com/category/c/'>C#</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/869/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/869/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/869/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/869/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/869/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/869/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/869/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/869/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/869/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/869/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/869/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/869/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/869/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/869/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=869&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/09/04/the-cost-of-string-split/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/09/04/the-cost-of-string-split/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>CommunicationException: NotFound</title>
		<link>http://ajdotnet.wordpress.com/2010/08/29/communicationexception-notfound/</link>
		<comments>http://ajdotnet.wordpress.com/2010/08/29/communicationexception-notfound/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 13:44:55 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=860</guid>
		<description><![CDATA[CommunicationException: NotFound – that is the one exception that bugs every Silverlight developer sooner or later. Take the image from an earlier post: This error essentially tells you that a server call somehow messed up – which is obvious – and nothing beyond, much less anything useful to diagnose the issue. This not exactly rocket [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=860&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>CommunicationException: NotFound</em> – that is the one exception that bugs every Silverlight developer sooner or later. Take the image from an <a href="http://ajdotnet.wordpress.com/2010/08/08/silverlight-and-integrated-authentication/" target="_blank">earlier post</a>:</p>
<p><img title="app_error" alt="app_error" src="http://ajdotnet.files.wordpress.com/2010/08/app_error.jpg?w=788&#038;h=132&#038;h=132" width="788" height="132" /></p>
<p>This error essentially tells you that a server call somehow messed up – which is obvious – and nothing beyond, much less anything useful to diagnose the issue.</p>
<blockquote><p>This not exactly rocket science, but the question comes up regularly at the <a href="http://silverlight.net/forums/" target="_blank">Silverlight forums</a>, so I’m trying to convey the complete picture once and for all (and only point to it, once the question comes up again – and it will!).</p>
<p>I’m also violating my rule not to write about something that is readily available somewhere else. But I have the feeling that the available information is either limited to certain aspects, not conveying the complete picture, or hard to come by or to understand. Why else would the question come up that regularly?</p>
</blockquote>
<p><strong>&#160;</strong></p>
<p><strong>The Root Cause</strong></p>
<p>So, why the “NotFound”, anyway? Any HTTP response contains a numeric code. 200 (OK) if everything went well, others for errors, redirections, caching, etc.; a list can be found at <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes" target="_blank">wikipedia</a>. Any error whatsoever results in a different result code, say 401 (Unauthorized), 404 (NotFound), or 503 (Service unavailable).</p>
<p>Any plugin using the browser network stack (as Silverlight does by default) however is also subject to some restrictions the browser imposes in the name of security: The browser will only pass 200 in good cases or 404 without any further information in any other case to the plugin. And the plugin can do exactly <a href="http://en.wikipedia.org/wiki/Nil" target="_blank">NIL</a> about it, as it never gets around to see the original response.</p>
<blockquote><p>Note: This is not Silverlight specific, but happens to every plugin that makes use of the browser network stack.</p>
</blockquote>
<p>Generally speaking there are two different groups of issues that are reported as errors:</p>
<ol>
<li>Service errors: The services throws some kind of exception. </li>
<li>Infrastructure issues: The service cannot be reached at all. </li>
</ol>
<p>Since those two groups of issues have very different root causes, it makes sense to be able to at least tell them apart, if nothing else. This is already half of the diagnosis.</p>
<p><strong>&#160;</strong></p>
<p><strong>Handling Service Errors</strong></p>
<p>Any exception thrown by a WCF service is by default returns as service error (i.e. SOAP fault) with HTTP response code 500 (Internal Server Errors). And as we have established above, the Silverlight plugin never get’s to see that error.</p>
<p>The recommended way to handle this situation is to tweak the HTTP response code to 200 (OK) and expect the Silverlight client code to be able to distinguish error from valid result. Actually this is already backed into WCF: A generated client proxy will deliver errors via the <em>AsyncCompletedEventArgs.Error </em>property – <em>if </em>we tweak the response code that is. Fortunately the extensible nature of WCF allows us to do just that using a behavior, which you can find readily available <a href="http://msdn.microsoft.com/en-us/library/dd470096(VS.96).aspx" target="_blank">here</a>.</p>
<p>Once we get errors through to Silverlight we can go ahead and make actual <em>use </em>of the error to further distinguish server errors:</p>
<ol>
<li>Business errors (e.g. server side validations) with additional information (like the property that was invalid). </li>
<li>Generic business errors with no additional information. </li>
<li>Technical errors on the server (database not available, <em>NullReferenceException</em>, …). </li>
</ol>
<p>It’s the technical errors that will reveal more diagnostic information about the issue at hand, but let’ go through them one by one…</p>
<p><u>Business errors with additional information</u> are actually part of the service’s contract, more to the point, the additional information constitutes the fault contract:</p>
<p><img title="code_declared_fault1" alt="code_declared_fault1" src="http://ajdotnet.files.wordpress.com/2010/08/code_declared_fault1.jpg?w=435&#038;h=280" width="435" height="280" /></p>
<p><img title="code_declared_fault2" alt="code_declared_fault2" src="http://ajdotnet.files.wordpress.com/2010/08/code_declared_fault2.jpg?w=414&#038;h=53" width="414" height="53" /></p>
<p>These faults are also called <em>declared faults </em>for the very reason that they are part of the contract and declared in advance. Declared faults are thrown and handled as <em>FaultException&lt;T&gt; (</em>available as full blown .NET version <a href="http://msdn.microsoft.com/en-us/library/ms576199.aspx" target="_blank">on the server</a>, and as respective <a href="http://msdn.microsoft.com/en-us/library/ms576199(v=VS.95).aspx" target="_blank">counterpart in Silverlight</a>), with the additional information as generic type parameter:</p>
<p><img title="code_throw_declared" alt="code_throw_declared" src="http://ajdotnet.files.wordpress.com/2010/08/code_throw_declared.jpg?w=479&#038;h=138" width="479" height="138" /></p>
<p>Note: There’s no need to construct the <em>FaultException </em>from another exception. And of course this <em>StandardFault</em> class is rather simplistic, not covering more fine-grained information, e.g. invalid properties – which you may need in order to plug into the client side validation infrastructure. But that’s another post. </p>
<p>On the client side this information is available in a similar way, and can be used to give the user feedback:</p>
<p><img title="code_handle_declared" alt="code_handle_declared" src="http://ajdotnet.files.wordpress.com/2010/08/code_handle_declared.jpg?w=674&#038;h=137" width="674" height="137" /></p>
<p><u></u></p>
<p><u>Generic business errors</u> are not part of the service contract, hence they are called undeclared faults, and they cannot contain additional information beyond what the already got. From a coding perspective they are represented by <em>FaultExceptions </em>(the non-generic version, <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.faultexception.aspx" target="_blank">.NET</a> and <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.faultexception(v=VS.95).aspx" target="_blank">Silverlight</a>) and thrown and handled similarly to declared faults:</p>
<p><img title="code_handle_undeclared" alt="code_handle_undeclared" src="http://ajdotnet.files.wordpress.com/2010/08/code_handle_undeclared.jpg?w=546&#038;h=119" width="546" height="119" /></p>
<p>However, the documentation states…</p>
<blockquote><p>“In a service, use the FaultException class to create an untyped fault to return to the client <em>for debugging purposes</em>. […]</p>
<p>In general, it is strongly recommended that you use the <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.faultcontractattribute(v=VS.95).aspx" target="_blank">FaultContractAttribute</a> to design your services to return strongly typed SOAP faults (and not managed exception objects) for all fault cases in which you decide the client requires fault information. […]”</p>
<p><a title="http://msdn.microsoft.com/en-us/library/system.servicemodel.faultexception(v=VS.95).aspx" href="http://msdn.microsoft.com/en-us/library/system.servicemodel.faultexception(v=VS.95).aspx" target="_blank">MSDN</a></p>
</blockquote>
<p>&#160;</p>
<p>That leaves <u>arbitrary exceptions</u> thrown for whatever reason in your service. WCF also translates them to (undeclared) faults, yet it uses the generic version of <em>FaultException, </em>with the predefined type <em><a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.exceptiondetail(v=VS.95).aspx" target="_blank">ExceptionDetails</a></em>. This way, any exception in the service can (or rather could) be picked up on the client:</p>
<p><img title="code_handle_exception" alt="code_handle_exception" src="http://ajdotnet.files.wordpress.com/2010/08/code_handle_exception.jpg?w=742&#038;h=135" width="742" height="135" /></p>
<p>However, while <em>ExceptionDetails </em>contains information about exception type, stack trace, and so on, that fault contains by default only a generic text, stating “The server was unable to process the request due to an internal error.”. This is exactly as it should be in production, where any further information might give the wrong person too much information. During development however it may make sense to get more information, to be able to diagnose these issues more quickly. To do that, the configuration has to be changed:</p>
<p><img title="config_exception_debug" alt="config_exception_debug" src="http://ajdotnet.files.wordpress.com/2010/08/config_exception_debug.jpg?w=433&#038;h=98" width="433" height="98" /></p>
<p>And now the returned information contains various details about the original exception:</p>
<p><img title="app_exception_info" alt="app_exception_info" src="http://ajdotnet.files.wordpress.com/2010/08/app_exception_info.jpg?w=610&#038;h=222" width="610" height="222" /></p>
<p>BTW: To complete the error handling on the client, you need to to address the situation were the issue was on the client itself, in which case the exception would not be of some <em>FaultException </em>type:</p>
<p><img title="code_handle_client_error" alt="code_handle_client_error" src="http://ajdotnet.files.wordpress.com/2010/08/code_handle_client_error.jpg?w=635&#038;h=103" width="635" height="103" /></p>
<p>This covers any exception thrown from the WCF service, provided it could be reached at all.</p>
<p><em><strong>Alternative routes…</strong></em></p>
<p>As I said, tweaking the HTTP response code is the recommended way to handle these errors. This is still a compromise on the protocol level to work around the browser network stack limitation. However, there are other workarounds to do that, and for the sake of completeness:</p>
<ol>
<li>Compromise on the service’s contract: Rather than using the fault contract, one could include the error information in the regular data contract. This is typical for REST style services, e.g. Amazon works <a href="http://docs.amazonwebservices.com/AWSECommerceService/2009-11-01/DG/index.html?ItemSearch.html" target="_blank">that way</a>. For my application services I am generally reluctant to make that compromise. The down side is that is doesn’t cover technical errors, but that can be remedied with a global try/catch in your service method. </li>
<li>Avoid the browser network stack. Silverlight offers its own network stack implementation (<a href="http://msdn.microsoft.com/en-us/library/dd920295(v=VS.95).aspx" target="_blank">client HTTP handling</a>), though it defaults to using the browser stack. Using client HTTP handling, one can handle any HTTP response code, as well as offering more freedom regarding HTTP headers and methods. The downside however is, that we lose some of the features the browser adds to its network stack. Cookie handling and browser cache come to mind. </li>
</ol>
<p><strong>&#160;</strong></p>
<p><strong>Handling Infrastructure Issues</strong></p>
<p>If some issue prevented the service to be called at all, there is obviously no way for it to tweak the response. And unless we revert to <a href="http://msdn.microsoft.com/en-us/library/dd920295(v=VS.95).aspx" target="_blank">client HTTP handling</a> (which would be a rather drastic means, given the implications), the Silverlight client gets no chance to look at it either. Hence, we cannot do anything about our <em>CommunicationException: NotFound.</em></p>
<p><em>However, </em>by tweaking the response code for service exceptions as proposed above, we at least make it immediately obvious (if only by indirect reasoning) that the remaining <em>CommunicationException: NotFound </em>is indeed an infrastructure issue.</p>
<p>The good news is that infrastructure issues usually carry enough information by themselves. Also they appear rarely, but if they do they usually are quite obvious (including obviously linked to some recent change), affect any call (not just some), and are easily reproducibly. Hence using Fiddler one can get information about the issue very easily (even in <a href="http://www.fiddler2.com/fiddler/help/hookup.asp#Q-LocalTraffic" target="_blank">the localhost scenario</a>). </p>
<p>The fact that the issue is pretty obvious pretty fast, in turn makes it usually quite easy to attribute it to the actual cause – it must have been a change made very recently. Typical candidates are easy to track down:</p>
<ul>
<li>Switching between Cassini and IIS. I have written about that <a href="http://ajdotnet.wordpress.com/2010/08/08/silverlight-and-integrated-authentication/" target="_blank">here</a>. </li>
<li>Changing some application URLs, e.g. giving the web project a root folder for Cassini, without updating the service references. </li>
<li>Generating or updating service proxies, but forgetting to change the generated URLs to <a href="http://msdn.microsoft.com/en-us/library/cc197941(v=VS.95).aspx" target="_blank">relative addresses</a>. </li>
<li>Visual Studio sometimes assigns a new port to Cassini if the project settings say “auto-assign port”, and the last used port is somehow blocked. This may happen if another Cassini instance still lingers around from the last debugging session. </li>
<li>Any change recently made to the protocol or IIS configuration. </li>
</ul>
<p>This only get’s dirty if the change was made by some team member and you have no way of knowing what he actually changed. But since this will likely affect the whole team, you will be in good company <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><strong>&#160;</strong></p>
<p><strong>Wrap up</strong></p>
<p>There are two main issues with <em>CommunicationException: NotFound</em>: </p>
<ol>
<li>It doesn’t tell you anything and the slew of possible reasons makes it unnecessarily hard to diagnose the root cause. </li>
<li>It prevents legitimate handling of business errors in a WCF/SOAP conformant way. </li>
</ol>
<p>Both issues are addressed sufficiently by tweaking the HTTP response code of exceptions thrown within the service, which is simple enough. Hence the respective <a href="http://msdn.microsoft.com/en-us/library/dd470096(VS.96).aspx" target="_blank">WCF endpoint behavior</a> should be part of every Silverlight web project. And in case this is not possible for some reason, you can revert to <a href="http://msdn.microsoft.com/en-us/library/dd920295(v=VS.95).aspx" target="_blank">client HTTP handling</a>.</p>
<p>&#160;</p>
<p>Much if not all of this information is available somewhere within the Silverlight documentation. However, each link I found only covered certain aspects or symptoms, and I hope I have provided a more complete picture on how to tackle (for the last time) <em>CommunicationException: NotFound</em>.</p>
<p><font color="#008000">That’s all fro now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2010/08/29/communicationexception-notfound/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/08/29/communicationexception-notfound/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://ajdotnet.wordpress.com/category/aspnet/'>ASP.NET</a>, <a href='http://ajdotnet.wordpress.com/category/c/'>C#</a>, <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://ajdotnet.wordpress.com/category/software-development/'>Software Development</a>, <a href='http://ajdotnet.wordpress.com/category/wcf/'>WCF</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/860/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/860/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/860/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/860/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/860/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/860/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/860/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/860/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/860/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/860/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/860/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/860/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/860/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/860/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=860&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/08/29/communicationexception-notfound/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/app_error.jpg?w=788&#38;h=132" medium="image">
			<media:title type="html">app_error</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_declared_fault1.jpg?w=435" medium="image">
			<media:title type="html">code_declared_fault1</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_declared_fault2.jpg?w=414" medium="image">
			<media:title type="html">code_declared_fault2</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_throw_declared.jpg?w=479" medium="image">
			<media:title type="html">code_throw_declared</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_handle_declared.jpg?w=674" medium="image">
			<media:title type="html">code_handle_declared</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_handle_undeclared.jpg?w=546" medium="image">
			<media:title type="html">code_handle_undeclared</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_handle_exception.jpg?w=742" medium="image">
			<media:title type="html">code_handle_exception</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/config_exception_debug.jpg?w=433" medium="image">
			<media:title type="html">config_exception_debug</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/app_exception_info.jpg?w=610" medium="image">
			<media:title type="html">app_exception_info</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_handle_client_error.jpg?w=635" medium="image">
			<media:title type="html">code_handle_client_error</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/08/29/communicationexception-notfound/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>A Pesky Little Silverlight Problem: The Presumptuous Scrollbar</title>
		<link>http://ajdotnet.wordpress.com/2010/08/15/a-pesky-little-silverlight-problem-the-presumptuous-scrollbar/</link>
		<comments>http://ajdotnet.wordpress.com/2010/08/15/a-pesky-little-silverlight-problem-the-presumptuous-scrollbar/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 11:54:43 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=846</guid>
		<description><![CDATA[Just a small issue, but it may drive you crazy if you have to hunt it down… (it did that with me.) I have my Silverlight application sitting on an .aspx page, occupying all real estate. I work a while. And suddenly there is this scrollbar appearing on the right side: To hunt it down, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=846&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just a small issue, but it may drive you crazy if you have to hunt it down… (it did that with me.)</p>
<p>I have my Silverlight application sitting on an .aspx page, occupying all real estate. I work a while. And suddenly there is this scrollbar appearing on the right side:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2010/08/app_with_scrollbar.jpg"><img title="app_with_scrollbar" alt="app_with_scrollbar" src="http://ajdotnet.files.wordpress.com/2010/08/app_with_scrollbar.jpg?w=439&#038;h=227" width="439" height="227" /></a></p>
<p>To hunt it down, I create a new Silverlight project. No scrollbar. I compare the .aspx‘’. No difference to speak of. I deconstruct the Silverlight part of my application in hope the scrollbar will disappear. It won’t.</p>
<p>&#160;</p>
<p>Finally I stumbled by accident over the reason (which is – in retrospect – quite obvious):</p>
<p>Here’s the .aspx fragment that creates the Silverlight plugin:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2010/08/code_with_scrollbar.jpg"><img title="code_with_scrollbar" alt="code_with_scrollbar" src="http://ajdotnet.files.wordpress.com/2010/08/code_with_scrollbar.jpg?w=818&#038;h=320" width="818" height="320" /></a></p>
<p>Created by VS, I changed some code above this frament, and reformatted it in VS for better readability. And you know what? It’s already broken!</p>
<p>And I broke it by&#8230; drum-roll please… reformatting it in VS! The issue is the (irrelevant, according to any standard I’m aware of) whitespaces between the tags. Manually changing the code back to the original (closing <em>object</em> tag and <em>iframe </em>element at the end)&#8230;</p>
<h3></h3>
<p><a href="http://ajdotnet.files.wordpress.com/2010/08/code_without_scrollbar.jpg"><img title="code_without_scrollbar" alt="code_without_scrollbar" src="http://ajdotnet.files.wordpress.com/2010/08/code_without_scrollbar.jpg?w=919&#038;h=239" width="919" height="239" /></a></p>
<p>&#8230; will solve the problem and the scrollbar is gone:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2010/08/app_without_scrollbar.jpg"><img title="app_without_scrollbar" alt="app_without_scrollbar" src="http://ajdotnet.files.wordpress.com/2010/08/app_without_scrollbar.jpg?w=439&#038;h=227" width="439" height="227" /></a></p>
<p>Just one more reason to prefer Silverlight over HTML, if you ask me!</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p> <a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2010/08/15/a-pesky-little-silverlight-problem-the-presumptuous-scrollbar/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/08/15/a-pesky-little-silverlight-problem-the-presumptuous-scrollbar/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/846/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/846/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/846/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/846/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/846/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/846/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/846/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/846/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/846/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/846/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/846/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/846/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/846/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/846/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=846&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/08/15/a-pesky-little-silverlight-problem-the-presumptuous-scrollbar/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/app_with_scrollbar.jpg?w=439" medium="image">
			<media:title type="html">app_with_scrollbar</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_with_scrollbar.jpg?w=818" medium="image">
			<media:title type="html">code_with_scrollbar</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_without_scrollbar.jpg?w=919" medium="image">
			<media:title type="html">code_without_scrollbar</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/app_without_scrollbar.jpg?w=439" medium="image">
			<media:title type="html">app_without_scrollbar</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/08/15/a-pesky-little-silverlight-problem-the-presumptuous-scrollbar/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Out of the ordinary: Pakistan</title>
		<link>http://ajdotnet.wordpress.com/2010/08/13/out-of-the-ordinary-pakistan/</link>
		<comments>http://ajdotnet.wordpress.com/2010/08/13/out-of-the-ordinary-pakistan/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 19:12:36 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=837</guid>
		<description><![CDATA[No bits this time. Pakistan is encountering a &#34;disaster [that] is one of the most challenging that any country has faced in recent years” (BBC). The infrastructure is already down, and yet another flood is announced (CNN). Food, clean water, and medicine are unavailable in large areas, diseases are imminent (BBC).&#160;&#160; At the same time [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=837&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>No bits this time.</p>
<p>Pakistan is encountering a &quot;disaster [that] is one of the most challenging that any country has faced in recent years” (<a href="http://www.bbc.co.uk/news/world-south-asia-10943606" target="_blank">BBC</a>). The infrastructure is already down, and yet another flood is announced (<a href="http://edition.cnn.com/2010/WORLD/asiapcf/08/13/pakistan.floods/index.html?eref=edition#fbid=lmWRlAU8QXr&amp;wom=false" target="_blank">CNN</a>). Food, clean water, and medicine are unavailable in large areas, diseases are imminent (<a href="http://www.bbc.co.uk/news/world-south-asia-10961640" target="_blank">BBC</a>).&#160;&#160; </p>
<p>At the same time the Red Cross (<a href="http://www.icrc.org/eng" target="_blank">ICRC</a>) reports “relief &#8216;not in sufficient quanitites&#8217;” (<a href="http://www.bbc.co.uk/news/world-south-asia-10937676" target="_blank">BBC</a>) and the UN states that “massive scale-up [is] needed in Pakistan flood relief operation” (<a href="http://www.un.org/apps/news/story.asp?NewsID=35609&amp;Cr=pakistan&amp;Cr1=" target="_blank">UN</a>). </p>
<p>The German “tagesschau” reports that donations for Pakistan have been 620,000 €. During the same amount of time after the Haiti earth quake, donations have been as high as 20,100,000 € – 32 times as much (<a href="http://www.tagesschau.de/multimedia/sendung/ts21092.html" target="_blank">ARD, tagesschau, 12.08.10, 3:16</a>). And this is apparently a <a href="http://yubanet.com/world/Critical-Lack-of-Funding-Hampers-Emergency-Response-in-Pakistan.php" target="_blank">general trend</a>.</p>
<p>&#160;</p>
<p>If you can read this blog post, chances are you’re better off than many people and certainly those affected by this catastrophe!</p>
<p align="center"><strong>DO SOMETHING! </strong></p>
<ul>
<li><a href="http://www.icrc.org/eng" target="_blank">International Committee of the Red Cross</a> </li>
<li><a href="http://www.unicef.org/" target="_blank">UNICEF</a> and <a href="http://www.unhcr.org/" target="_blank">UNHCR</a> </li>
<li><a href="http://www.caritas.org/activities/emergencies/PakistanFloodCrisis.html" target="_blank">Caritas</a>&#160; </li>
<li><em>Or your preferred national <a href="http://www.interaction.org/crisis-list/interaction-members-respond-floods-pakistan" target="_blank">relief organization</a>…</em>&#160; </li>
</ul>
<p>If you need some additional motivation try this <a href="http://www.huffingtonpost.com/2010/08/04/pakistan-flood-photos-dra_n_670914.html#s122853" target="_blank">photo series</a> or <a href="http://www.youtube.com/results?search_query=pakistan+flood&amp;aq=f" target="_blank">youtube</a>.</p>
<p><strong><font color="#008000">AJ.NET</font></strong></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/miscellaneous/'>Miscellaneous</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/837/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/837/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/837/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/837/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/837/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/837/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/837/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/837/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/837/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/837/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/837/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/837/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/837/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/837/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=837&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/08/13/out-of-the-ordinary-pakistan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight and Integrated Authentication</title>
		<link>http://ajdotnet.wordpress.com/2010/08/08/silverlight-and-integrated-authentication/</link>
		<comments>http://ajdotnet.wordpress.com/2010/08/08/silverlight-and-integrated-authentication/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 09:25:17 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=827</guid>
		<description><![CDATA[I’ve been meaning to write about this for a while, because it’s a reoccurring nuisance: Using integrated authentication with Silverlight. More to the point, the nuisance is the differences between Cassini (Visual Studio Web Development Server) and IIS in combination with some WCF configuration pitfalls for Silverlight enabled WCF services…. Note: Apart from driving me [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=827&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’ve been meaning to write about this for a while, because it’s a reoccurring nuisance: Using integrated authentication with Silverlight. More to the point, the nuisance is the differences between Cassini (Visual Studio Web Development Server) and IIS in combination with some WCF configuration pitfalls for Silverlight enabled WCF services….</p>
<blockquote><p>Note: Apart from driving <em>me </em>crazy, I’ve been stumbling over this issue quite a few times in the <a href="http://forums.silverlight.net/" target="_blank">Silverlight forums</a>. Thus I’m going through this in detail, explaining one or the other seemingly obvious point&#8230;</p>
</blockquote>
<p>Many ASP.NET <a href="http://en.wikipedia.org/wiki/Line_of_business" target="_blank">LOB</a> applications run on the intranet with <a href="http://en.wikipedia.org/wiki/Windows_Integrated_Authentication" target="_blank">Windows integrated authentication</a> (see also <a href="http://msdn.microsoft.com/en-us/library/aa292114(VS.71).aspx" target="_blank">here</a>). This way the user is instantly available from <a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx" target="_blank"><em>HttpContext.User</em></a>, e.g. for display, and can be subjected to application security via a <a href="http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.aspx" target="_blank"><em>RoleProvider</em></a>. Silverlight on the other hand runs on the client. I have written about making the user and his roles available on the client <a href="http://ajdotnet.wordpress.com/2009/11/08/silverlight-bitspieces-part-7-application-permissions/" target="_blank">before</a>. However, the more important part is to have this information available in the WCF services serving the data and initiating server side processing. And being WCF, they work a little different from ASP.NET, or not, or only sometimes….</p>
<p>&#160;</p>
<p><strong></strong></p>
<p><strong>Starting with Cassini… </strong></p>
<p>Let’s assume we are developing a Silverlight application, using the defaults, i.e. Cassini, and the templates Visual Studio offers for new items. When a “Silverlight-enabled WCF service” is created, it uses the following settings:</p>
<p><img title="xml_serviceconfig" alt="xml_serviceconfig" src="http://ajdotnet.files.wordpress.com/2010/08/xml_serviceconfig.jpg?w=798&#038;h=278" width="798" height="278" /></p>
<p>Now there’s (already) a choice to make: Use ASP.NET compatibility? Or stay WCF only? (That question may be worth a separate post…). With ASP.NET compatibility, <em><a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext_properties.aspx" target="_blank">HttpContext.*</a></em> is available within the service, including <em><a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx" target="_blank">HttpContext.User</a></em>. The WCF pendant of the user is <em><a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicesecuritycontext.primaryidentity.aspx" target="_blank">OperationContext.Current.ServiceSecurityContext.PrimaryIdentity</a></em>. Take the following sample implementation to see which information is available during a respective call:</p>
<p><img title="code_service" alt="code_service" src="http://ajdotnet.files.wordpress.com/2010/08/code_service.jpg?w=692&#038;h=600" width="692" height="600" /></p>
<p>The client code to test that service is simple as can be:</p>
<p><img title="code_page" alt="code_page" src="http://ajdotnet.files.wordpress.com/2010/08/code_page.jpg?w=886&#038;h=494" width="886" height="494" /></p>
<p>The XAML is boilerplate enough, but for the sake of completeness:</p>
<p><img title="xaml_page" alt="xaml_page" src="http://ajdotnet.files.wordpress.com/2010/08/xaml_page.jpg?w=657&#038;h=452" width="657" height="452" /></p>
<p>I choose compatibility mode, and as the client shows, <em><a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx" target="_blank">HttpContext.User</a> </em>is available out of the box:</p>
<p><img title="app_default" alt="app_default" src="http://ajdotnet.files.wordpress.com/2010/08/app_default.jpg?w=518&#038;h=113" width="518" height="113" /></p>
<p>Great, just what an ASP.NET developer is used to. But compatibility or not, it also shows that the WCF user is not available. <em>But! </em>WCF is configurable, and all we have to do is set the correct configuration. In this case we have to choose <em><a href="http://msdn.microsoft.com/en-us/library/system.net.authenticationschemes.aspx" target="_blank">Ntlm</a> </em>as authentication scheme: </p>
<p><img title="xml_serviceconfig_ntlm" alt="xml_serviceconfig_ntlm" src="http://ajdotnet.files.wordpress.com/2010/08/xml_serviceconfig_ntlm.jpg?w=515&#038;h=132" width="515" height="132" /></p>
<p>And look what we’ve got:</p>
<p><img title="app_with_ntlm" alt="app_with_ntlm" src="http://ajdotnet.files.wordpress.com/2010/08/app_with_ntlm.jpg?w=531&#038;h=113" width="531" height="113" /></p>
<p>Great, no problem at all. Now we have the baseline and are ready to move on to IIS.</p>
<p><strong>&#160;</strong></p>
<p><strong>Now for IIS…</strong></p>
<p>Moving to IIS on the developer machine is simple. Just go to the web project settings, tab “Web”, choose “Use Local IIS Web Server”, optionally creating the respective virtual directory from here. In order to work against IIS, Visual Studio needs to run with administrative permissions.</p>
<p><img title="vs_projectconfig" alt="vs_projectconfig" src="http://ajdotnet.files.wordpress.com/2010/08/vs_projectconfig.jpg?w=687&#038;h=121" width="687" height="121" /></p>
<p>&#160;</p>
<p>Moving from Cassini to IIS however has a slew of additional pitfalls:</p>
<ul>
<li>The service URL </li>
<li>The IIS configuration for authentication </li>
<li>WCF service activation issues </li>
<li>The WCF authentication scheme </li>
<li>localhost vs. machine name </li>
</ul>
<p>Usually they show up as team (which obviously doesn&#8217;t help), but let’s look at them one by one.</p>
<p>&#160;</p>
<p><em><strong></strong></em></p>
<p><em><strong>The service URL</strong></em></p>
<p>There’s one difference between how Cassini and IIS are being addressed by the web project: Projects usually run in Cassini in the root (i.e. localhost:12345/default.aspx), while in IIS they run in a virtual directory (e.g. localhost/MyApplication/default.aspx). This may affect you whenever you are dealing with absolute and relative URLs. It will at least cause the generated service URLs to differ more than just by the port information. Of course you can recreate the service references at that point, but you don’t want to do that every time you switch between Cassini and IIS, do you?</p>
<blockquote><p>BTW: There’s a similar issue if you are running against IIS, using localhost, and you create a service reference: This may write the machine name into the <em>ServiceReferences.ClientConfig </em>(depending on the proxy configuration), e.g. <em>mymachine.networkname.com/application</em>, rather than <em>localhost</em>. While these are semantically the same URLs, for Silverlight is qualifies as a cross domain call. Consequently it will look for a <em>clientaccesspolicy.xml</em> file which is probably not there and react with a respective security exception. </p>
</blockquote>
<p>The solution with Silverlight 3 is to dynamically adjust the endpoint of the client proxy in your code to point to the service within the web, the Silverlight application was started from:</p>
<p><img title="code_adjusturl" alt="code_adjusturl" src="http://ajdotnet.files.wordpress.com/2010/08/code_adjusturl.jpg?w=863&#038;h=206" width="863" height="206" /></p>
<p>Silverlight 4 supports <a href="http://msdn.microsoft.com/en-us/library/cc197941(v=VS.95).aspx" target="_blank">relative URLs</a> out of the box:</p>
<p><img title="xml_clientconfig" alt="xml_clientconfig" src="http://ajdotnet.files.wordpress.com/2010/08/xml_clientconfig.jpg?w=571&#038;h=82" width="571" height="82" /></p>
<p>Coming versions of the tooling will probably generate relative URLs in the first place; until then you’ll have to remember to adjust them every time you add or update a service reference.</p>
<p>&#160;</p>
<p><em><strong></strong></em></p>
<p><em><strong>The IIS configuration for authentication</strong></em></p>
<p>This one may be obvious, but in combination with others, it may still bite you. Initially starting the application will result in the notorious <em>NotFound </em>exception:</p>
<p><img title="app_error" alt="app_error" src="http://ajdotnet.files.wordpress.com/2010/08/app_error.jpg?w=788&#038;h=132" width="788" height="132" /></p>
<blockquote><p>Note: To be able to handle server exceptions in Silverlight you’ll have to overcome some IE plugin limitations, inhibiting access to http response 500. This can be achieved via a behavior, as described on <a href="http://msdn.microsoft.com/en-us/library/dd470096(VS.96).aspx" target="_blank">MSDN</a>. However this addresses exceptions thrown by the service implementation and won’t help in the infrastructure related errors I’m talking about here.</p>
</blockquote>
<p>The eventlog actually contains the necessary information: </p>
<p><img title="el_require_wa" alt="el_require_wa" src="http://ajdotnet.files.wordpress.com/2010/08/el_require_wa.jpg?w=640&#038;h=444" width="640" height="444" /></p>
<p>No windows authentication? Well, while Cassini automatically runs in the context of the current user, IIS needs explicitly being told that Windows Authentication is required. This is simple in IIS configuration, just enable Windows Authentication and disable Anonymous Authentication in the IIS configuration for the respective virtual directory. </p>
<p>&#160;</p>
</p>
<p><em><strong></strong></em></p>
<p><em><strong>WCF service activation issues</strong></em></p>
<p>Running again will apparently not have changed anything at all, displaying the same error. With just a seemingly minor difference in the eventlog entry:</p>
<p><img title="el_require_aa" alt="el_require_aa" src="http://ajdotnet.files.wordpress.com/2010/08/el_require_aa.jpg?w=640&#038;h=444" width="640" height="444" /></p>
<p>That’s right. The service demands to run <em>anonymous </em>after it just demanded to run <em>authenticated</em>. Call it schizophrenic.</p>
<p>To make a long story short, our service has two endpoints with conflicting demands: The regular service endpoint requires Windows Authentication, while the “mex” endpoint for service meta information requires Anonymous access. OK, we might re-enable anonymous access, but that wasn’t indented, so the way to work around this activation issue is to keep anonymous access disabled and to remove the “mex” endpoint from the web.config:</p>
<p><img title="xml_serviceconfig_nomex" alt="xml_serviceconfig_nomex" src="http://ajdotnet.files.wordpress.com/2010/08/xml_serviceconfig_nomex.jpg?w=796&#038;h=132" width="796" height="132" /></p>
<p>Curiously generating the service reference still works in Visual Studio (perhaps with login dialogs, but still)…</p>
<p>&#160;</p>
<p><em><strong></strong></em></p>
<p><em><strong></strong></em></p>
<p><em><strong>The WCF authentication scheme</strong></em></p>
<p>We’re still not there. The next issue when running the application might be a login credentials dialog when the service is called. And no matter what you type in, it still won’t work anyway, again with the <em>NotFound </em>exception. Unfortunately this time without an eventlog entry.</p>
<p>Again, to make it short, IIS doesn’t support <em>Ntlm </em>as authentication scheme, we need to switch to <em><a href="http://msdn.microsoft.com/en-us/library/system.net.authenticationschemes.aspx" target="_blank">Negotiate</a></em>… . </p>
<p><img title="xml_serviceconfig_negotiate" alt="xml_serviceconfig_negotiate" src="http://ajdotnet.files.wordpress.com/2010/08/xml_serviceconfig_negotiate.jpg?w=516&#038;h=133" width="516" height="133" /></p>
<p>And <em>now </em>it works:</p>
<p><img title="app_with_negotiate" alt="app_with_negotiate" src="http://ajdotnet.files.wordpress.com/2010/08/app_with_negotiate.jpg?w=525&#038;h=111" width="525" height="111" /></p>
<p>Do I have to say that this configuration doesn’t run in Cassini? Right, every time you switch between IIS and Cassini you have to remember to adjust the configuration. There is another enumeration value for the authentication scheme, named <em><a href="http://msdn.microsoft.com/en-us/library/system.net.authenticationschemes.aspx" target="_blank">IntegratedWindowsAuthentication</a></em>, which would be nice – if it worked. Unfortunately those two values, <em>Ntlm </em>and <em>Negotiate</em>, are the only ones that work, under Cassini and IIS respectively.</p>
<p>&#160;</p>
<p><em><strong></strong></em></p>
<p><em><strong>localhost vs. machine name</strong></em></p>
<p>Now it works, we get the user information as needed. For a complete picture however, we need to look at the difference between addressing the local web server via <em>localhost </em>or via the machine name: Calls against localhost are optimized by the operating system to bypass some of the network protocol stack and work directly against the kernel mode driver (HTTP.SYS). This affects caching as well as http sniffers like <a href="http://www.fiddler2.com" target="_blank">Fiddler</a>, which both work <a href="http://www.fiddler2.com/fiddler/help/hookup.asp#Q-LocalTraffic" target="_blank">only via the machine name</a>. </p>
<blockquote><p>Note: This may actually be the very reason to switch to IIS early during development, when you need Fiddler as debugger (to check the actually exchanged information). Otherwise it’s later on, when you need it as profiler (to measure network utilization). Of course you’ll want http caching enabled and working by that time.</p>
</blockquote>
<p>Of course you can put the machine name in the project settings, yet this would affect all team members. Perhaps a better idea is to have the page redirect dynamically:</p>
<p><img title="code_redirect" alt="code_redirect" src="http://ajdotnet.files.wordpress.com/2010/08/code_redirect.jpg?w=374&#038;h=166" width="374" height="166" /></p>
<p>Another word on caching: In IIS6 caching has to be explicitly set for the .xap file, using 1 day as default cache time and allowing 1 minute at the minimum. During development this may be an issue. With IIS7 caching should be automatically set to <em>CacheUntilChange</em> and you may also set the cache time with a resolution in seconds.</p>
<p>&#160;</p>
<p><strong></strong></p>
<p><strong>Where are we?</strong></p>
<p>OK, that was quite a list of pitfalls and differences between Cassini and IIS, even IIS6 and IIS7. Some of this may go away with the new <a href="http://weblogs.asp.net/scottgu/archive/2010/06/28/introducing-iis-express.aspx" target="_blank">IIS Express</a>. Some will stay and remain a nuisance. Visual Studio initially guides you towards using Cassini. At one time however you’ll have to switch to IIS. And since you cannot have both at the same time, this may be an issue especially in development teams. My recommendation would be: Start with IIS right away or plan the switch as a concerted action within your team.</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2010/08/08/silverlight-and-integrated-authentication/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/08/08/silverlight-and-integrated-authentication/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://ajdotnet.wordpress.com/category/aspnet/'>ASP.NET</a>, <a href='http://ajdotnet.wordpress.com/category/c/'>C#</a>, <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://ajdotnet.wordpress.com/category/software-development/'>Software Development</a>, <a href='http://ajdotnet.wordpress.com/category/wcf/'>WCF</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/827/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/827/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/827/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/827/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/827/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/827/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/827/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=827&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/08/08/silverlight-and-integrated-authentication/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/xml_serviceconfig.jpg?w=798" medium="image">
			<media:title type="html">xml_serviceconfig</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_service.jpg?w=692" medium="image">
			<media:title type="html">code_service</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_page.jpg?w=886" medium="image">
			<media:title type="html">code_page</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/xaml_page.jpg?w=657" medium="image">
			<media:title type="html">xaml_page</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/app_default.jpg?w=518" medium="image">
			<media:title type="html">app_default</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/xml_serviceconfig_ntlm.jpg?w=515" medium="image">
			<media:title type="html">xml_serviceconfig_ntlm</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/app_with_ntlm.jpg?w=531" medium="image">
			<media:title type="html">app_with_ntlm</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/vs_projectconfig.jpg?w=687" medium="image">
			<media:title type="html">vs_projectconfig</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_adjusturl.jpg?w=863" medium="image">
			<media:title type="html">code_adjusturl</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/xml_clientconfig.jpg?w=571" medium="image">
			<media:title type="html">xml_clientconfig</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/app_error.jpg?w=788" medium="image">
			<media:title type="html">app_error</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/el_require_wa.jpg?w=640" medium="image">
			<media:title type="html">el_require_wa</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/el_require_aa.jpg?w=640" medium="image">
			<media:title type="html">el_require_aa</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/xml_serviceconfig_nomex.jpg?w=796" medium="image">
			<media:title type="html">xml_serviceconfig_nomex</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/xml_serviceconfig_negotiate.jpg?w=516" medium="image">
			<media:title type="html">xml_serviceconfig_negotiate</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/app_with_negotiate.jpg?w=525" medium="image">
			<media:title type="html">app_with_negotiate</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/08/code_redirect.jpg?w=374" medium="image">
			<media:title type="html">code_redirect</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/08/08/silverlight-and-integrated-authentication/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Flurfunk</title>
		<link>http://ajdotnet.wordpress.com/2010/07/26/flurfunk/</link>
		<comments>http://ajdotnet.wordpress.com/2010/07/26/flurfunk/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 17:59:17 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Blogroll]]></category>
		<category><![CDATA[SDX]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=801</guid>
		<description><![CDATA[Recently I have been blogging a little less than usual. One reason for that was that my company started its corporate blog, named „Flurfunk“ (German, „water-cooler conversation“?). And being an experienced blogger… they said… and I was arrested. Anyway, it’s in German, therefore&#8230; &#60;content locale=”de; de-DE”&#62; &#8230; für die der deutschen Sprache mächtigen Leser: SDX [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=801&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I have been blogging a little less than usual. One reason for that was that my company started its corporate blog, named „Flurfunk“ (German, „water-cooler conversation“?). And being an experienced blogger… they said… and I was arrested. Anyway, it’s in German, therefore&#8230;</p>
<p><font color="#0000ff"><a href="http://flurfunk.sdx-ag.de/" target="_blank"><img style="display:inline;margin:5px 0 5px 5px;" title="flurfunk" alt="flurfunk" align="right" src="http://ajdotnet.files.wordpress.com/2010/07/flurfunk.png?w=200&#038;h=169" width="200" height="169" /></a>&lt;<font color="#800000">content</font> locale=”<font color="#ff0000">de; de-DE</font>”&gt;</font></p>
<p>&#8230; für die der deutschen Sprache mächtigen Leser: SDX hat den firmeneigenen Blog „<a href="http://flurfunk.sdx-ag.de/" target="_blank">Flurfunk</a>” gestartet.</p>
<p>Die Themen sind ein bunter Mix aus kleineren <a href="http://flurfunk.sdx-ag.de/2010/07/pivot-datenvisualisierung-in.html" target="_blank">technischen Artikeln</a> (und Kollegen die das mit dem “klein” noch <a href="http://flurfunk.sdx-ag.de/2010/06/wird-windows-azure-erfolg-haben.html" target="_blank">nicht verstanden haben</a> <img src='http://s2.wp.com/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> ), netten <a href="http://flurfunk.sdx-ag.de/2010/07/technik-zum-anfassen-wm-auswertung-mit_13.html" target="_blank">Hinweisen aus dem Back-Office</a>&#160; <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> , aktuelles <a href="http://flurfunk.sdx-ag.de/2010/07/juni-office-day.html" target="_blank">aus dem Büro</a>, <a href="http://flurfunk.sdx-ag.de/2010/06/sdx-technical-council-agiles.html" target="_blank">Veranstaltungshinweise</a> – und nicht zuletzt <a href="http://flurfunk.sdx-ag.de/2010/06/sie-schlafen-abends-gerne-zu-hause-in.html" target="_blank">Marketing</a>.     <br />OK, auch nicht ganz so ernst gemeintes <a href="http://flurfunk.sdx-ag.de/2010/06/neulich-im-sdx-portal.html" target="_blank">ist dabei</a> ;o). Schön bunt ist‘s <a href="http://flurfunk.sdx-ag.de/2010/06/jpmcc-die-experts-fielen-auf_9998.html" target="_blank">auf jeden Fall</a>!</p>
<p>Einfach mal reinschauen und guten Tag sagen <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><font color="#0000ff">&lt;/<font color="#800000">content</font>&gt;</font></p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/blogroll/'>Blogroll</a>, <a href='http://ajdotnet.wordpress.com/category/sdx/'>SDX</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/801/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/801/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/801/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/801/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/801/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/801/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/801/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=801&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/07/26/flurfunk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/07/flurfunk.png?w=200" medium="image">
			<media:title type="html">flurfunk</media:title>
		</media:content>
	</item>
		<item>
		<title>Replacing Events by Callbacks</title>
		<link>http://ajdotnet.wordpress.com/2010/07/24/replacing-events-by-callbacks/</link>
		<comments>http://ajdotnet.wordpress.com/2010/07/24/replacing-events-by-callbacks/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 11:57:00 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=779</guid>
		<description><![CDATA[My last post laid out how the employment of events has changed recently. Most importantly the broadcasting scenario – which was the major pattern so far – is no longer the only relevant pattern. Rather the “event-based asynchronous pattern”, MSDN, has emerged. Reasons include the inherently asynchronous nature of Silverlight as well as parallel patterns. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=779&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My <a href="http://ajdotnet.wordpress.com/2010/07/18/employment-of-events-is-changing/" target="_blank">last post</a> laid out how the employment of events has changed recently. Most importantly the broadcasting scenario – which was the major pattern so far – is no longer the only relevant pattern. Rather the “event-based asynchronous pattern”, <a href="http://msdn.microsoft.com/en-us/library/wewwczdw.aspx" target="_blank">MSDN</a>, has emerged. Reasons include the inherently asynchronous nature of Silverlight as well as parallel patterns.</p>
<p>Now for the practical implications of this new pattern. Let’s look at an example to get the idea, and a better understanding of the consequences in code…</p>
<p>Let’s assume a component that is instantiated, does some work (allegedly asynchronous, and notifying about the progress) and provides the result at the end via an event. This is akin to making a server call, showing a confirmation message box, or the way the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker(VS.95).aspx" target="_blank">BackgroundWorker</a> component works. </p>
<p><strong>Example 1: Using events </strong></p>
<p>First, implementing the a component the classical way would look somewhat like this:</p>
<p>The result event needs a respective <em>EventArgs </em>class, the declaration and the trigger method:</p>
<p> <font color="#0000ff">public</font> <font color="#0000ff">class</font> WorkResultEventArgs : EventArgs   <br />{   <br />&#160;&#160;&#160; <font color="#0000ff">public</font> <font color="#0000ff">object</font> ResultData { <font color="#0000ff">get</font>; <font color="#0000ff">set</font>; }   <br />}   </p>
<p><font color="#0000ff">public</font> <font color="#0000ff">class</font> MyWorkingComponent1   <br />{   <br />&#160;&#160;&#160; <font color="#0000ff">public</font> <font color="#0000ff">event</font> EventHandler&lt;WorkResultEventArgs&gt; WorkResult;   <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#0000ff">protected</font> <font color="#0000ff">virtual</font> <font color="#0000ff">void</font> OnWorkResult(<font color="#0000ff">object</font> resultData)   <br />&#160;&#160;&#160; {   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">if</font> (WorkResult != <font color="#0000ff">null</font>)   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; WorkResult(<font color="#0000ff">this</font>, <font color="#0000ff">new</font> WorkResultEventArgs() { ResultData = resultData });   <br />&#160;&#160;&#160; }&#160; <br />&#160;&#160;&#160; …   <br />}   <br /> 
<p>A work progress event should go a little further and provide cancelation support:</p>
<p> <font color="#0000ff">public</font> <font color="#0000ff">class</font> WorkProgressEventArgs : CancelEventArgs   <br />{   <br />&#160;&#160;&#160; <font color="#0000ff">public</font> <font color="#0000ff">int</font> Progress { <font color="#0000ff">get</font>; <font color="#0000ff">set</font>; }   <br />&#160;&#160;&#160; <font color="#0000ff">public</font> <font color="#0000ff">object</font> SomeData { <font color="#0000ff">get</font>; <font color="#0000ff">set</font>; }   <br />}   </p>
<p><font color="#0000ff">public</font> <font color="#0000ff">class</font> MyWorkingComponent1   <br />{&#160; <br />&#160;&#160;&#160; <font color="#0000ff">public</font> <font color="#0000ff">event</font> EventHandler&lt;WorkProgressEventArgs&gt; WorkProgress;   <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#0000ff">protected</font> <font color="#0000ff">virtual</font> <font color="#0000ff">bool</font> OnWorkProgress(<font color="#0000ff">int</font> progress, <font color="#0000ff">object</font> someData)   <br />&#160;&#160;&#160; {   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">if</font> (WorkProgress == <font color="#0000ff">null</font>)   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">return</font> <font color="#0000ff">true</font>;   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; var ea = <font color="#0000ff">new</font> WorkProgressEventArgs() { Progress = progress, SomeData = someData, Cancel = <font color="#0000ff">false</font> };   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; WorkProgress(<font color="#0000ff">this</font>, ea);   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">return</font> ea.Cancel ? <font color="#0000ff">false</font> : <font color="#0000ff">true</font>;   <br />&#160;&#160;&#160; }   <br />&#160;&#160;&#160; …   <br />}   <br /> 
<p>Now we only need the actual worker method:</p>
<p> <font color="#0000ff">public</font> <font color="#0000ff">class</font> MyWorkingComponent1   <br />{&#160; <br />&#160;&#160;&#160; …   <br />&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#0000ff">public</font> <font color="#0000ff">void</font> StartWork()   <br />&#160;&#160;&#160; {   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">int</font> sum = 0;   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">for</font> (<font color="#0000ff">int</font> i = 0; i &lt; 10; ++i)   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sum += i;   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">if</font> (!OnWorkProgress(i, sum))   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">return</font>;   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; OnWorkResult(sum);   <br />&#160;&#160;&#160; }   <br />}   <br /> 
<p>Again, we may assume that there is some asynchronicity involved, e.g. the loop could contain a web request or something. But this example should do for the sake of the argument.</p>
<p>The usage (as by support form Visual Studio to create the event handlers) would look like this:</p>
<p> <font color="#0000ff">public</font> <font color="#0000ff">void</font> Test1()   <br />{   <br />&#160;&#160;&#160; <font color="#0000ff">var</font> worker = <font color="#0000ff">new</font> MyWorkingComponent1();   <br />&#160;&#160;&#160; worker.WorkProgress += <font color="#0000ff">new</font> EventHandler&lt;WorkProgressEventArgs&gt;(Worker_WorkProgress);   <br />&#160;&#160;&#160; worker.WorkResult += <font color="#0000ff">new</font> EventHandler&lt;WorkResultEventArgs&gt;(Worker_WorkResult);   <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; worker.StartWork();   <br />}   </p>
<p><font color="#0000ff">void</font> Worker_WorkProgress(<font color="#0000ff">object</font> sender, WorkProgressEventArgs e)   <br />{   <br />&#160;&#160;&#160; Console.WriteLine(e.Progress + <font color="#800000">&quot;:&quot;</font> + e.SomeData);   <br />}   </p>
<p><font color="#0000ff">void</font> Worker_WorkResult(<font color="#0000ff">object</font> sender, WorkResultEventArgs e)   <br />{   <br />&#160;&#160;&#160; Console.WriteLine(<font color="#800000">&quot;Result:&quot;</font> + e.ResultData);   <br />}   <br /> 
<p>Creating the component, registering the event handlers, running the task, throw the component away. The fact that events are multi cast capable is never used at all (and never will, as the component is rather short-lived). </p>
<p>I guess we can agree that this is all very boilerplate. And all in all, that’s quite some overhead, from the component perspective as well as from the client code. </p>
<p><strong>Example 2: Using callbacks</strong></p>
<p>Now let’s try the new approach. Rather than defining an event, I pass in two callbacks. The information that was carried in the <em>EventArgs </em>is moved to the parameter lists, thus no need for these classes. The <em>Cancel </em>property is replaced by the return value of the callback. And since the client code always follows the same idiom, I expect the callbacks as constructor parameters, eliminating a source of errors along the way — something that is not possible with event handlers: </p>
<p> <font color="#0000ff">public</font> <font color="#0000ff">class</font> MyWorkingComponent2   <br />{&#160; <br />&#160;&#160;&#160; <font color="#0000ff">public</font> Action&lt;MyWorkingComponent2, <font color="#0000ff">object</font>&gt; WorkResult {<font color="#0000ff">get</font>;<font color="#0000ff">set</font>;}&#160; <br />&#160;&#160;&#160; <font color="#0000ff">public</font> Func&lt;MyWorkingComponent2, <font color="#0000ff">int</font>, <font color="#0000ff">object</font>, bool&gt; WorkProgress { <font color="#0000ff">get</font>; <font color="#0000ff">set</font>; }&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#0000ff">public</font> MyWorkingComponent2(&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Action&lt;MyWorkingComponent2, <font color="#0000ff">object</font>&gt; workResult,&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Func&lt;MyWorkingComponent2, <font color="#0000ff">int</font>, <font color="#0000ff">object</font>, bool&gt; workProgress)&#160; <br />&#160;&#160;&#160; {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; WorkResult = workResult;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; WorkProgress= workProgress;&#160; <br />&#160;&#160;&#160; }&#160; <br />&#160;&#160;&#160; …   <br />}   <br /> 
<p>The worker method changes only slightly:</p>
<p> <font color="#0000ff">public</font> <font color="#0000ff">class</font> MyWorkingComponent2   <br />{&#160; <br />&#160;&#160;&#160; …   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#0000ff">public</font> <font color="#0000ff">void</font> StartWork()&#160; <br />&#160;&#160;&#160; {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">int</font> sum = 0;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">for</font> (<font color="#0000ff">int</font> i = 0; i &lt; 10; ++i)&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sum += i;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">if</font> (!WorkProgress(<font color="#0000ff">this</font>, i, sum))&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">return</font>;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; WorkResult(<font color="#0000ff">this</font>, sum);&#160; <br />&#160;&#160;&#160; }&#160; <br />}   <br /> 
<p>That’s it. No <em>EventArgs </em>classes, no events, no respective <em>OnEventHappened</em> methods. Granted, the callback declarations are a little more complex, and their parameters also lack intellisense providing information about the semantics of each parameter. But otherwise? Way shorter, way more concise, way less overhead. The actual worker method hasn&#8217;t changed at all, but all the event related overhead is gone, which amounted to only 40% LOC. </p>
<p>Now the client code, first only slightly adapted:</p>
<p> <font color="#0000ff">public</font> <font color="#0000ff">void</font> Test1()   <br />{   <br />&#160;&#160;&#160; <font color="#0000ff">var</font> worker = <font color="#0000ff">new</font> MyWorkingComponent2(   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; (sender, resultData) =&gt; Worker_WorkResult(sender, resultData),   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; (sender, progress, someData) =&gt; Worker_WorkProgress(sender, progress, someData)   <br />&#160;&#160;&#160; );   <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; worker.StartWork();   <br />}   </p>
<p><font color="#0000ff">bool</font> Worker_WorkProgress(<font color="#0000ff">object</font> sender, <font color="#0000ff">int</font> progress, <font color="#0000ff">object</font> someData)   <br />{   <br />&#160;&#160;&#160; Console.WriteLine(progress + <font color="#800000">&quot;:&quot;</font> + someData);   <br />&#160;&#160;&#160; <font color="#0000ff">return</font> <font color="#0000ff">true</font>;   <br />}   </p>
<p><font color="#0000ff">void</font> Worker_WorkResult(<font color="#0000ff">object</font> sender, <font color="#0000ff">object</font> resultData)   <br />{   <br />&#160;&#160;&#160; Console.WriteLine(<font color="#800000">&quot;Result:&quot;</font> + resultData);   <br />}   <br /> 
<p>As you can see, it didn’t change that much. But passing in the lambdas via the constructor fits the use case far better than events, and it is even more robust, as I cannot forget to pass in a callback via the constructor, the way I can forget to register an event handler.</p>
<p>Speaking of lambdas, and since the implementation is that simple, we can even simplify the client code further by omitting those two handler methods: </p>
<p> <font color="#0000ff">public</font> <font color="#0000ff">void</font> Test1()   <br />{   <br />&#160;&#160;&#160; <font color="#0000ff">var</font> worker = <font color="#0000ff">new</font> MyWorkingComponent2(   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; (sender, resultData) =&gt; { Console.WriteLine(<font color="#800000">&quot;Result:&quot;</font> + resultData); },   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; (sender, progress, someData) =&gt; { Console.WriteLine(progress + <font color="#800000">&quot;:&quot;</font> + someData); <font color="#0000ff">return</font> <font color="#0000ff">true</font>; }   <br />&#160;&#160;&#160; );   <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; worker.StartWork();   <br />}   </p>
<p>Alright, this would have been possible with events as well if you used anonymous methods. But Visual Studio guides you otherwise and early examples of anonymous methods (before we had lambdas) where rather ugly, so I doubt that can be seen as valid counterargument. Here however lambdas can be seen as typical means of choice. </p>
<p><strong>Verdict</strong></p>
<p>Neat? Net result:</p>
<ul>
<li>I’m writing less code on the event source side, including no longer declaring <em>EventArgs </em>classes. </li>
<li>I’m writing less code on the event sink side. </li>
<li>The handler methods can use clean parameter lists (rather than <em>EventArgs</em>). </li>
<li>I’m eliminating the risk of forgetting to register event handlers by making the callbacks explicit parameters. </li>
<li>I’m elimination the danger of leaks due to failing to consistently deregistering event handlers.
<ul>
<li>(That was not addressed in the example, but still.) </li>
</ul>
</li>
<li>When chaining together several of these steps I can make the logic – especially conditional processing – more explicit and concise.
<ul>
<li>Events would either require setting up beforehand (partly unnecessary overhead), or setup on demand, cluttering the handler with registration and deregistration code. </li>
</ul>
</li>
</ul>
<p>All in all, this is way more readable, way more robust, and way more efficient than using events.</p>
<p>I for one have begun to adopt this scheme quite liberally. My Silverlight bookshelf application has wrappers for service calls that translate the event to callbacks (several actually, including error handling and other demands). My dialogs always take callbacks for OK and Cancel. I so far have two <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.input.icommand(v=VS.95).aspx" target="_blank">ICommand</a></em> implementations, both take callbacks (one with parameters, the other without). I even have a <em>PropertyObserver</em> class that translates a <em><a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.propertychanged(v=VS.95).aspx" target="_blank">PropertyChanged</a></em> event into a callback.     <br />Actual event handlers? Apart from the wrappers enabling what I just presented, only a few reacting to control events.</p>
<p>In other words: This is not just an interesting technical detail. It really changes the way I’m addressing certain demands.</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p> <a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2010/07/24/replacing-events-by-callbacks/"><img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/07/24/replacing-events-by-callbacks/" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://ajdotnet.wordpress.com/category/c/'>C#</a>, <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://ajdotnet.wordpress.com/category/software-development/'>Software Development</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/779/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/779/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/779/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/779/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/779/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/779/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/779/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/779/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/779/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/779/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/779/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/779/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/779/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/779/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=779&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/07/24/replacing-events-by-callbacks/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/07/24/replacing-events-by-callbacks/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Employment of Events is changing&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2010/07/18/employment-of-events-is-changing/</link>
		<comments>http://ajdotnet.wordpress.com/2010/07/18/employment-of-events-is-changing/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 13:27:40 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=786</guid>
		<description><![CDATA[The other day I had a little chat with a colleague. It was about one of his worker components and how it used events to communicate intermediate state and the final result. About event registration and deregistration, and the ungainly code resulting from it. When I suggested using callbacks instead of events, he quickly jumped [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=786&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The other day I had a little chat with a colleague. It was about one of his worker components and how it used events to communicate intermediate state and the final result. About event registration and deregistration, and the ungainly code resulting from it. When I suggested using callbacks instead of events, he quickly jumped on the bandwagon; a few day later I got a single note on Messenger: „Callbacks are WAY COOL!“.</p>
<p>That got me thinking. Why did I recommend callbacks? When and why did I abandon events? What’s wrong with events anyway?</p>
<p>Well, there’s nothing wrong with events at all. It’s just that Silverlight, asynchronous, and multithreaded processing have changed the picture (and I may have worked too much in those areas lately <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ). And this is the deal:</p>
<ol>
<li>Until recently I used to “see” (read: write code for/against) events mainly from the event consumer side. WinForms, WebForms; register handler, react to something. That kind of stuff.
<ul>
<li>Since “recently” I kind of had to do that less often. Why? Silverlight data binding solved many of the demands I previously used to address with event handlers. Making a control invisible for example. (Events still drive databinding, but at the same time databinding shields them away from me.) </li>
</ul>
</li>
<li>Also since “recently” I have had to implement the providing part quite a bit more often. Why? Silverlight databinding relies on certain interfaces that contain event declarations, namely <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=VS.95).aspx" target="_blank"><em>INotifyPropertyChanged</em></a>, <a href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.inotifycollectionchanged(v=VS.95).aspx" target="_blank"><em>INotifyCollectionChanged</em></a>, and <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo(v=VS.95).aspx" target="_blank"><em>INotifyDataErrorInfo</em></a><em>.</em> </li>
<li>And the “event-based asynchronous pattern”. Yep. We’ll get to that one. </li>
</ol>
<p>OK, let’s try to classify these scenarios.</p>
<p><strong>Broadcasts</strong></p>
<p>The first two points are just two sides of the same coin: <em>The radio broadcasting scenario</em>.</p>
<ul>
<li>Some component wants to advertise interactions or state changes; hence it broadcasts them by way of events. </li>
<li>Some client code needs to get notified about one or the other of these events; hence it subscribes to the event by way of an respective event handler, to consume it from there on. </li>
</ul>
<p>Same as radio, the broadcaster broadcasts and doesn&#8217;t care whether anyone listens. Same as radio, the receiver is turned one and listens as long as something comes in. Well, the analogy stops at the life time: Event source and consumers tend to have similar life time.</p>
<p><strong>Passing the Baton</strong></p>
<p>The 3rd point is actually a quite different scenario: Start some work and have an event notify me about the result (and sometimes about intermediate state). Once I receive the result I let go of the participant and pass the baton on to the next piece of work.</p>
<p>Same as in a relay run, each participant does one job and once it’s done, he is out of business. Same as in a relay run, participation is obligatory – take someone out (or put something in his way) and the whole chain collapses.</p>
<p>Needless to say that this is nothing like the broadcasting scenario…</p>
<p>Usually the reason for the event approach (rather than simple return values) is asynchronous processing; and in fact this is not a particularly new pattern – <em><a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker(VS.95).aspx" target="_blank">BackgroundWorker</a></em> works accordingly. On the other hand the pattern is still evolving, as the usual pattern for asynchronous work has been no pattern at all (i.e. leave it to the developer, as <em><a href="http://msdn.microsoft.com/en-us/library/system.threading.thread(VS.95).aspx" target="_blank">Thread</a></em> or <em><a href="http://msdn.microsoft.com/en-us/library/system.threading.threadpool(VS.95).aspx" target="_blank">ThreadPool</a> </em>do), or the <em><a href="http://msdn.microsoft.com/en-us/library/2e08f6yc.aspx" target="_blank">IAsyncResult pattern</a></em> (relying on a wait handle). New developments however start to employ events more often, and Microsoft has actually dubbed this pattern as “event-based asynchronous pattern” (<a href="http://msdn.microsoft.com/en-us/library/wewwczdw.aspx" target="_blank">see MSDN</a>).</p>
<p>One area which relies heavily on this pattern is server requests in Silverlight, via <a href="http://msdn.microsoft.com/en-us/library/tt0f69eh(v=VS.95).aspx" target="_blank"><em>WebClient</em></a> or generated proxies. But it doesn’t stop there, as Silverlight is asynchronous by nature, rather than by exception: Showing a modal dialog, navigating to another page, (down-)loading an assembly. And quite often these single incidences are chained together to form a bigger logical program flow, for example:</p>
<ul>
<li><em>The user clicks the delete button –&gt; the application shows the confirmation dialog –&gt; a call to the delete operation is made –&gt; IF it succeeds (the code navigates to a list page –&gt; …) OTHERWISE (an error message box is shown –&gt; …)</em> </li>
</ul>
<p>Any arrow represents an event based “hop” to bridge some “asynchronicity gap” – essentially turning the logically sequential chain into a decoupled, temporary register and deregister event nightmare.</p>
<blockquote><p>Coming back to the beginning of the post: This is the scenario I was discussion with my colleague. And doing this with a whole bunch of events and respective handler methods is simply awkward, especially if you even have to provide the event sources, usually with respective <em>EventArgs </em>classes. And the issue of having to consistently deregister the event handlers in order to avoid memory leaks becomes more prevalent.</p>
</blockquote>
<p><strong>Changing the Picture…</strong></p>
<p>Inevitably I got annoyed with the setup/teardown orgies, and eventually I began to abandon events in this case and started passing simple callbacks along. Like this:</p>
<p><span style="color:#0000ff;">void</span> DeleteBook(Book book)     <br />{     <br />&#160;&#160;&#160; <span style="color:#0000ff;">string</span> msg= <span style="color:#800000;">&quot;Delete book #&quot;</span> + book.Inventory + <span style="color:#800000;">&quot;, ‘&quot;</span> + book.Title + <span style="color:#800000;">&quot;’ ?&quot;</span> ;     <br />&#160;&#160;&#160; MessageBoxes.Instance.ShowConfirm(<span style="color:#0000ff;">null</span>, msg,&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ok =&gt; { <span style="color:#0000ff;">if</span> (ok) BeginDeleteBook(book); }     <br />&#160;&#160;&#160; );     <br />}</p>
<p><span style="color:#0000ff;">void</span> BeginDeleteBook(Book book)     <br />{     <br />&#160;&#160;&#160; <span style="color:#0000ff;">this</span>.DeleteBookCall.Invoke(book.BookID,     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ea =&gt; NavigateToBooks());     <br />}</p>
<p>And actually I’m not the only one following this approach. The <a href="http://msdn.microsoft.com/en-us/library/dd460717.aspx" target="_blank">Task Parallel Library</a> TPL for example has already started to make heavy use of callbacks. So this is definitely not limited to Silverlight…</p>
<blockquote><p>Note: Also this lays the ground for a next evolutionary step: <a href="http://en.wikipedia.org/wiki/Coroutine" target="_blank">Coroutines</a>.</p>
<p>Caliburn has a <a href="http://caliburn.codeplex.com/wikipage?title=IResult&amp;ProjectName=caliburn" target="_blank">nice example</a> of what this looks like; a little weird at first glance actually, but it collects all that logically sequential but technically asynchronous control flow in one method. Jeremy digs a little deeper into the topic in his post “<a href="http://csharperimage.jeremylikness.com/2010/03/sequential-asynchronous-workflows-in.html" target="_blank">Sequential Asynchronous Workflows in Silverlight using Coroutines</a>”.&#160; </p>
</blockquote>
<p>Anyway, even without going into coroutines, the callbacks over events approach has its merits in terms of coding efficiency. I’ll provide a motivating example, next post.</p>
<p><span style="color:#008000;">That’s all for now folks,      <br /><strong>AJ.NET</strong></span></p>
<p> <a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2010/07/18/employment-of-events-is-changing/"><img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/07/18/employment-of-events-is-changing/" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://ajdotnet.wordpress.com/category/c/'>C#</a>, <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://ajdotnet.wordpress.com/category/software-development/'>Software Development</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/786/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=786&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/07/18/employment-of-events-is-changing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2010/07/18/employment-of-events-is-changing/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>The Future (of) UI</title>
		<link>http://ajdotnet.wordpress.com/2010/06/12/the-future-of-ui/</link>
		<comments>http://ajdotnet.wordpress.com/2010/06/12/the-future-of-ui/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 13:54:20 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=773</guid>
		<description><![CDATA[The way we think about user interaction – actually the user interfaces themselves – is changing. The iPhone seems to be the protagonist teaching us new ways to interact with phones and iPad even coins a new form factor driving this trend further. Touch and multi touch are becoming main stream because vendors have begun [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=773&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The way we think about <a href="http://en.wikipedia.org/wiki/Human-computer_interaction" target="_blank">user interaction</a> – actually the <a href="http://en.wikipedia.org/wiki/User_interface" target="_blank">user interfaces</a> themselves – is changing. The <a href="http://en.wikipedia.org/wiki/Iphone" target="_blank">iPhone</a> seems to be the protagonist teaching us new ways to interact with phones and <a href="http://en.wikipedia.org/wiki/Ipad" target="_blank">iPad</a> even coins a new form factor driving this trend further. Touch and multi touch are becoming main stream because vendors have begun to create operating systems, UI metaphors, and backing services <em>around </em>these interaction principles – rather than slightly adjusting OSes/UIs build for conventional PCs with keyboard and mouse. </p>
<p>This is actually a defining feature of the next evolutionary step of UI, namely <a href="http://en.wikipedia.org/wiki/Natural_User_Interface" target="_blank"><em>Natural User Interfaces (NUI)</em></a>. As wikipedia states…</p>
<blockquote><p>A NUI relies on a user being able to carry out relatively natural motions, movements or gestures that they quickly discover control the computer application or manipulate the on-screen content. <strong>The most descriptive identifier of a NUI is the lack of a physical keyboard and/or mouse.</strong> (<a href="http://en.wikipedia.org/wiki/Natural_User_Interface" target="_blank">wikipedia</a>)</p>
</blockquote>
<p>While Apple seems to take the lead in public perception, Microsoft has a rather mixed lineup: With smart phones <a href="http://www.windowsphone7.com/multimedia/Media2" target="_blank">Windows Mobile 7</a> seems a bit like “taking the last chance”, even if the move to <a href="http://blogs.msdn.com/b/somasegar/archive/2010/03/15/introducing-windows-phone-7-development-tools.aspx" target="_blank">Silverlight as a platform</a> is a bold one and (IMO) a good one. On the other hand they just managed to <a href="http://gizmodo.com/5527442/microsoft-cancels-innovative-courier-tablet-project" target="_blank">drop</a> the very promising – by itself as well as positioned against the iPad – <a href="http://www.engadget.com/2010/03/05/microsofts-courier-digital-journal-exclusive-pictures-and-de/" target="_blank">Courier</a> project. As a <a href="http://www.leading-edge-dev.de/" target="_blank">colleague</a> stated in your internal company blog: “I’m frustrated. Period.” And lastly Microsoft has <a href="http://en.wikipedia.org/wiki/Microsoft_Surface" target="_blank">Surface</a> which has no competition I’m aware of at all (unless you want to <a href="http://www.springwald.de/content/projekte/hardware/multitouch/index.html" target="_blank">build one yourself</a>).</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:935cca87-17e4-4ee0-9b15-a240ef06e01d" class="wlWriterEditableSmartContent">
<div><span style="text-align:center; display: block;"><a href="http://ajdotnet.wordpress.com/2010/06/12/the-future-of-ui/"><img src="http://img.youtube.com/vi/-9j_tYP-kzc/2.jpg" alt="" /></a></span></div>
</div>
<p>Surface is not only <a href="http://www.microsoft.com/surface/" target="_blank">commercially available</a>, it also adds the capability to detect objects placed on the table and thus goes beyond plain multi touch. And it is subject to further research, as this excerpt from PDC09 shows: (better quality <a href="http://channel9.msdn.com/pdc2008/KYN04/" target="_blank">here</a>, at 83:00)</p>
</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:11cb75fa-8543-47f8-b022-09ef54157bcf" class="wlWriterEditableSmartContent">
<div><span style="text-align:center; display: block;"><a href="http://ajdotnet.wordpress.com/2010/06/12/the-future-of-ui/"><img src="http://img.youtube.com/vi/XfzplPIrzjY/2.jpg" alt="" /></a></span></div>
</div>
<p>&#160;</p>
<p><strong>Looking Ahead </strong></p>
<p>Well, this is kind of what we have today. If you would like to see where this might be heading, have a look at the <a href="http://www.microsoft.com/winme/0902/1000046/Wharton_Tech_Conference_MBR.asx" target="_blank">Microsoft Gives Glimpse Into the Future</a> talk Stephen Elop held early ‘09. It’s a 36 minutes video, but you may jump to 14:00 and watch the presentation of &quot;Glimpse in the future&quot;. What’s presented there is impressive: Live translations enabling people talking with each other in different languages. Surface like tables interacting directly with iPad-like multi touch tablets placed on it. <a href="http://en.wikipedia.org/wiki/Minority_Report_(film)" target="_blank">Minority Report</a> like control. <a href="http://en.wikipedia.org/wiki/Augmented_reality" target="_blank">Augmented reality</a>. …. It’s even more impressive since everything is backed afterwards by actually existing (if in early stages) technology. There’s a shortened and also an extended version available on youtube:</p>
</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:0a1d850d-fe40-478c-89e0-4746b7e29ea3" class="wlWriterEditableSmartContent">
<div><span style="text-align:center; display: block;"><a href="http://ajdotnet.wordpress.com/2010/06/12/the-future-of-ui/"><img src="http://img.youtube.com/vi/jkTsZUzCkcI/2.jpg" alt="" /></a></span></div>
</div>
</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:3d6239f5-f1d0-4644-8a11-d0a4dc42d390" class="wlWriterEditableSmartContent">
<div><span style="text-align:center; display: block;"><a href="http://ajdotnet.wordpress.com/2010/06/12/the-future-of-ui/"><img src="http://img.youtube.com/vi/i2WK7mOQO2g/2.jpg" alt="" /></a></span></div>
</div>
<p>&#160;</p>
<p>Speaking of Minority Report. Another great video comes from John Underkoffler; John has been the science adviser for that movie and <em>he does the whole presentation with exactly that technology</em>!</p>
</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:2a205d3d-e46b-44ab-a95f-75e3a63a805b" class="wlWriterEditableSmartContent">
<div><span style="text-align:center; display: block;"><a href="http://ajdotnet.wordpress.com/2010/06/12/the-future-of-ui/"><img src="http://img.youtube.com/vi/b6YTQJVzwlI/2.jpg" alt="" /></a></span></div>
</div>
<p>This talk is certainly worth watching, as he makes some very interesting observations (in fact, watching this video triggered this post; thanks Daniel). His final prediction is … <em>ambitious</em>: “I think in 5 years time, when you buy a computer, you’ll get this.”</p>
<p>Is that cool or what?</p>
<p>&#160;</p>
<p><strong>Second Thoughts</strong>&#160;</p>
<p>Well, as they say:</p>
<blockquote><p>“Prediction is very difficult, especially about the future.” (<a href="http://larry.denenberg.com/predictions.html" target="_blank">various</a>)</p>
</blockquote>
<p>There’s one thing I don’t like about those predictions. They are (deliberately?) incomplete. They certainly shine in new fields of applications for computers, new degrees of collaboration, new ways of interaction. Like home integration, meeting areas with huge collaboration screens, geo services and augmented reality, or simply navigating and reshaping existing data. But in their aim to show new ways of doing things, they neglect the “old”, conventional demands, demands that won’t go away.</p>
<p>The very fact that these NUI approaches – touch, gestures, even voice – are defined by “the lack of a physical keyboard and/or mouse” (and in case you didn’t notice – NONE of the above videos hat a keyboard in it!) renders them inappropriate for a whole bunch of scenarios. Can you imagine a secretary typing on a virtual keyboard? A call center clerk waving at his screen while he talks to a customer? A banker shooing stock rates up and down? A programmer snipping his code into place? Cool as all that Minority Report and other stuff may seem, I have a hard time imagining anyone whose daily job today requires a keyboard to a substantial degree using some other “device” instead.</p>
<p>In the end we’ll probably see both. NUI approaches are going to spread, new devices targeted at different scenarios simply require different notions of user interaction. But they are not going to replace today’s conventional computers, they are going to be a complement, actually even a necessary one. Another necessary complement is the mutual integration with each other, the internet/cloud, and social platforms, but that’s a different story.</p>
<p>For us developers this will be the actual challenge: developing on conventional machines for devices and environments that have totally different ideas of how an application should look like and interact with its surroundings. Testing is going to be a bitch.</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p>   <a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f06%2f12%2fthe-future-of-ui%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f06%2f12%2fthe-future-of-ui%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/software-architecture/'>Software Architecture</a>, <a href='http://ajdotnet.wordpress.com/category/software-development/'>Software Development</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/773/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/773/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/773/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=773&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/06/12/the-future-of-ui/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.microsoft.com/winme/0902/1000046/Wharton_Tech_Conference_MBR.asx" length="140" type="video/asf" />
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f06%2f12%2fthe-future-of-ui%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>MCPD &#8211; Enterprise Application Developer 3.5</title>
		<link>http://ajdotnet.wordpress.com/2010/06/03/mcpd-enterprise-application-developer-3-5/</link>
		<comments>http://ajdotnet.wordpress.com/2010/06/03/mcpd-enterprise-application-developer-3-5/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 14:43:13 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=761</guid>
		<description><![CDATA[I finally managed to upgrade my MCPD/EA from .NET 2.0 to .NET 3.5. And since my last post on the topic is still requested relatively frequently, I thought an update might be due. Again, I took the upgrade exams, but since they distinguish the topics pretty well (each topic is covered in a separated section [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=761&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img style="display:inline;margin:0 0 10px 10px;" align="right" src="http://ajdotnet.files.wordpress.com/2010/06/mcpdea35.png" />I finally managed to upgrade my MCPD/EA from .NET 2.0 to .NET 3.5. And since <a href="http://ajdotnet.wordpress.com/2006/08/18/mcpd-enterprise-application-developer/" target="_blank">my last post on the topic</a> is still requested relatively frequently, I thought an update might be due.</p>
<p>Again, I took the upgrade exams, but since they distinguish the topics pretty well (each topic is covered in a separated section during the questionnaire and has to be completed before moving on to the next), the assessments should be valid for single exams as well – even if the single exams may shift emphasis somewhat.</p>
<p><strong>Logistics</strong></p>
<p>The upgrade is available to those who have the MCPD/EA on .NET 2.0. (This implies that there is no direct upgrade from the older MCSD, sorry Daniel.) </p>
<p>There are two exams that cover the ground of 5 single exams: </p>
<ul>
<li>Exam <a href="http://www.microsoft.com/learning/en/us/exam.aspx?ID=70-568&amp;locale=en-us" target="_blank">70-568</a>: UPGRADE: Transition your MCPD Enterprise Application Developer Skills to MCPD Enterprise Application Developer 3.5, Part 1 </li>
<li>Exam <a href="http://www.microsoft.com/learning/en/us/exam.aspx?ID=70-569&amp;locale=en-us" target="_blank">70-569</a>: UPGRADE: Transition your MCPD Enterprise Application Developer Skills to MCPD Enterprise Application Developer 3.5, Part 2 </li>
</ul>
<p>You can learn more about these and other upgrades <a href="http://www.microsoft.com/learning/en/us/certification/mcpd.aspx#tab3" target="_blank">here</a>.</p>
<p>Part 1 includes the following three parts and respective certifications:</p>
<ul>
<li>Microsoft Certified Technology Specialist: .NET Framework 3.5, ADO.NET Applications </li>
<li>Microsoft Certified Technology Specialist: .NET Framework 3.5, ASP.NET Applications </li>
<li>Microsoft Certified Technology Specialist: .NET Framework 3.5, Windows Forms Applications </li>
</ul>
<p>Part 2 adds another Technology Specialist part and the “Designing and Developing” part that concludes the MCPD:</p>
<ul>
<li>Microsoft Certified Technology Specialist: .NET Framework 3.5, Windows Communication Foundation Applications </li>
<li>Designing and Developing Enterprise Applications Using the Microsoft .NET Framework 3.5 </li>
</ul>
<p>All of which concludes the “Microsoft Certified Professional Developer: Enterprise Application Developer 3.5”</p>
<p>More information about single exams is available <a href="http://www.microsoft.com/learning/en/us/certification/mcpd.aspx#tab2" target="_blank">here</a>.</p>
<p><strong>The Exam Parts</strong></p>
<p>While the <a href="http://ajdotnet.wordpress.com/2006/08/18/mcpd-enterprise-application-developer/" target="_blank">last upgrade</a> included a major remapping of the certification scheme, this one is merely keeping up with technological changes. The single parts vary in the amount of change they have undergone and the degree to which they can be considered being up-to-date.</p>
<ul>
<li><strong>The ASP.NET part </strong>was no big surprise, containing additional questions for ASP.NET AJAX. I’ll call that “reasonably up-to-date”.      <br />&#160; </li>
<li><strong>The WinForms part </strong>hasn’t really changed its content at all. Hardly surprising, since WinForms itself haven’t changed. What has changed with .NET 3.5 though, is the introduction of WPF, a whole new UI technology. WPF is completely missing from the 3.5 exams. Hence, seen as <em>Windows </em>development part, this can hardly be called up-to-date.       <br />&#160;</li>
<li><strong>The ADO.NET part</strong>. Well. I would call that one “<em>un</em>reasonably up-to-date”. It is still mainly focused on DataSets in great detail. Now, I can understand that LINQ2SQL doesn’t qualify for an exam with ADO.NET Entity Framework around the corner. But still! DataSets have gone out-off-fashion even before LINQ2SQL and I really had to scratch some layers of dust from that knowledge.       <br />&#160;</li>
<li><strong>The WCF Part </strong>is probably the most advanced. This used to be the “Building Services” exam, covering remoting and WSE, but those topics are completely gone. This exam is solely focused on WCF, and you have to have a solid understanding about hosting options, configuration, and security to pass this exam.       <br />&#160;</li>
<li><strong>Designing and Developing </strong>hasn’t changed in style, but it incorporates current technologies. Unlike the respective other exams, it actually addresses WPF and ADO.NET Entity Framework as technology choices. </li>
</ul>
<p>Generally speaking, each and every of these exam parts can be solved by people with reasonable experience in the topic. That should cover ASP.NET, WinForms, and “Designing and Developing” quite nicely. Whether you put ADO.NET in that bag is up to you, but dusting the DataSet knowledge shouldn’t be a showstopper anyway. The only part that is more demanding is the WCF part. Be aware that the questions cover WCF capabilities in general; having created one or the other WCF service or reference in Visual Studio and twisted the configuration somewhat is certainly not going to get you through this exam.</p>
<p><strong>Looking Ahead</strong></p>
<p>.NET 4.0 and Visual Studio 2010 have been released weeks ago and usually it takes Microsoft about a year to prepare the next increment of certifications. So the current 3.5 certification is going to stay valuable for quite some time. Still, a little crystal ball gazing might be fun:</p>
<p>In terms of technologies, .NET 4.0 does not only contain brand new stuff, but also incorporates some technologies that have been around for some time, but not formally part of the .NET Framework. Together with the gaps noted above we have the following list of suspects:</p>
<ul>
<li>In the ADO.NET area:
<ul>
<li>LINQ 2 SQL (leaving it out so far may have been lack of time rather than a deliberate choice after all) </li>
<li>ADO.NET Entity Framework </li>
</ul>
</li>
<li>In the ASP.NET area:
<ul>
<li>ASP.NET MVC </li>
<li>ASP.NET Dynamic Data </li>
<li>perhaps jQuery </li>
</ul>
</li>
<li>In the Windows Development area:
<ul>
<li>WPF </li>
<li>Parallel Extensions (PLINQ, TPL) </li>
</ul>
</li>
<li>In the Designing and Developing area: </li>
<ul>
<li>Visual Studio Architecture features </li>
<li>Testing features       </li>
</ul>
</ul>
<p>I do hope that we will see a substitution of content in the ADO.NET area. Please Microsoft, no more DataSets! And it wouldn’t be a surprise at all if Microsoft dropped WinForms in favor of WPF, adding a little parallel stuff. ASP.NET on the other hand will certainly grow, as ASP.NET WebForms are not substituted but complemented by the new additions. The new Visual Studio features may result in in just one or the other additional question. But then, they might not, as they are not universally available.</p>
<p>Anyway, this is reasonably manageable for those people trying to keep their certificates up-to-date. For people trying to get their first certification it certainly adds up; but then, they may start with Technology Specialist or the more specific MCPD certificates and build on that.</p>
<p>What parts didn’t I mention? Silverlight is obviously missing from the list. And don’t tell me, it’s not relevant for enterprise development, for it certainly is! But I still can live with that, for it isn’t formally part of the .NET Framework and you have to draw the line somewhere. The same applies to Team Foundation Server. </p>
<p>On the other hand, how can you call yourself a certified “Enterprise Application Developer”, not knowing about TFS or Silverlight?</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://ajdotnet.wordpress.com/category/software-developers/'>Software Developers</a>, <a href='http://ajdotnet.wordpress.com/category/wcf/'>WCF</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/761/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/761/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/761/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/761/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/761/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/761/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/761/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=761&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/06/03/mcpd-enterprise-application-developer-3-5/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/06/mcpdea35.png" medium="image" />
	</item>
		<item>
		<title>Calling Amazon &#8211; Sample Code</title>
		<link>http://ajdotnet.wordpress.com/2010/05/15/calling-amazon-sample-code/</link>
		<comments>http://ajdotnet.wordpress.com/2010/05/15/calling-amazon-sample-code/#comments</comments>
		<pubDate>Sat, 15 May 2010 14:59:08 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/?p=753</guid>
		<description><![CDATA[As addition to my blog posts regarding Amazon I have extracted the respective code into a separate sample: The code can be downloaded here: AmazonSample.zip After downloading the solution (VS2010!), you need to open the appSettings.config file in the web project and provide your personal Amazon credentials. Afterwards F5 should be all you need. Calls [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=753&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As addition to my blog posts regarding Amazon I have extracted the respective code into a separate sample: </p>
<p><a href="http://ajdotnet.files.wordpress.com/2010/05/app_amazonsample.jpg" target="_amazon"><img src="http://ajdotnet.files.wordpress.com/2010/05/app_amazonsample_small.jpg" /></a> </p>
<p>The code can be downloaded here: <a title="Herunterladen" href="http://www.alexander-jung.net/download/AmazonSample.zip">AmazonSample.zip</a></p>
<p>After downloading the solution (VS2010!), you need to open the <em>appSettings.config </em>file in the web project and provide your personal Amazon credentials. Afterwards F5 should be all you need. </p>
<p>Calls via the server use a simple cache implementation that stores the XML returned from Amazon in a local directory. This way one can have a more detailed look at the information available from Amazon. This is intended for debugging purposes and to avoid flooding Amazon during development – it is not suitable for production code!</p>
<p>The related blog posts are available here:</p>
<ul>
<li><a href="http://ajdotnet.wordpress.com/2010/03/21/calling-amazon-part-1/">Calling Amazon – Part 1</a></li>
<li><a href="http://ajdotnet.wordpress.com/2010/03/25/calling-amazon-part-2/">Calling Amazon – Part 2</a></li>
</ul>
<p><font color="#008000">That’s all for now folks,     <br /><strong>AJ.NET</strong></font></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/c/'>C#</a>, <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://ajdotnet.wordpress.com/category/software-architecture/'>Software Architecture</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/753/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=753&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/05/15/calling-amazon-sample-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/05/app_amazonsample_small.jpg" medium="image" />
	</item>
		<item>
		<title>Calling Amazon &#8211; Part 2</title>
		<link>http://ajdotnet.wordpress.com/2010/03/25/calling-amazon-part-2/</link>
		<comments>http://ajdotnet.wordpress.com/2010/03/25/calling-amazon-part-2/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 19:27:51 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=747</guid>
		<description><![CDATA[The last post provided some introduction into calling an external service, namely Amazon, and spend some thoughts on the infrastructure questions. It left off with some decisions: I’m going to make REST calls, as they are more flexible than SOAP calls. I’ll make the calls to Amazon from the client. It’s important to note that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=747&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://ajdotnet.wordpress.com/2010/03/21/calling-amazon-part-1/" target="_blank">last post</a> provided some introduction into calling an external service, namely Amazon, and spend some thoughts on the infrastructure questions. It left off with some decisions:</p>
<ol>
<li>I’m going to make REST calls, as they are more flexible than SOAP calls. </li>
<li>I’ll make the calls to Amazon from the client. </li>
</ol>
<p>It’s important to note that these decisions depend to a very high degree on the particular service I’m calling. Amazon offering a policy file, the structure of the API allowing to keep the secrets on my server, the fact that Amazon actually offers REST calls in the first place. Any other service might need a completely different approach. (That’s what the last post covered.)</p>
<p>As a reminder, here is the relevant image:</p>
<p><img title="amazon_client_call" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/amazon_client_call.gif?w=708&#038;h=330&#038;h=330" width="708" height="330" /></p>
<p>So how about actually implementing that?</p>
<p><strong>The Server Part</strong>&#160;</p>
<p>The server has to build and sign the URL for the Amazon call. Implementing that is straight forward. The <em>AmazonApi</em> class maintains the Amazon configuration in the <em>appSettings.config</em>: </p>
<p><img title="Code_AmazonApi1" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/code_amazonapi1.jpg?w=632&#038;h=277" width="632" height="277" /></p>
<p>The <em>BuildItemSearchRequestUrl </em>method first calls a method to prepare the query parameters, then another method to build a respective URL:</p>
<p><img title="Code_AmazonApi2" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/code_amazonapi2.jpg?w=516&#038;h=149" width="516" height="149" /></p>
<p>The called methods are equally simple. <em>BuildRequestParams</em> translates the typed query parameters into a dictionary, adding some other necessary parameters along the way. The parameter names can be found in the <a href="http://docs.amazonwebservices.com/AWSECommerceService/2009-11-01/DG/index.html?ItemSearch.html" target="_blank">developer guide</a>: </p>
<p><img title="Code_AmazonApi3" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/code_amazonapi3.jpg?w=679&#038;h=250" width="679" height="250" /></p>
<p>In order to build the URL I need the <em>SignedRequestHelper </em>class, extracted from Amazon’s <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2480&amp;categoryID=14" target="_blank">REST sample</a>: </p>
<p><img title="Code_AmazonApi4" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/code_amazonapi4.jpg?w=522&#038;h=119" width="522" height="119" /></p>
<p>This method is made available to the client via a WCF service, but I’ll leave that one out, its straight forward and boilerplate enough. </p>
<p><strong>Calling Amazon from the Client</strong> </p>
<p>On the SL client we have a two step process: First, call the server with the filter criteria, and get the prepared URL. Second, make the call to Amazon, using the URL. The first call is no different than any other call to my own server application, no need to elaborate on that. The second one uses the <em>WebClient</em> class to make the REST call:</p>
<p><img title="Code_AmazonClientApi" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/code_amazonclientapi.jpg?w=682&#038;h=502" width="682" height="502" /></p>
<p>The <em>ParseItemSearchResponse</em> translates the XML into a respective object structure. Boilerplate, boring, and kind of longish if you do it manually.</p>
<p><strong>View Model Stuff</strong></p>
<p>Now that the details are in place, I “only” need to wire them into the UI. </p>
<p>The calls from the SL client to its housing server application are straight forward. First, call the server with the filter criteria, and get the prepared URL. Second, make the call to Amazon, using the URL. First the bookkeeping:</p>
<p><img title="Code_AmazonVM1" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/code_amazonvm1.jpg?w=580&#038;h=333" width="580" height="333" /></p>
<p>The <em>BuildItemSearchRequestUrlCall </em>class encapsulates the calls to the <em>BuildItemSearchRequestUrl</em> service operation shown earlier, <em>AmazonClientApi </em>does the same for Amazon and is also shown above.</p>
<p>Now the actual implementation, kind of leapfrogging from one method to the next by way of asynchronous events and lambdas I pass in for that purpose:</p>
<p><img title="Code_AmazonVM2" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/code_amazonvm2.jpg?w=667&#038;h=505" width="667" height="505" /></p>
<p>That should get the first 10 results from Amazon – and the proof that I can actually make the call:</p>
<p><img title="app_amazonsearchsimple" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/app_amazonsearchsimple.jpg?w=732&#038;h=474" width="732" height="474" /></p>
<p>The <em>ShowAmazonResponseErrors</em> simply iterates over the returned error collection and shows a respective message box. Amazon will return an error if it couldn’t find anything:</p>
<p><img title="App_NothingFound" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/app_nothingfound.jpg?w=587&#038;h=131" width="587" height="131" /></p>
<p>I have now solved the basic technical demands, yet the user may be a little more demanding, since&#8230; </p>
<p><strong>Employing Paging</strong></p>
<p>… 10 items is usually not sufficient. Hence I need to make more calls, read paging. Paging technically only requires an <em>ItemPage </em>parameter to be set to a value bigger than 1 (the page index is 1-based). However on the view model, some additional questions arise. </p>
<p>First question is whether the subsequent pages should be loaded right away, constantly filling the result grid in the background. This could be done by triggering the next call, once the previous one has returned, until all available results have arrived. <em>Leapfrogging in a loop. </em>Of course, if the user triggered a new search somewhen in-between, I would have to cancel that chain of calls. Or I could let the user trigger the loading explicitly, e.g. with some „load more“ button (which is what I’ll do). </p>
<p>In any case I have to deal with the user changing the filter criteria or interacting with the result, e.g. resorting it. This is obvious for the second case, but even automatically loading all data in chunks takes time. </p>
<p>Therefore I need to distinguish between the first call, and subsequent calls. The first call initiates a new search, replacing any previous search result. Subsequent calls have to use the same filter criteria, just with another page, and the result is appended to the previous ones. Now, if the filter criteria is bound to the UI <i>and</i> used as parameter to the service call, the user might change the filter and then click the „load more“ button (or the automatic loading might kick off at that time). To prevent that I need a copy of my request property. Similarly I need to maintain my result in a separate property, otherwise the call would overwrite any previous result data. </p>
<p><em>BeginSearchAmazon </em>and <em>EndSearchAmazon</em> now only handle the first call, initiating a new search, and have to be changed accordingly:</p>
<p><img title="Code_AmazonVM3" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/code_amazonvm3.jpg?w=537&#038;h=395" width="537" height="395" /></p>
<p>The chain for subsequent calls looks similar in structure, but preserves the values in the separate copy properties:</p>
<p><img title="Code_AmazonVM4" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/code_amazonvm4.jpg?w=696&#038;h=472" width="696" height="472" /></p>
<p>The next image shows the dialog after having loaded 3 pages and in the process of loading the fourth:&#160; </p>
<p><img title="app_amazonsearch" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/app_amazonsearch.jpg?w=757&#038;h=487" width="757" height="487" /></p>
<p>Great? By the way, the details link jumps straight to Amazon, showing the respective book.</p>
<p><strong>Roundup</strong></p>
<p>Whether you are going to call Amazon or some other external service, these two posts should give you some hints on what to take into account form the infrastructure and architectural perspective. On the client you’ll have to look into Silverlight security and cross domain calls, on the server you might run into firewall or proxy authentication issues. </p>
<p>Also the Amazon API with its approach to paging may give you some hints on how to implement paging over larger result sets with Silverlight. While server calls are asynchronous, SL doesn’t provide the option of processing results <i>while</i> they arrive. For a large result set it might take some time to download the data, and the user might notice the time lag. It could be the better user experience to load the data in chunks, as shown here.</p>
<p>One hint at last: Jon Galloway has a good explanation on the rationale behind policy files on the called server, see <a href="http://weblogs.asp.net/jgalloway/archive/2008/12/12/silverlight-crossdomain-access-workarounds.aspx" target="_blank">here</a>.</p>
<p><font color="#008000">That’s all for now folks, <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f03%2f25%2fcalling-amazon-part-2%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f03%2f25%2fcalling-amazon-part-2%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/c/'>C#</a>, <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://ajdotnet.wordpress.com/category/software-architecture/'>Software Architecture</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/747/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=747&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/03/25/calling-amazon-part-2/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/amazon_client_call.gif?w=708&#38;h=330" medium="image">
			<media:title type="html">amazon_client_call</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/code_amazonapi1.jpg?w=632" medium="image">
			<media:title type="html">Code_AmazonApi1</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/code_amazonapi2.jpg?w=516" medium="image">
			<media:title type="html">Code_AmazonApi2</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/code_amazonapi3.jpg?w=679" medium="image">
			<media:title type="html">Code_AmazonApi3</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/code_amazonapi4.jpg?w=522" medium="image">
			<media:title type="html">Code_AmazonApi4</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/code_amazonclientapi.jpg?w=682" medium="image">
			<media:title type="html">Code_AmazonClientApi</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/code_amazonvm1.jpg?w=580" medium="image">
			<media:title type="html">Code_AmazonVM1</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/code_amazonvm2.jpg?w=667" medium="image">
			<media:title type="html">Code_AmazonVM2</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/app_amazonsearchsimple.jpg?w=732" medium="image">
			<media:title type="html">app_amazonsearchsimple</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/app_nothingfound.jpg?w=587" medium="image">
			<media:title type="html">App_NothingFound</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/code_amazonvm3.jpg?w=537" medium="image">
			<media:title type="html">Code_AmazonVM3</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/code_amazonvm4.jpg?w=696" medium="image">
			<media:title type="html">Code_AmazonVM4</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/app_amazonsearch.jpg?w=757" medium="image">
			<media:title type="html">app_amazonsearch</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f03%2f25%2fcalling-amazon-part-2%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Calling Amazon &#8211; Part 1</title>
		<link>http://ajdotnet.wordpress.com/2010/03/21/calling-amazon-part-1/</link>
		<comments>http://ajdotnet.wordpress.com/2010/03/21/calling-amazon-part-1/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 16:57:59 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=717</guid>
		<description><![CDATA[Connectivity is one of the promises of Silverlight. And what better target for my bookshelf application than Amazon? So I decided the book lists could come with the book cover image, and creating new catalogue entries can be streamlined using Amazon search. And while this is about Amazon, the thoughts should give you some hints [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=717&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Connectivity is one of the promises of Silverlight. And what better target for my bookshelf application than Amazon? So I decided the book lists could come with the book cover image, and creating new catalogue entries can be streamlined using Amazon search. And while this is about Amazon, the thoughts should give you some hints on what to consider for other calls to external services as well.</p>
<blockquote><p>Note: This post will dig into the Amazon API and some general infrastructure questions. Actually implementing this will be the topic of the next post.</p>
</blockquote>
<p><strong>The Preconditions</strong></p>
<p>Amazon isn’t exactly forthcoming with its product catalogue API. Starting at <a title="http://aws.amazon.com/" href="http://aws.amazon.com/" target="_blank">http://aws.amazon.com/</a> points to about any Amazon service offering there is — except the product catalogue API. Well, some <a href="http://www.bing.com" target="_blank">bings</a> later, by way of other articles and blog posts, and once you know that the correct name is „Product Advertising API“, you’ll find the <a href="https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html" target="_blank">entry point</a>. From there it is reasonably <a href="http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=5" target="_blank">well documented</a>. </p>
<p>First thing is to register oneself as developer. This will result in various information, one can pick up on his user profile page: </p>
<ul>
<li>The <em>AWS Account ID </em>is the user ID </li>
<li>A variable number of&#160; pairs of an <em>AWS Access Key ID </em>and the respective <em>AWS Secret Access Key </em>itself. You need one for the REST API. </li>
<li>A variable number of X.509 certificates, one of which you need to make secure SOAP requests. </li>
</ul>
<p><strong>Understanding the API</strong></p>
<p>As a quick guide to the documentation: The entry to documentation is <a href="http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=5" target="_blank">here</a>. Under “Documentation Archive” you can pick the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=3426&amp;categoryID=19" target="_blank">latest version</a> of the <a href="http://docs.amazonwebservices.com/AWSECommerceService/2009-10-01/GSG/" target="_blank">Getting Started Guide</a> and the <a href="http://docs.amazonwebservices.com/AWSECommerceService/2009-11-01/DG/" target="_blank">Developer Guide</a>. </p>
<p>The logical next step is to find some samples, get them working and understand the details of calling Amazon. There is one <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2480&amp;categoryID=14" target="_blank">sample using the REST API</a>, and <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2481&amp;categoryID=14" target="_blank">one for SOAP</a> using&#8230; WSE?. <em>Well. WCF is actually quite new and since almost everyone is still using WSE, why update&#8230; </em>. Anyway, the example is simple to migrate – and it doesn’t work at all, could never work actually, since it doesn’t address security. </p>
<blockquote><p>You can find descriptions on how to get security for SOAP calls working <a href="http://docs.amazonwebservices.com/AWSECommerceService/2009-11-01/DG/SOAP_SOAPAuth.html" target="_blank">here</a>. I never checked that out, though (I ended up using the REST API, see below), and I couldn’t find any samples using WCF.</p>
</blockquote>
<p>The REST API is used by putting parameters in a dictionary, supplementing the user information, and letting a helper class (<em>SignedRequestHelper.cs</em>) produce a URL. The respective request with that URL will return <a href="http://docs.amazonwebservices.com/AWSECommerceService/2009-11-01/DG/AnatomyofaResponse.html" target="_blank">some XML</a>, one has to parse. </p>
<blockquote><p>You’ll need that helper class; unfortunately it is, again, not that easy to find, as most links will lead you the <a href="http://associates-amazon.s3.amazonaws.com/signed-requests/helper/index.html" target="_blank">online test page</a>, not the download. You could even download that page <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2609&amp;categoryID=14" target="_blank">here</a>. But I never found a download for the class by itself and ended up extracting it form the example named above.</p>
</blockquote>
<p>The WSDL is also <a href="http://docs.amazonwebservices.com/AWSECommerceService/2009-11-01/DG/WSDLLocation.html" target="_blank">available</a> and can be used to create a WCF client. Even if you employ the REST API, the data classes from the WCF client may help you parsing the returned XML. </p>
<p>The API itself is simple and straight forward. You send some query parameters and you get some result. The query parameters include the operation, and the operation determines the valid set of other parameters. The operation I’m going to be interested in is <em><a href="http://docs.amazonwebservices.com/AWSECommerceService/2009-11-01/DG/ItemSearch.html" target="_blank">ItemSearch</a></em>. </p>
<p>The query parameters also include the <em>ResponseGroup</em> parameter that describes <a href="http://docs.amazonwebservices.com/AWSECommerceService/2009-10-01/DG/CHAP_ResponseGroupsList.html" target="_blank">what kind of output I would like</a>. Amazon doesn’t return each and every detail about, say, any book in a book search result. It returns just some major fields like title, detail URL, etc. by default. One could use this information to populate a search result list and load the book details on demand, thus relieving Amazon from doing too much unnecessary work in the first place (and reducing network load). But in cases where more information is needed right away, one can tell Amazon to include other sets of information, like images, in the returned search result.</p>
<p>Another parameter is <em>ItemPage</em> for the partition of results. Amazon returns 10 items with each search request, and no way to change that value. To get the next 10 values, one has to make separate calls for page 2, 3, and so on, 400 at most. </p>
<p><strong>The Infrastructure Question</strong> </p>
<p>Now there are a few choices to make (or rather to rule out). We have the REST and the SOAP API at our disposal, and we can make the call from our server, or from our Silverlight client. Note also that the REST call can be split into two independent parts: building the URL (which includes signing), and making the actual call against Amazon. In theory this leads to the following options: </p>
<ol>
<li>SOAP call from the server </li>
<li>SOAP call from the Silverlight client </li>
<li>REST URL built at the server, call made from the server </li>
<li>REST URL built at the server, call made from the SL client </li>
<li>REST URL built at the Silverlight client, call made from the SL client </li>
</ol>
<p>What are the forces restricting these options? </p>
<ul>
<li>One restriction is that I‘m not going to send my private Amazon secret key or certificate – <em>my eyes only, signed with the blood of a black cat killed on full moon on the grave of a convicted murderer </em>– to the Silverlight client. It’s not that I don’t trust you&#8230; Well, it is, and I don’t. That invalidates option 2 and 5. </li>
<li>Another possible restriction is the server infrastructure. Depending on proxy or firewall configuration, you cannot call outbound from your server to the internet. In case of a proxy it might be possible, but it‘d take unreasonable effort. That puts at least a question mark behind options 1 and 3. </li>
</ul>
<blockquote><p>Regarding proxy authentication: ASP.NET applications (including .asmx services) have the <a href="http://msdn.microsoft.com/en-us/library/system.net.credentialcache.defaultnetworkcredentials.aspx" target="_blank">CredentialCache.DefaultNetworkCredentials</a> property to get the current user’s credentials to pass on. WCF services don’t have that option which makes it unreasonably hard to make the subsequent call using the current user’s security context. <em>Tell me if I’m missing something!</em>&#160;</p>
</blockquote>
<ul>
<li>To make the picture complete: Our SL client is also subject to security restrictions. The called service has to explicitly allow the call from our client, offering a <a href="http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx" target="_blank">policy file</a>. Fortunately Amazon does that, so this won’t be an issue for now. If you are planning on using other services, make sure to check this out, for this puts a block on the call form the client. </li>
</ul>
<blockquote><p>Note: I‘d like to stress the fact that it is the providing service, Amazon in this case, who has to opt in for client calls. There is nothing that can be done on the client side about it. This is quite a common misconception…</p>
</blockquote>
<p>The corrected list of options: </p>
<ol>
<li>(SOAP call from the server) </li>
<li><strike>SOAP call from the Silverlight client</strike> </li>
<li>(REST URL built at the server, call made from the server) </li>
<li><u>REST URL built at the server, call made from the SL client</u> </li>
<li><strike>REST URL built at the Silverlight client, call made from the SL client</strike> </li>
</ol>
<p>Since the REST API offers client side calls (option 4) and still leaves the option of making server calls (option 3), the SOAP option never came up again. I actually started with server calls. </p>
<p><strong>Calling Amazon from the Server</strong> </p>
<p>In this scenario all security related issues are the server’s problem:</p>
<p>The client passes the filter criteria to the server, the server creates a signed URL, invokes the REST call, parses the XML, and returns the result. The call from the server to Amazon may have to go through proxies, firewalls, or other intermediaries.</p>
<p><img title="amazon_server_call" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/amazon_server_call.gif?w=597&#038;h=342" width="597" height="342" /></p>
<p>Doing the work on the server had certain advantages: It was easy to implement, I could use unit tests, I added some persistent caching in files (actually to avoid flooding Amazon with my debug calls, but caching would of course improve multiple clients). Also in this scenario the server does the job of parsing the returned XML into decent entities, and only those are returned to the client, which may be a factor depending in the WAN structure. </p>
<p><strong>Calling Amazon from the Client</strong> </p>
<p>In this scenario the client still calls the server, but rather than making the call to Amazon, the server just builds the signed URL and hands it back to the client. The client calls Amazon and it also has to parse the resulting XML. </p>
<p><img title="amazon_client_call" alt="" src="http://ajdotnet.files.wordpress.com/2010/03/amazon_client_call.gif?w=708&#038;h=330" width="708" height="330" /></p>
<p>Calling the service from the client is only possible if the called serve permits it (as Amazon does). And if it does, it is more fragile as one cannot always foresee under which circumstance the code will run. If something goes wrong, the chances of getting diagnostics information are bad. </p>
<p>On the other hand the proxy issue is nicely circumvented and in case you have to support different authentication schemes, say openID, you may be better off telling the user that you cannot record his credential information on the server if the server never sees it.</p>
<blockquote><p>Initially I implemented the client side call more out of curiosity, to evaluate the implications. But when I eventually did run into the proxy issue, I only had to switch my view model to get it working again. </p>
</blockquote>
<p><strong>Calling What from Where?</strong></p>
<p>I’d like to stress that point: The decision whether to call the external service from my own server or from the client is extremely depended on very different influences: Infrastructure, security related, available API, did the service opt in to client calls, etc.. The decision may consequently be completely different in other cases. It may even be the case that there is no simple solution. For example, had Amazon neglected to opt in for client calls (the policy file), I would have been forced to make the call form the server. Had I then run into the proxy or some other firewall issue I would have had some hard tasks to face.</p>
<blockquote><p>There may be some workarounds, like falling back to .asmx for the credentials or some browser script workaround – but none is especially nice.</p>
</blockquote>
<p>Anyway, since in my case I have a working approach, I can now set out to actually implementing it. <em>Next post…</em></p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f03%2f21%2fcalling-amazon-part-1%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f03%2f21%2fcalling-amazon-part-1%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://ajdotnet.wordpress.com/category/software-architecture/'>Software Architecture</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/717/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/717/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/717/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/717/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/717/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/717/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/717/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/717/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/717/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/717/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/717/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/717/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/717/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/717/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=717&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/03/21/calling-amazon-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/amazon_server_call.gif" medium="image">
			<media:title type="html">amazon_server_call</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/03/amazon_client_call.gif" medium="image">
			<media:title type="html">amazon_client_call</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f03%2f21%2fcalling-amazon-part-1%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Understanding Validation in Silverlight</title>
		<link>http://ajdotnet.wordpress.com/2010/02/28/understanding-validation-in-silverlight/</link>
		<comments>http://ajdotnet.wordpress.com/2010/02/28/understanding-validation-in-silverlight/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 13:51:18 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=712</guid>
		<description><![CDATA[Input validation is necessary in every business application. Time to look into validation with Silverlight. Starting a little internet research will reveal two variations: Putting validation code into property setters, throwing exceptions (covered by Jesse Liberty). Decorating properties with validation attributes, either checked by the data grid, or manually, again eventually based on exceptions (see [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=712&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Input validation is necessary in every business application. Time to look into validation with Silverlight.</p>
<p>Starting a little internet research will reveal two variations:</p>
<ul>
<li>Putting validation code into property setters, throwing exceptions (<a href="http://blogs.silverlight.net/blogs/jesseliberty/archive/2009/06/05/silverlight-validation-in-detail.aspx" target="_blank">covered by Jesse Liberty</a>). </li>
<li>Decorating properties with validation attributes, either checked by the data grid, or manually, again eventually based on exceptions (see <a href="http://msdn.microsoft.com/en-us/library/dd901590(VS.95).aspx" target="_blank">MSDN</a>). </li>
</ul>
<p>OK, obviously you don’t need me to repeat what has been described by others in sufficient detail. </p>
<p>However, neither the property setter approach, nor validation attributes work well with code generated classes (which are employed <a href="http://ajdotnet.wordpress.com/2010/01/01/excursus-supervising-controller-pattern/" target="_blank">quite regularly with SL</a>). Would property changed event handler solve that? How do value converters fit into the picture? What about mutual dependent properties? Null values? Actually, there’s no overall concept that would help answer these questions. </p>
<blockquote><p>Note: <a href="http://msdn.microsoft.com/en-us/library/ee707344(VS.91).aspx" target="_blank">WCF RIA Services</a> (see also <a href="http://silverlight.net/getstarted/riaservices/" target="_blank">here</a>; formerly known as <a href="http://blogs.msdn.com/brada/archive/2009/11/18/welcome-to-wcf-ria-services-beta.aspx" target="_blank">RIA Services</a>) addresses the „generated code“ issue by copying the validation from the server to the client. However I refrain from using WCF Services in this learning experience, since the aim is to understand what’s going on under the hood. Additionally I can easily envision cases in which I may want different (i.e. more restricting) validations on the frontend than on the server.</p>
</blockquote>
<p><strong>Defining “Validation”</strong></p>
<p>Let’s clarify what we are talking about. Validation (more to the point, input validation) deals with checking some user input, however it is made, against, let’s call it <em>syntactical</em> and <em>semantical</em> rules. Syntactical rules include all that is necessary to satisfy the type of the backing data, e.g. ensuring the string actually is a valid time (provided the property is of type <em>DateTime</em>). Semantical rules deal with additional restrictions, usually business related, say whether some value is in a certain range.</p>
<blockquote><p>Note: Validation always happens <em>after </em>the user has made his input, making sure the input was correct. The alternative approach (though not always feasible) is to let him only make valid input in the first place, e.g. with date pickers, numeric up/down, or masked edit boxes. This renders at least the need for syntactic validation obsolete, semantic validation may or may not be covered. Still, it may provide the better user experience.</p>
</blockquote>
<p>Syntactic rules are usually enforced implicitly during the actual conversion. The need for a conversion depends on what data the control actually provides (e.g. a date picker control supplies a <em>DateTime </em>ready to use, no need for validation in this case). In other cases syntactic validation is covered by the databinding mechanism of Silverlight. </p>
<p>Semantical rules are up to the developer. </p>
<p>There’s another difference between syntactic and semantic validation: Syntactic validation <em>has </em>to occur <i>before</i> changing the data (since it’s a precondition to a successful type conversion), thus it is also tied to the UI and the databinding process. Semantic validation on the other hand can also happen <em>after</em> the data has already been changed. And it doesn’t have to happen in the UI either. Matter of fact, some validations may not even be possible in the UI, but have to be enforced by the business logic or even the database. Heck, they may happen out-of-band at any time, say by asking some other system asynchronously. </p>
<blockquote><p>Note: Within my Silverlight UI I don’t care who actually does the validation, but the fact that it may happen outside of the usual sequence (databinding, triggered by some user input) is important.</p>
</blockquote>
<p>Typical use cases for validation include:</p>
<p><em>syntactic validation      <br /></em>A) ensuring a string represents a certain type (numeric, date,&#8230;) </p>
<p><em>semantic validation      <br /></em>B) ensuring some input, i.e. required fields     <br />C) ensuring a certain text length     <br />D) ensuring a value matches some criterion (range check, regular expression, date in the future, etc.) </p>
<p><em>special cases      <br /></em>E) mutually dependent fields (mutual exclusion, value dependencies, etc.)     <br />F) distinguishing between input and no input (i.e. null values)</p>
<p><strong>Validation “mechanics” in SL </strong></p>
<p>Validation is tied to <a href="http://msdn.microsoft.com/en-us/library/cc278072(VS.95).aspx" target="_blank">data binding</a> and to get it working the binding properties have to be set respectively:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2010/02/xaml_textbox.jpg" /></p>
<p>Now let’s take a closer look at the data binding process. Here’s a (somewhat simplified) sequence diagram of the relevant code for validation, after a control changed its value. Basically it all depends on exceptions:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2010/02/validation.jpg?w=799&#038;h=672" width="799" height="672" /></p>
<p>(Note: this is not entirely correct regarding the exception handling, but is conveys the actual meaning better.)</p>
<p>Let’s go over the locations I numbered:</p>
<p>1: The <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter(VS.95).aspx" target="_blank">value converter</a> you could declare in the binding expression is called – yet it does not take part in the validation handling. Meaning, any exception thrown here won’t appear as validation error, but as actual application error. This renders value converters useless in cases that need syntactic validation (like use case A).</p>
<p>2: Right after the value converter, a <em>try</em> marks the area in which every exception will be treated as validation error. </p>
<blockquote><p>Personally I don’t understand why the value converters have been left out of this area (seems to be a conscious decision). They would have offered some easy to use validation mechanism&#8230;</p>
</blockquote>
<p>3: The type converter of the property&#8217;s type is called, which translates the value from the type passed in by the control (a textbox passes a string, other controls may pass in other types) to the target type, say <em>Int32</em>. Exceptions thrown here will show up as something like „Input string was not in a correct format.“, and of course the property retains its original value. Hence the type converter does syntactic validation (use case A). There’s however no feasibly way to customize the conversion, like what a value converter could do.</p>
<blockquote><p>Personally I don’t understand why the value converters&#8230; . <em>Ah, said that already, didn’t I?</em></p>
</blockquote>
<p>4: The property value is set, and in turn ticks off any validation code put in the property setter for semantic validation. The samples on the internet usually have the validation code <i>before</i> actually changing the property value, thus the property still retains its original value in case of a validation error, read exception. Anyway, use cases B (ignoring null values for the moment), C, and D are covered here.</p>
<p>5: The setter will also raise the <em>PropertyChangedEvent</em>, and in turn any exception thrown in a respective handler will also take part in the validation handling. However if we get that far, the property now has the invalid data already set. Still, this may be another location for use cases B, C, and D.</p>
<p>6: Any validation error is announced to the control via the <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.bindingvalidationerror(VS.95).aspx" target="_blank">BindingValidationError</a> </em>event. Many controls have an error state and will show a red border and an error tooltip. Alternatively there is a <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.validationsummary(VS.95).aspx" target="_blank">ValidationSummary</a></em> control that takes care of presenting the feedback:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2010/02/app_validation_error.jpg" /></p>
<p>7: Finally there’s some missing parts in the sequence diagram:</p>
<ul>
<li>The databinding mechanism doesn’t check the validation attributes, so who does? The <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid(VS.95).aspx" target="_blank"><em>DataGrid</em></a> is the only control that actively validates the row in edit mode, but one can <a href="http://msdn.microsoft.com/en-us/library/dd901590(VS.95).aspx" target="_blank">trigger the validation himself</a>.       <br />If done before writing the data, this approach bypasses any value and type conversion (another reason why value converters have no part in validation). Theoretically one could validate a property this way without setting the values at all. However due to the type conversion issue, the only sensible approach is validate afterwards (which is what the <em>DataGrid</em> does), and let the data binding mechanism care about conversions. This way one could trigger that validation generically in the <em>PropertyChanged </em>event handler. </li>
<li>Nobody cares about errors (exceptions) in property setters and event handlers (point 4 and 5) <em>outside </em>of this sequence. Meaning any other code manipulation the properties and causing an exception will tear the whole application down. </li>
</ul>
<p>As a corollary: Validation works one binding at a time. This implies that mutually dependent properties (use case E) are not part of the equation. If property X caused an error that may be fixed by changing property Y, SL doesn’t help. One can work around this (by a combination of UI design and simulated <em>PropertyChanged</em> events), but it’s ugly work.</p>
<p>I left out use case F (null values) so far: Data intensive applications may have to distinguish between no entry (empty string, null value) and the 0-value for the data type (e.g. „0“, „00:00“). The data type of the property would be a nullable value type, e.g. Nullable&lt;Int32&gt; or Nullable&lt;DateTime&gt;. The sad part: Type converters don’t handle null values, neither does some other part of the data binding mechanism. nullable types are treated like their non-nullable counterpart, thus no empty strings are allowed, worse, an empty string even usually causes an exception, thus validation error. The best way to solve this is a separate property of type string that handles null and 0 representation and does the type conversion. However it takes some effort to keep those two properties in sync and propagate <em>PropertyChanged </em>events of the other property.</p>
<p><strong>Consequences &amp; Conclusions</strong></p>
<p>Now that the input validation mechanism is understood (I hope), I can draw some conclusions:</p>
<p><em>To set or not to set&#8230;</em></p>
<p>There is some inconsistency between whether an invalid value will actually be set in the data property or not: Type converter (syntactic validation) and property setter issues (semantic validation) generally leave the value as is. Validations in property changed notifications &#8211; including validation attributes if implemented that way &#8211; (also semantic validations) will set the property to the invalid value and notify only afterwards. This in turn means that our view model logic has to take the validity of the data into account, i.e. a save button should check some kind of <em>IsValid </em>property on the model.</p>
<p><em>To throw or not to throw&#8230;</em></p>
<p>In SL3 the validation mechanism relies on exceptions. Adverse effect is that the first validation error hides subsequent errors, which may obscure the feedback for the user. Secondly this code is also present when I set the properties from code, with no data binding infrastructure readily available to catch the exceptions. Hence I have to be very careful, or some innocent code may take my whole application down.</p>
<p><em>To depend or not to depend&#8230;</em></p>
<p>Validation in SL3 doesn’t cover mutually dependent properties properly. Some nasty stunts and compromises may get you a working solution, but it hurts to write that code (been there, done that!).</p>
<p>Anyway, with SL4 around the corner (see below) I‘d refrain from putting too much effort into this issue right now. </p>
<p><em>To convert or not to convert&#8230;</em></p>
<p>As said before, value converters do not exactly work with validation, at least if the conversion itself may fail. Thus I’d refrain from using them altogether in case validation is also needed. I’d rather put the conversion logic into „shadow properties“, i.e. properties that replace/complement the original property, changing only the property type (usually to string). Another reason for these shadow properties would be the null/0 issue mentioned above.</p>
<p>To keep these two properties connected and synchronized takes some effort. For example if one property changes, the other should raise the <em>PropertyChanged</em> event as well. </p>
<p><strong>Silverlight 4</strong></p>
<p>With SL4 we’ll get <em>IDataErrorInfo </em>and <em>INotifyDataErrorInfo </em>for asynchronous validation, as <a href="http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx#idataerrorinfo" target="_blank">announced by Tim Heuer</a>, and described <a href="http://weblogs.asp.net/fredriknormen/archive/2009/11/22/silverlight-4-and-asynchronous-validation-with-inotifydataerrorinfo.aspx" target="_blank">in more detail by Fredrik Normén</a>. </p>
<p>Contrary to SL3 this isn’t tied to exceptions any more. This will change the picture completely:</p>
<ul>
<li>The first validation error won’t necessarily prevent other validations </li>
<li>Other code setting the value (outside of databinding) won’t have to deal with exceptions (and still partake in validation). </li>
<li>Asynchronous validation is covered. </li>
<li>Mutual dependencies can be addressed. </li>
</ul>
<p>The one notable gap is the still missing <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.metadatatypeattribute.aspx" target="_blank"><em>MetadataTypAttribute</em></a><em> </em>that would enable the usage of validation attributes for code generated classes. The only other aspect not covered is the null values and value converter issue. But strictly speaking this is more an issue of type conversion than of the validation itself. (Still a pesky issue.)</p>
<blockquote><p>If SL4 changes nearly everything, then why this post in the first place? Well, apart from the fact that existing code doesn’t migrate itself, while the contents presented here are less relevant, they are still valid.</p>
</blockquote>
<p><strong>Final Verdict</strong></p>
<p>With SL3 I’d say about 80% of my validation demands are covered. But as always, the remaining 20% don’t appear all that often, but if they do, it hurts.</p>
<p>Looking ahead, SL4 will provide a better foundation for validation, and solve some issues — yet it still won’t cover every aspect. Still, having looked at SL4 may give some hints on what to implement today for SL3 (and what not), with a clean migration path to SL4.</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f02%2f28%2funderstanding-validation-in-silverlight%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f02%2f28%2funderstanding-validation-in-silverlight%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Filed under: <a href='http://ajdotnet.wordpress.com/category/net/'>.NET</a>, <a href='http://ajdotnet.wordpress.com/category/net-framework/'>.NET Framework</a>, <a href='http://ajdotnet.wordpress.com/category/silverlight/'>Silverlight</a>, <a href='http://ajdotnet.wordpress.com/category/software-architecture/'>Software Architecture</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/712/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=712&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/02/28/understanding-validation-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/02/xaml_textbox.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2010/02/validation.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2010/02/app_validation_error.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f02%2f28%2funderstanding-validation-in-silverlight%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Bits&amp;Pieces: The First Steps with Visual State Manager</title>
		<link>http://ajdotnet.wordpress.com/2010/01/24/silverlight-bitspieces-the-first-steps-with-visual-state-manager/</link>
		<comments>http://ajdotnet.wordpress.com/2010/01/24/silverlight-bitspieces-the-first-steps-with-visual-state-manager/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 15:41:20 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=702</guid>
		<description><![CDATA[Visual State Manager. Easy to understand in principle. But it takes some getting used to to be able to use it&#8230; . There is a lot of information about VSM available, e.g. a quick introduction at silverlight.net, and when I first started to tackle VSM I read it all and then some (felt that way, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=702&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Visual State Manager. Easy to understand in principle. But it takes some getting used to to be able to use it&#8230; .</p>
<p>There is a lot of information about VSM available, e.g. a quick introduction at <a href="http://www.silverlight.net/learn/tutorials/stylestemplatesvsm-cs/" target="_blank">silverlight.net</a>, and when I first started to tackle VSM I read it all and then some (felt that way, anyway). Still, my first experiments with VSM failed miserably—and it did so because of a lack of understanding. Because the one main issue for me was that all the articles and screencasts explained what the VSM does and what great effects one (well, someone else) could achieve with it, yet all with the emphasis on ‚what‘ (and usually all at once), not on ‚how‘ (in small digestible chunks).</p>
<p>So, if you have looked into VSM and didn’t quite get it, but only just, then this post may be for you. First I‘m going to dive into some code, afterwards I’ll try to offer a few hints that should help you getting started with VSM.</p>
<p><strong>The Crash Course</strong></p>
<p>Controls have <em>states </em>(like normal, pressed, focused, for a button); states are represented by VSM as <u>Visual States</u>, organized in distinct <u>State Groups</u>. State Groups separate mutually independent Visual States (e.g. pressed state or mouse over are independent of the focus state). Silverlight allows to define these states in templates, along with <u>State Transitions</u> that define how the state change is to happen (e.g. instant change or some animation).</p>
<p>Silverlight also provides an attribute, namely <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.templatevisualstateattribute(VS.95).aspx" target="_blank">TemplateVisualStateAttribute</a></em>, to declare the supported Visual States and Groups on a control. Keep in mind however that this is merely for tool support and perhaps documentation. At runtime, the presence or absence of these attributes is of no consequence at all.</p>
<p><strong>The Sample</strong></p>
<p>OK, let’s see some code. I’ll build on the image button from <a href="http://ajdotnet.wordpress.com/2010/01/17/silverlight-bitspieces-derived-custom-controls/" target="_blank">my last post</a>. It should support three different images, as well as a focused rectangle. (I’ll leave out the text though. I don’t need it and it would complicate matters for this post without gain.) The button class <a href="http://msdn.microsoft.com/de-de/library/system.windows.controls.button(VS.95).aspx" target="_blank">already defines</a> the Visual States and Groups, I’ll stick with that.</p>
<p>First I extended the image button control class to support three dependency properties, namely <em>NormalImage</em>, <em>HooverImage</em>, and <em>DisabledImage</em>. (I could have added a ClickedImage, but I‘ll solve that otherwise.) To make a long story short, here is the custom class, defining the necessary dependency properties:</p>
<p><img title="code_imagebutton" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/code_imagebutton.jpg?w=718&#038;h=484" width="718" height="484" /></p>
<p>The button inherits the VSM attributes from its base class, thus I don’t have to reiterate them here. </p>
<p>Having done that I can already use these properties to set them in XAML:</p>
<p><img title="xaml_imagebutton" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/xaml_imagebutton1.jpg?w=616&#038;h=92" width="616" height="92" /></p>
<p>Of course it still uses only the one image, I gave it last time. So, the next step is to extend the template with images, and other parts, to accommodate the Visual Styles. If I can live with XAML, I could do this using Visual Studio 2008. To do it in a design view I need Visual Studio 2010 or Blend.</p>
<blockquote><p>In any case, this is conventional designing, it’s not yet time to look in blend at the “States” panel in Blend! And when it comes to this, VS2010 is also out of the game (at least in beta 2).</p>
</blockquote>
<p> The resulting XAML looks somewhat like that:</p>
<p><img title="xaml_template1" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/xaml_template1.jpg?w=750&#038;h=379" width="750" height="379" /></p>
<p>Note that I used a Grid to stack the images on top of each other. Note also that the default settings for all parts are compliant with my „normal“ button state, i.e. the second and third image are invisible, so is the focus rectangle.</p>
<p>Now that my control contains all the primitives I need, it’s time to enter VSM. To prepare for that, I manually provided the State Groups and Visual States. This ensures that I get all states (Blend would only add the ones it manipulates, and since the normal state is going to be empty, it would always be missing), and in the order I prefer.</p>
<p><img title="xaml_template2" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/xaml_template2.jpg?w=613&#038;h=274" width="613" height="274" /></p>
<p>Now is the time to enter blend, select the button, then the current template, and have a look at the “States” pane.</p>
<p><img title="blend_states1" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/blend_states1.jpg?w=607&#038;h=330" width="607" height="330" /></p>
<p>Note that the “States” pane contains the State Groups with their respective Visual States. Blend gets this information from the <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.templatevisualstateattribute(VS.95).aspx" target="_blank">TemplateVisualStateAttribute</a></em> on the class, but also includes additional states and groups it finds in the template XAML. Additionally there is a “pseudo-state” named “Base”, which is simply the “state” in which the control is without putting it in a distinct state.</p>
<p>Now I went ahead, selected the state in question in Blend and changed the controls to match my design. Since I had the desired design figured out before I started the VSM – up to which properties to change for a transition – this was as simple as can be. For the mouse over state:</p>
<p><img title="blend_states2" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/blend_states2.jpg?w=862&#038;h=576" width="862" height="576" /></p>
<p>Note how Blend shows the design area with a red border and a “recording mode” sign. Every change to the template is now recorded as state change for the selected state, mouse over in this case. (You could switch recording off by clicking on the red dot in the upper left, and manipulate the properties ordinarily; yet selecting another state will switch it back on, so this is OK for some quick fixes, but too error prone for general editing.)    <br />Note also that the “Objects” pane shows not only the controls, but marks those affected by the currently manipulated state with a red dot and puts the manipulated properties beneath. In case you accidentally manipulated the wrong property, you should remove this entry, rather than simply change it back, otherwise the (trivial) transition will remain in the XAML.</p>
<p>Just setting the visibility of two images results in some verbose and (at first sight) rather confusing XAML:</p>
<p><img title="xaml_template3" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/xaml_template3.jpg?w=549&#038;h=392" width="549" height="392" /></p>
<p>The disabled state looks similar. The click state is represented by the hover image which is moved slightly off center to achieve the click effect (“Properties” pane, “Transform”).</p>
<p>And here’s the resulting button in action, showing normal, hover, disabled, and clicked state:</p>
<p><img title="app_buttonstates" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/app_buttonstates.jpg?w=83&#038;h=24" width="83" height="24" /></p>
<p><strong>Lessons Learned</strong></p>
<p>What I just presented was a fast forward replay of employing the VSM. Using VSM minimalistic to the extreme actually, since I have left out quite a bit of VSM functionality, most notably transitions with animations. Still, I have applied some guidelines I learned to value when using VSM, that I’d like to point out. </p>
<p>So, here are some of the twists that made VSM useful to (rather by) me&#8230; (some learned the hard way).</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  Hint 0 (The most general hint): <u>States need careful planning. </u></p>
<p>If you don’t know yet what the control should look like in the various states, you should shy away from the “States” pane in Blend. Start with conventionally designing the control, It may even help to design a separate control template per state, and merge them only after the design has reached a stable state.</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  Hint 1: <u>Don’t look at existing controls.</u></p>
<p>It’s tempting to look at the existing templates, with Blend the XAML is only a mouse click away. Don’t. The button template has ~100 LOC, and I’ve seen others with more than 300 LOC. And what’s more, they are fully styled, meaning that they employed probably all the features, caring for sophisticated visual effects but not exactly for the poor developer trying to deduce the workings from looking at the XAML.</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  Hint 2: <u>Start simple.</u></p>
<p>Many samples quickly jump at animations used for transitions, easing functions, and slicing French Fries. For me one key to understanding VSM was to stick to the minimum at first. States. Transitions only as simple as possible. Period.</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  Hint 3: <u>VSM is not about <em>creating</em> states. It is about <em>styling </em>them.</u></p>
<p>My initial thinking was „I have a button with a normal image; in disabled mode I need to have a disabled image&#8230;“. This led to all kinds of mind twists, like „how do I create an image control during a state change?“ „Should I rather replace the image URL of the existing control, and how?“, and others. It was a crucial part of understanding when I realized that I do not have a button with one image in one state and another image in another state. What I have is a button with <em>three images in all states</em>, as presented above. The difference between the states is merely which of these images is visible and which is not.</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  Hint 4: <u>When designing a new control, avoid the VSM “States” pane for quite some time. </u></p>
<p>There is one pitfall I managed to hit several times in the beginning. I started Blend, selected the particular state I‘m interested in, and tried to design my control for that state. This is futile, because Blend does not actually design the control (as in setting property values), rather it designs the transitions to these values. (You could switch off recoding mode, but Blend really insists on switching it on again and again and again.)</p>
<p>Therefore I generally design my control „conventionally“. I.e. I place the normal image in a grid and style it; then I make it invisible (kind of a manual state change) and do the same with the next image; and so forth for all states. Only when I‘m done with this I allow myself to even look at the VSM support in Blend.</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  Hint 5: <u>The visual state for the normal state is <em>always there</em>. And <em>always empty</em>. </u></p>
<p>Worse, you’ll have to include it manually in XAML, since Blend doesn’t put it there&#8230; <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  </p>
<p>„Normal state“ is the default state of the state group. Each state group has one; it doesn’t have be be named „normal“, but it has to exist. This is the state in which the control is by default, after initially displaying the control, and before VSM has even touched it. The one that is denoted as “Base” in the “States” pane.</p>
<p>The „normal“ state has to be declared, because otherwise the control will not be drawn correctly after it has been in a different state, say <em>normal –&gt; hover –&gt; normal</em>. And it has to be empty because otherwise the control would show up in an undefined state, at least according to VSM, which can never again be reached, once the control was in a different state. This would lead to all kinds of inconsistencies.</p>
<p>Lemma: All controls in the template initially have property values compliant with the normal state. In the image button example: The normal image is visible, the other images invisible.</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  Hint 6: <u>VSM is not about designing states. It’s about designing <em>differences between </em>the state in question and <em>the normal state</em>.</u></p>
<p>Suppose I have the control designed the „conventional“ way with the looks of the normal state; I also have yet invisible controls for the other states. Now is the time to enter Blend and the “State” pane. Choose the state in question, e.g. mouse over, and manipulate exactly those properties that constitute the difference between normal state and mouse over state. I.e. set the normal image to invisible and the hover image to visible. Blend will record the respective transitions.</p>
<p>It’s always <em>this </em>difference, always normal state vs. the state in question. Only if you achieved the first belt in using VSM and signed the no-liability warrant should you go ahead and attack transitions between specific states, for complexity will explode.</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  Hint 7: <u>State groups are mutually independent. And the same is mandatory for the state differences.</u></p>
<p>Never let different state groups manipulate the same properties. For example the button addresses common states and focus states independently. It would not work to implement the focused state by setting the hover image visible, as this would collide with the mouse over state and eventually result in undefined behavior. The focused state could show a focus rectangle. Or it could actually even manipulate the hover image, as long as it is not the visibility property used by the mouse over. (Whether that makes is a different question, though.)</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  Hint 8: <u>Visual states are not put in stone.</u></p>
<p>Controls usually have visual states defined via attributes. However this is just some information, used by some tools (such as Blend), but of no consequence otherwise. <a href="http://msdn.microsoft.com/en-us/library/system.windows.visualstatemanager.gotostate(VS.95).aspx" target="_blank"><em>VisualStateManager.GoToState</em></a> is what triggers a transition, and it may or may not be called from the control itself. The visual states and groups defined in the template are merely backing information used at runtime. Should the need arise, I could define a new state group, say „Age“, with two visual states „YoungAge“ and „OldAge“ in XAML. Then I could go ahead and call the VSM from the code behind file of my page class to change the state. And after 5 minutes of inactivity my button could grow a beard.</p>
<p><strong>Wrap-Up</strong></p>
<p>So far the hints. But what about more complex demands? I have barely touched the eye catching features at all.</p>
<p>In my opinion, what I just presented will cover the first steps and provide a sound understanding of the core VSM principles. Once this level of understanding VSM is mastered, one can go ahead and explore other areas. </p>
<p>And there certainly are “other areas”. I already mentioned state specific transitions; animated transitions are another topic. If you need an example of what’s possible have a look at <a href="http://www.nibblestutorials.net/pages/behaviors/ListBoxItem/Default.html" target="_blank">this online sample</a>. This is VSM in action, admittedly complemented with some code, but surprisingly little. (You can dig into it starting Blend and opening the sample project „ColorSwatchSL“.)</p>
<p>Some other useful links:</p>
<ul>
<li>VSM designing tips: <a title="http://blogs.msdn.com/expression/archive/2009/10/02/visual-state-manager-tips-for-design-and-authoring.aspx" href="http://blogs.msdn.com/expression/archive/2009/10/02/visual-state-manager-tips-for-design-and-authoring.aspx" target="_blank">http://blogs.msdn.com/expression/archive/2009/10/02/visual-state-manager-tips-for-design-and-authoring.aspx</a> </li>
<li>Additional styling tips (for different controls): <a href="http://blogs.msdn.com/expression/pages/styling-tips.aspx" target="_blank">http://blogs.msdn.com/expression/pages/styling-tips.aspx</a> </li>
<li>A more complex example: <a href="http://scorbs.com/2008/06/11/parts-states-model-with-visualstatemanager-part-1-of/" target="_blank">http://scorbs.com/2008/06/11/parts-states-model-with-visualstatemanager-part-1-of/</a> </li>
</ul>
<p>And from now on it’s no longer a lack of understanding that keeps me from doing things. It’s my incompetence as designer… <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f01%2f24%2fsilverlight-bitspieces-the-first-steps-with-visual-state-manager%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f01%2f24%2fsilverlight-bitspieces-the-first-steps-with-visual-state-manager%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, C#, Design Time, Silverlight, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/702/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/702/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/702/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/702/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/702/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/702/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/702/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/702/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/702/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/702/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/702/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/702/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/702/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/702/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=702&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/01/24/silverlight-bitspieces-the-first-steps-with-visual-state-manager/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/code_imagebutton.jpg" medium="image">
			<media:title type="html">code_imagebutton</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/xaml_imagebutton1.jpg" medium="image">
			<media:title type="html">xaml_imagebutton</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/xaml_template1.jpg" medium="image">
			<media:title type="html">xaml_template1</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/xaml_template2.jpg" medium="image">
			<media:title type="html">xaml_template2</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/blend_states1.jpg" medium="image">
			<media:title type="html">blend_states1</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/blend_states2.jpg" medium="image">
			<media:title type="html">blend_states2</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/xaml_template3.jpg" medium="image">
			<media:title type="html">xaml_template3</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/app_buttonstates.jpg" medium="image">
			<media:title type="html">app_buttonstates</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f01%2f24%2fsilverlight-bitspieces-the-first-steps-with-visual-state-manager%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Bits&amp;Pieces: Derived Custom Controls</title>
		<link>http://ajdotnet.wordpress.com/2010/01/17/silverlight-bitspieces-derived-custom-controls/</link>
		<comments>http://ajdotnet.wordpress.com/2010/01/17/silverlight-bitspieces-derived-custom-controls/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 13:06:48 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=690</guid>
		<description><![CDATA[OK, let’s put the last findings to good use and create a derived control that carries its own default template. This post is again about some fairly basic stuff, but it is the logical next step. My use case: I wanted/needed a simple image button, one that simply takes the image as a property, rather [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=690&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>OK, let’s put the <a href="http://ajdotnet.wordpress.com/2010/01/10/silverlight-bitspieces-controls-basics/" target="_blank">last findings</a> to good use and create a derived control that carries its own default template. This post is again about some fairly basic stuff, but it is the logical next step. </p>
<p>My use case: I wanted/needed a simple image button, one that simply takes the image as a property, rather than having to manipulate the content for every button anew. So what do I need?</p>
<ol>
<li>A derived class. </li>
<li>A dependency property for the image URL. </li>
<li>A new default template. </li>
</ol>
<p>Deriving a SL control is just a matter of clicking add/new item in the solution explorer, and choosing „Silverlight Templated Control“. This will actually create 2 things (and address the default template requirement as well&#8230;):</p>
<ol>
<li>A class derived form Control, placed in a .cs file in the folder I used to create the new item. </li>
<li>A XAML file named <em>Themes/Generic.xaml </em>is created (or extended if it already exists) and contains a style and template for the new control. </li>
</ol>
<p>Now, the implied behavior is that a custom control sets its <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.control.defaultstylekey(VS.95).aspx" target="_blank"><em>DefaultStyleKey</em> property</a> to a type (usually its own). At runtime SL will determine the default style of a control by using this type’s assembly to read the <em>Themes/Generic.xaml </em>content and pick the style that has the type as target type. </p>
<p><img title="code_defaultstylekey" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/code_defaultstylekey.jpg?w=391&#038;h=144" width="391" height="144" /></p>
<p>Note how the style in <em>Themes/Generic.xaml </em>uses an XML namespace to map the class name to a C# namespace:</p>
<p><img title="xaml_defaultstylekey" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/xaml_defaultstylekey.jpg?w=601&#038;h=120" width="601" height="120" /></p>
<blockquote><p>Note: One consequence of this is that all styles of all custom controls in an assembly will end up in the same <em>generic.xaml </em>file. This is usually not an issue, even if implementation and style/template reside in relatively remote files. However, if the assembly grows to accommodate a bigger number of controls, it might make sense to put the control specific resources into separate .xaml files right beside the implementation. Loading the template from a .xaml resource is no big deal, all you need is <em><a href="http://msdn.microsoft.com/en-us/library/xc4235zt(VS.95).aspx" target="_blank">GetManifestResourceStream</a>&#160;</em>and <em><a href="http://msdn.microsoft.com/en-us/library/cc190359(VS.95).aspx" target="_blank">XamlReader.Load</a></em>, in more detail <a href="http://msdn.microsoft.com/en-us/library/cc189076(VS.95).aspx" target="_blank">here</a>.</p>
</blockquote>
<p>The next step is to change the base class — I want to <i>extend</i> the Button, not write it completely anew — and to provide the dependency property for the image. Having a peek at the <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.source(VS.95).aspx" target="_blank">Source</a> </em>property of the <em>Image </em>control tells me that <em>ImageSource </em>is the adequate type.</p>
<h3><img title="code_property" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/code_property.jpg?w=681&#038;h=127" width="681" height="127" /></h3>
<p>Now, let’s customize the appearance. Unfortunately Blend cannot deduce the dependency between the control an the style in <em>Themes/Generic.xaml</em>. Therefore its easier to create an instance of the <em>ImageButton</em>, assign a temporary style with template in blend, placed it into the same page’s XAML: </p>
<p><img title="xaml_aboutpage_style" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/xaml_aboutpage_style.jpg?w=776&#038;h=222" width="776" height="222" /></p>
<p>and the respective button:</p>
<p><img title="xaml_aboutpage_button" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/xaml_aboutpage_button.jpg?w=564&#038;h=58" width="564" height="58" /></p>
<p>Of course I need to have the respective image… </p>
<p>I can now use Blend to work on the template (assigned within the style):</p>
<p><img title="blend_chose_template" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/blend_chose_template.jpg?w=501&#038;h=269" width="501" height="269" /></p>
<p>This will change to editing context to the template rather than the control:</p>
<p><img title="blend_edit_template" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/blend_edit_template.jpg?w=287&#038;h=181" width="287" height="181" /></p>
<p>I changed it to include the image, placed it beside the text. (Actually, placed beside what I choose to have in the content property, using a <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentpresenter(VS.95).aspx" target="_blank">content presenter</a></em>.)</p>
<p>Now I want the image control to show what I have in the <em>NormalImage </em>property I just wrote. Blend is aware of the type of my class, so I can bind the <em>Image.Source </em>property using a template binding to the property of my class.</p>
<p><img title="blend_image_binding1" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/blend_image_binding1.jpg?w=310&#038;h=159" width="310" height="159" /></p>
<p>and clicking it:</p>
<p><img title="blend_image_binding2" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/blend_image_binding2.jpg?w=325&#038;h=400" width="325" height="400" /></p>
<p>The temporary style with template finally looks like this:</p>
<p><img title="xaml_intermediate_style" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/xaml_intermediate_style.jpg?w=496&#038;h=222" width="496" height="222" /></p>
<p>Template bindings can be used to bind against existing properties (of appropriate type), as well as any new property I choose to provide. Actually for a complete implementation I would probably have to map alignments, and other properties accordingly to parts of my template, to provide full customizability for my control. </p>
<p>Now that I’m done designing my button, I can save it, copy the resulting template into the default style for my control in <em>Themes/Generic.xaml</em>, recompile – and then just use it:</p>
<p><img title="xaml_imagebutton" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/xaml_imagebutton.jpg?w=497&#038;h=21" width="497" height="21" /></p>
<p>Just an image, no text; and at runtime:</p>
<p><img title="app_imagebutton" alt="" src="http://ajdotnet.files.wordpress.com/2010/01/app_imagebutton.jpg?w=274&#038;h=78" width="274" height="78" /></p>
<p>&#160;</p>
<p>Alright, that’s the basics of a custom control. Essentially what I’ve done is </p>
<ul>
<li>replacing the default template with one that includes an image </li>
<li>providing a dependency property for the image, actually nothing more than a mirror of the respective property of the image in my template. </li>
</ul>
<p>This is all very boilerplate on one hand, yet extremely flexible at the same time. </p>
<p>Now, the image of the button does not „feel“ very buttonish, i.e. it does not reflect mouse over, disabled state, or clicked state. This is the domain of VSM. Next post&#8230;</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f01%2f17%2fsilverlight-bitspieces-derived-custom-controls%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f01%2f17%2fsilverlight-bitspieces-derived-custom-controls%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, C#, Design Time, Silverlight, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/690/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/690/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/690/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/690/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/690/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/690/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/690/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/690/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=690&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/01/17/silverlight-bitspieces-derived-custom-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/code_defaultstylekey.jpg?w=391" medium="image">
			<media:title type="html">code_defaultstylekey</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/xaml_defaultstylekey.jpg?w=601" medium="image">
			<media:title type="html">xaml_defaultstylekey</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/code_property.jpg?w=681" medium="image">
			<media:title type="html">code_property</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/xaml_aboutpage_style.jpg?w=776" medium="image">
			<media:title type="html">xaml_aboutpage_style</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/xaml_aboutpage_button.jpg?w=564" medium="image">
			<media:title type="html">xaml_aboutpage_button</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/blend_chose_template.jpg?w=501" medium="image">
			<media:title type="html">blend_chose_template</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/blend_edit_template.jpg?w=287" medium="image">
			<media:title type="html">blend_edit_template</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/blend_image_binding1.jpg?w=310" medium="image">
			<media:title type="html">blend_image_binding1</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/blend_image_binding2.jpg?w=325" medium="image">
			<media:title type="html">blend_image_binding2</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/xaml_intermediate_style.jpg?w=496" medium="image">
			<media:title type="html">xaml_intermediate_style</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/xaml_imagebutton.jpg?w=497" medium="image">
			<media:title type="html">xaml_imagebutton</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/app_imagebutton.jpg?w=274" medium="image">
			<media:title type="html">app_imagebutton</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f01%2f17%2fsilverlight-bitspieces-derived-custom-controls%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Bits&amp;Pieces: Controls Basics</title>
		<link>http://ajdotnet.wordpress.com/2010/01/10/silverlight-bitspieces-controls-basics/</link>
		<comments>http://ajdotnet.wordpress.com/2010/01/10/silverlight-bitspieces-controls-basics/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 15:26:06 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=674</guid>
		<description><![CDATA[Silverlight is all about controls, and I have yet barely touched them. It’s about time to change this. And since controls are such an ingrained feature of SL, I can safely refer to others for the bread-and-butter explanations and focus on the key points afterwards. (Still, is post is going to be about fairly basic [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=674&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Silverlight is all about controls, and I have yet barely touched them. It’s about time to change this.</p>
<p>And since controls are such an ingrained feature of SL, I can safely refer to others for the bread-and-butter explanations and focus on the key points afterwards. (Still, is post is going to be about fairly basic stuff.)</p>
<p><strong>The basics…</strong></p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/cc278068(VS.95).aspx" target="_blank">Control Customization</a> (MSDN) does a good job of naming the core concepts, namely Style, Template, Parts, States and State Groups. </li>
<li>Many Softies blogs about SL, I found <a href="http://weblogs.asp.net/dwahlin/archive/tags/Silverlight/default.aspx" target="_blank">Dan Wahlin</a> particularly valuable (and he’ll point you to others.) </li>
<li>Various hints can be found on <a href="http://silverlight.net/" target="_blank">silverlight.net</a> and <a href="http://www.silverlightshow.net" target="_blank">silverlightshow.net</a>, e.g. about <a href="http://www.silverlightshow.net/Tips/StylesAndTemplates.aspx" target="_blank">Styles and Templates</a>. </li>
</ul>
<p>Done <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>OK, this would be a short post, if that where indeed it. </p>
<p>Actually this is how I started. Using controls the way I did in WinForms or ASP.NET, setting properties, layouting, styling. It is all so common and natural, I didn’t spend much thought on controls per se at first. </p>
<p>However, treating SL controls like WinForms controls doesn’t do them credit and neglects quite a bit of the potential. Actually, in my opinion, the SL control system is one step ahead of all previous systems. </p>
<p><strong>The Key Point About SL Controls…</strong></p>
<p>… is this: <em>Silverlight clearly and cleanly distinguishes and separates <u>behavior</u> (control type), <u>shape</u> (control template), and <u>style</u> (control style). </em></p>
<p>And the glue holding this <a href="http://en.wikipedia.org/wiki/Triumvirate" target="_blank">triumvirate</a> together is the properties, more accurately <a href="http://msdn.microsoft.com/en-us/library/cc221408(VS.95).aspx" target="_blank">dependency properties</a>. The following image is an attempt to describe this relationship:</p>
<p> <img src="http://ajdotnet.files.wordpress.com/2010/01/control_structure.jpg" />
<ul>
<li>Controls define their properties, and only the properties defined in a control are accessible for manipulation via styles or to be referenced by templates. </li>
<li>Templates make up the shape of the control, by assembling Parts into a new compound representation. </li>
<li>And styles set property values that affect either the behavior or are referenced by the template to affect the appearance or content of a Part. </li>
</ul>
<p>Add the fact that properties may be subject to databinding and you get a very concise system. </p>
<p><strong>In More Detail… </strong></p>
<p><em>Control…</em></p>
<p>SL controls come as classes (surprise!), but their job is only to define behavior (unlike WinForms or WebForms controls that also do the rendering). E.g. a button control essentially does three things:</p>
<ul>
<li>It defines behavior. I.e. it reacts on mouse over and mouse click to render a hover effect or trigger the click event. </li>
<li>It defines (dependency) properties. The properties offer a way of controlling the behavior and appearance – if the control code or the template chose to refer to them. </li>
<li>It triggers the rendering process, deferring it to the template(s). Usually controls bring their own default template within the resources, many let the template be replaced either partly (usually by setting a <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.content(VS.95).aspx" target="_blank"><em>Content</em></a><em> </em>property), or completely by setting some <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.contenttemplate(VS.95).aspx" target="_blank">Template</a> </em>property. </li>
</ul>
<p><em>Style…</em></p>
<p>Styles are essentially a way to set a couple of properties of a control. Period. </p>
<p>To be more elaborate, Styles don’t care whether those values actually <em>style </em>the control in the sense of designing it. For example I can set the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.selectionmode(VS.95).aspx" target="_blank">selection mode</a> of a data grid, which affects the behavior rather than the design. Styles can set virtually <em>any </em>property of <em>any </em>control, including the one I haven’t even written yet. Styles are also not restricted to certain (and in these cases typically simple) types; leveraging <a href="http://msdn.microsoft.com/en-us/library/cc189036(VS.95).aspx" target="_blank">the power of XAML</a>, styles can assign virtually <em>any </em>value of <em>any </em>type.</p>
<p>Lemma: Styles can <em>only </em>manipulate properties. Meaning if I need a button with an image I cannot simply set the image via a style, because the standard button control simply does not have a respective property. I need to derive a control and define a respective dependency property.</p>
<p>Since those properties are class specific, styles are consequently type specific (contrary to CSS), and have to unequivocally state that type. Hence one cannot define a style (say setting font type and size) and apply it to a textbox as well as to a link control. To one who is used to CSS this may come as a restriction.</p>
<p><em>Template…</em></p>
<p>Basically a template is the XAML representation of the Parts that together constitute the visual appearance of a control. This can be a mixture of primitives, but it could also incorporate other controls. Also there is some degree of “behavior” in the sense that this may include animations, visual state manager information, and other dynamic content. Depending on the control, a template can be partly set via some content property or completely via some template property. Some controls may offer more than one template, e.g. for header and cells in a data grid. Templates can refer to properties, by way of <a href="http://msdn.microsoft.com/en-us/library/cc189062(VS.95).aspx" target="_blank"><em>TemplateBinding</em></a>, and those properties can afterwards be customized via styles. </p>
<p>Depending on the control (which carries the logic to “activate” them), templates can offer a wide spectrum of extensibility. As an example consider the following textbox, using an alternate template:</p>
<p> <img src="http://ajdotnet.files.wordpress.com/2010/01/xaml_textbox.jpg" />
<p>This template adds a small glyph to the textbox and sets its tooltip to the textbox content. And this is the result: </p>
<p> <img src="http://ajdotnet.files.wordpress.com/2010/01/app_textbox.jpg" />
<p>This is not bullet proof (changing the text won’t update the tooltip), but it should give a first hint on the potential of customization via templates. </p>
<p>Add visual state manager and states for mouse, selection, validation errors, put animations on top, and you get an unprecedented customizability of even the most basic controls. The down side is the unprecedented complexity, for example the template for the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.datepicker(VS.95).aspx" target="_blank">date picker control</a> (extracted via blend) has about 150 LOC, and I have seen other with over 300 LOC.&#160;&#160;&#160; </p>
<p><strong>Some Conventions…</strong></p>
<p>SL controls don’t adhere to some global style, i.e. it is not possible to somehow state that every textbox should use a certain font within a given application (this is one of the <a href="http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx#implicit-style" target="_blank">new SL4 features</a>, though). To make my default style assignments easier I like to have standard styles named after class (i.e. &quot;Textbox” – not “<em>Default</em>Textbox” or “Textbox<em>Style</em>”, or some other convention). One could replace the standard classes with derived classes or use some other generic mechanism, yet so far Blend and manual assignment worked fine for me.</p>
<p>Regarding templates, I generally don’t set the Template property within the page XAML. Rather I like to assign the template indirectly via a style. This way I won’t have to think about setting both properties, style and template, and worry about dependencies. Applied to the example above:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2010/01/xaml_textbox_withstyle.jpg" /></p>
<p>And the respective style which also sets the property:</p>
<p>&#160;<img src="http://ajdotnet.files.wordpress.com/2010/01/xaml_textbox_style.jpg" /> </p>
<p>If styles and templates are that powerful one could assume that the need to deriving controls was less prevalent. Matter of fact I do derive controls as often as before, only the reasons have changed: Mostly I derive controls to define properties that I need within custom templates and styles.</p>
<p>And I thought this might be a shorter post…. Anyway, the next post will lay out some additional basic stuff before I’m going to tackle derived controls and VSM.</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f01%2f10%2fsilverlight-bitspieces-controls-basics%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f01%2f10%2fsilverlight-bitspieces-controls-basics%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, Silverlight  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/674/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=674&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/01/10/silverlight-bitspieces-controls-basics/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/control_structure.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/xaml_textbox.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/app_textbox.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/xaml_textbox_withstyle.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/xaml_textbox_style.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f01%2f10%2fsilverlight-bitspieces-controls-basics%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>MVVM needs (re)definition</title>
		<link>http://ajdotnet.wordpress.com/2010/01/01/mvvm-needs-redefinition/</link>
		<comments>http://ajdotnet.wordpress.com/2010/01/01/mvvm-needs-redefinition/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 13:41:42 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=666</guid>
		<description><![CDATA[So, the last two posts made the point of showing that MVVM has a rather fragile theoretical foundation. Either that, or it is constantly misapplied. Matter of fact, there are two incarnations of MVVM. In order to distinguish them, let’s call them MVVM/PM and MVVM/SC respectively. As a quick recap: The relevant difference between the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=666&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So, the last two posts made the point of showing that MVVM has a rather fragile theoretical foundation. Either that, or it is constantly misapplied.</p>
<p>Matter of fact, there are two incarnations of MVVM. In order to distinguish them, let’s call them <a href="http://ajdotnet.wordpress.com/2010/01/01/excursus-presentation-model-pattern/" target="_blank">MVVM/PM</a> and <a href="http://ajdotnet.wordpress.com/2010/01/01/excursus-supervising-controller-pattern/" target="_blank">MVVM/SC</a> respectively.</p>
<blockquote><p>As a quick recap: The relevant difference between the Presentation Model pattern and the Supervising Controller Patter (and the MVVM derivates respectively) is whether the View gets access to the Model’s data model or not. The patterns are very similar, but they differ in this one important aspect.</p>
<p>See my preparatory posts for details. Another descriptions of the two patterns with the same distinction can be found in the <a href="http://msdn.microsoft.com/en-us/library/dd458859.aspx" target="_blank">Composite Application Guidance for WPF and Silverlight</a> documentation.</p></blockquote>
<p>One could argue that this difference is superficial, even that Supervising Controller is actually a special case of Presentation Model (if you promote Fowlers exception for read-only data to the be the norm). In fact, when I discussed this whole topic with other people, about half of them fell into the camp that didn’t care at all and rather took the pragmatic approach, like “Who cares, I use MVVM the way it suites me, no matter what some useless theoretician thinks I should be doing.”. But even they didn’t argue the fact that there actually is something wrong with the theory.</p>
<p><strong>The Problem with the Theory…</strong></p>
<p>Theoretical musings aside – and presuming we agree that there are two different MVVM patterns – why is that a problem?</p>
<p>Well, I see several problems:</p>
<p><strong>First</strong>, if someone tells you, he is using MVVM, he <em>communicates </em>something.</p>
<p>This is the most important achievement of the <a href="http://en.wikipedia.org/wiki/Design_Patterns_(book)" target="_blank">GoF</a> with their groundbreaking work on <a href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)" target="_blank">patterns</a>: Simply by providing a catalogue of abstract relationships of software artifacts and <em>naming</em> them, they established a vocabulary. This vocabulary is a means of communication, a way of talking about abstract concepts. What this has done to foster knowledge reuse, software quality, and documentation aspects can hardly be underestimated.</p>
<p>However, having a term with <a href="http://en.wikipedia.org/wiki/Table_%28verb%29" target="_blank">contradictory meanings</a> will <a href="http://books.google.de/books?id=_lIEAAAAMBAJ&amp;lpg=PA72&amp;ots=oiyY787oyg&amp;dq=%22The%20British%20Staff%20prepared%22%20%22to%20table%22&amp;hl=en&amp;pg=PA72#v=onepage&amp;q=%22The%20British%20Staff%20prepared%22%20%22to%20table%22&amp;f=false" target="_blank">destroy that means</a> perhaps more severely than not having a respective term in the first place.</p>
<p><strong>Second</strong>, having a solid theoretical foundation, a clear concept, leads to a better understanding in general.</p>
<p>It is the concept that guides me if I have to face a situation that is not really addressed by the current implementation. And implementation has to follow the concept, not vice versa.</p>
<p>If I know what the theoretical foundation is, it can help me answering certain questions. Or it can tell me clearly that a particular topic isn’t covered by this pattern, hence I will know that I’ll have to look elsewhere. Without a solid foundation I won’t get any guidance, I would have to solve every problem on my own, and I would be in danger of violating principles that I’m not even aware of.</p>
<p><strong>Third, </strong>on the practical side, we need to clarify the theoretical foundation to tackle the actual issue: <em>Neither approach does actually help by itself.</em></p>
<p>As an example take <a href="http://msdn.microsoft.com/en-us/library/cc278072(VS.95).aspx#data_validation" target="_blank">validation</a>. Validation in SL3 works by <a href="http://blogs.silverlight.net/blogs/jesseliberty/archive/2009/06/05/silverlight-validation-in-detail.aspx" target="_blank">putting validation code into property setters</a> or <a href="http://wildermuth.com/2009/09/28/How_Silverlight_3_Validation_Works" target="_blank">applying validation attributes to them</a>. However, neither option is feasible with the code generated service proxy classes. Alternative approaches I found, like attaching code to the property changed event, are not very satisfying to say the least. Other demands include thoughts about generic caching or offline support.</p>
<ul>
<li>MVVM/PM solves this issue quite easily within the PM. But having to replicate the data model leads to a maintenance nightmare. And (at least in the Silverlight area) it’s hardly employed, anyway.</li>
<li>MVVM/SC (the usually employed pattern because it works very well with the tooling) simply stops short of answering questions regarding validation.</li>
</ul>
<blockquote><p>Actually it has been the issue of validation and thoughts about caching and offline support that triggered all these thoughts and sent me back to the drawing board, investigating the concept, and trying to find out what the theory tells me. Well, I found two different MVVMs…</p></blockquote>
<p><strong>Verdict</strong></p>
<p>So, I did wreck MVVM, didn’t I? Sorry. Couldn’t be helped.</p>
<p>In my opinion, the only solution for this mess is a redefinition of the term MVVM. This in inevitable, I’m just not sure how this will happen. The concept could evolve and form a better theoretical foundation. But then, people could also continue to neglect the theory and come up with “pragmatic solutions” – meaning that MVVM becomes a fancy umbrella term for anything that looks remotely like PM or SC.</p>
<p>Personally, I would certainly prefer a sound theoretical foundation, probably one that emancipates MVVM from its two parents. Actually I would go where the tooling goes (see <a href="http://weblogs.asp.net/dwahlin/archive/2009/12/08/getting-started-with-the-mvvm-pattern-in-silverlight-applications.aspx" target="_blank">Dan’s post</a>), because this is what people will do in the long run, and with good reason. Thus I would start with MVVM/SC as MVVM. From there I would either extend MVVM or complement it with other patterns to address validation, caching, synchronization for offline applications, whatever.</p>
<p>Yes, this would imply redefining MVVM to stem from SC rather than PM, and to accept VM as misnomer for the sake of continuity. And additional concepts to fill the gaps, that may yet have to evolve. However, this is what people think they are doing, anyway. It’s simpler to adjust the theory than people’s perceptions.</p>
<blockquote><p>One important note: I deliberately ignored WPF! While MVVM started there and was reused with SL, it may be the case that the special demands of an SL application may cause MVVM to evolve differently for the two technologies. (It may not. Still, I’d like to keep that door open.)</p></blockquote>
<p>So far my criticism. I’m aware that I just redefined (or rather dumped?) a well-established term, and I’m not someone like Fowler who does that on a daily basis. So I would be interested in opinions. Just tell me if I went over the top.</p>
<p><span style="color:#008000;">That’s all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f01%2f01%2fmvvm-needs-redefinition%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f01%2f01%2fmvvm-needs-redefinition%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, Silverlight, Software Architecture  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/666/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/666/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/666/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/666/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/666/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/666/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/666/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=666&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/01/01/mvvm-needs-redefinition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2010%2f01%2f01%2fmvvm-needs-redefinition%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Excursus: Supervising Controller Pattern</title>
		<link>http://ajdotnet.wordpress.com/2010/01/01/excursus-supervising-controller-pattern/</link>
		<comments>http://ajdotnet.wordpress.com/2010/01/01/excursus-supervising-controller-pattern/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 13:35:04 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=662</guid>
		<description><![CDATA[Note: This is the second preparation post for an upcoming MVVM related post (which got definitely too long)…. The Supervising Controller pattern (previously known as Supervising Presenter pattern) goes back to Fowler ([Fowler-SC]). What makes it relevant for Silverlight development is that it is the usually employed pattern. Similarly to the Presentation Model (PM) pattern, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=662&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Note: This is the second preparation post for an upcoming MVVM related post (which got definitely too long)….</p>
<p>The Supervising Controller pattern (previously known as Supervising Presenter pattern) goes back to Fowler ([<a href="http://martinfowler.com/eaaDev/SupervisingPresenter.html" target="_blank">Fowler-SC</a>]). What makes it relevant for Silverlight development is that it is the <a href="http://ajdotnet.wordpress.com/2009/08/27/silverlight-bitspieces-part-4-view-model-basics/" target="_blank">usually employed pattern</a>.</p>
<p>Similarly to the <a href="http://martinfowler.com/eaaDev/PresentationModel.html" target="_blank">Presentation Model</a> (PM) pattern, the Supervising Controller pattern essentially contains three parts: View, Model, and Supervising Controller (SC). The SC pattern provides “the ability to easily map between the view and model, often using some kind of Data Binding”. The mediator between the View and the Model is the SC: “A Supervising Controller has two primary responsibilities: input response and partial view/model synchronization.” ([<a href="http://martinfowler.com/eaaDev/SupervisingPresenter.html" target="_blank">Fowler-SC</a>])</p>
<p>While the SC pattern is very similar to the PM pattern, the relationship and responsibilities of the parts are somewhat different. For an SL application it looks like this:</p>
<p><img title="supervising_controller" src="http://ajdotnet.files.wordpress.com/2010/01/supervising_controller.gif?w=801&#038;h=409" border="0" alt="supervising_controller" width="801" height="409" /></p>
<p>Compared with the <a href="http://ajdotnet.wordpress.com/2010/01/01/excursus-presentation-model-pattern/" target="_blank">PM pattern</a>, the difference is seemingly minor: The SC lacks the responsibility to establish a data model, rather there is an additional arrow from View to Model. However, this is actually (at least in comparison to the PM pattern) the defining characteristic of the SC pattern: The View interacts directly with the Model (contrary to the PM pattern). The SC acts only as a mediator, once the connection between View and Model is established, the SC is no longer involved.</p>
<p>The SC has the following responsibilities (leaving aside view entities, as they constitute only a minor part of the data model):</p>
<ul>
<li>Handling the controller logic part</li>
<li>Talking to the service</li>
</ul>
<p>Obviously the SC as less responsibilities than the Presentation Model, resulting in less complexity, and better <a href="http://en.wikipedia.org/wiki/Separation_of_concerns" target="_blank">separation of concern</a>. On the other hand it is also less flexible and thus less applicable in complex cases.</p>
<p><strong>The Relation to MVVM</strong></p>
<p>Matter if fact, this is the way MVVM for Silverlight is usually presented: If you find a more recent description of Silverlight with MVVM (which is curiously not that easy), it is probably similar to <a href="http://ajdotnet.wordpress.com/2009/08/27/silverlight-bitspieces-part-4-view-model-basics/" target="_blank">my own introduction</a>. Dan Wahlin has <a href="http://weblogs.asp.net/dwahlin/archive/2009/12/08/getting-started-with-the-mvvm-pattern-in-silverlight-applications.aspx" target="_blank">recently written</a> about the topic, focusing on SL, and it’s probably the most concise introduction to MVVM with SL I&#8217;ve found so far. And again, his code snippets and text descriptions clearly follow the SC pattern. (Curiously his images follow the PM pattern, but since he never names it and takes a rather pragmatic approach anyway, I’ll leave it at that. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  )</p>
<p>Notwithstanding the verdict: From a purely formalistic point of view, <span style="text-decoration:underline;">this is simply wrong</span>! If MVVM is defined as a derivate of the PM pattern (as it was originally introduced), it cannot follow the SC patter at the same time. Both patterns follow contradictory approaches regarding the data model and the resulting ViewModel responsibilities. Actually it is even worse: Since it is not even a responsibility of the SC to define a data model in the first place, the term ViewModel is grossly misleading.</p>
<p>However, given that the Model for SL applications is usually code generated and supports everything that is needed for databinding, the beauty of this approach is its ease of use. At first. (<em>In other words, stay tuned…</em>)</p>
<p><span style="color:#008000;">That’s all for now folks,<br />
<strong>AJ.NET</strong></span></p>
<br />Posted in .NET, Silverlight, Software Architecture  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/662/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/662/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/662/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/662/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/662/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/662/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/662/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=662&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/01/01/excursus-supervising-controller-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/supervising_controller.gif" medium="image">
			<media:title type="html">supervising_controller</media:title>
		</media:content>
	</item>
		<item>
		<title>Excursus: Presentation Model Pattern</title>
		<link>http://ajdotnet.wordpress.com/2010/01/01/excursus-presentation-model-pattern/</link>
		<comments>http://ajdotnet.wordpress.com/2010/01/01/excursus-presentation-model-pattern/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 13:24:54 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=659</guid>
		<description><![CDATA[Note: This post is a preparation post for an upcoming MVVM related post (which got definitely too long)…. The Presentation Model pattern goes back to Fowler ([Fowler-PM]). What makes it relevant for Silverlight development is that it is often cited as the underlying pattern for the Model-View-ViewModel pattern. Essentially the Presentation Model pattern contains View, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=659&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Note: This post is a preparation post for an upcoming MVVM related post (which got definitely too long)….</p>
<p>The Presentation Model pattern goes back to Fowler ([<a href="http://martinfowler.com/eaaDev/PresentationModel.html" target="_blank">Fowler-PM</a>]). What makes it relevant for Silverlight development is that it is often cited as the underlying pattern for the <a href="http://en.wikipedia.org/wiki/Model_View_ViewModel" target="_blank">Model-View-ViewModel</a> pattern.</p>
<p>Essentially the Presentation Model pattern contains View, Presentation Model (PM) and Model. And it actually comes in two flavors: “An important implementation detail of Presentation Model is whether the View should reference the Presentation Model or the Presentation Model should reference the View. Both implementations provide pros and cons.” ([<a href="http://martinfowler.com/eaaDev/PresentationModel.html" target="_blank">Fowler-PM</a>])</p>
<blockquote><p>Interesting (but irrelevant for this post): “A Presentation Model that references a view generally maintains the synchronization code in the Presentation Model. […] The views implement interfaces allowing for easy stubbing when testing the Presentation Model.”&#160; <br />This leads straight to the <a href="http://www.martinfowler.com/eaaDev/ModelViewPresenter.html" target="_blank">Passive View incarnation</a> of the <a href="http://en.wikipedia.org/wiki/Model_View_Presenter" target="_blank">MVP pattern</a>, also supported by the <a href="http://msdn.microsoft.com/en-us/library/cc304728.aspx" target="_blank">WCSF</a>. The other incarnation of MVP is the Supervising Controller (which will be the topic of another post). The pattern ecosystem certainly has some relations…</p>
</blockquote>
<p>Now, the View referencing the PM (Fowler explicitly mentions databinding) leads to MVVM/PM. Given Fowlers <a href="http://www.martinfowler.com/bliki/AnemicDomainModel.html" target="_blank">rejection of DTO’s</a> its fair to assume that he had a Model constituted as <a href="http://en.wikipedia.org/wiki/Business_object_%28computer_science%29" target="_blank">BO</a>’s in mind, with the BO’s talking directly to the next layer. However, I’ll skip that and stay with <a href="http://en.wikipedia.org/wiki/Data_transfer_object" target="_blank">DTO</a>’s as Model. <a href="http://ajdotnet.wordpress.com/2008/07/06/rants-and-rails/" target="_blank">Personal opinions</a> aside, the common case with SL applications is using code generated service proxies, especially the service contract, as Model.</p>
<p>Hence the relationship of the participants in an SL application would look like this:</p>
<p><img title="presentation_model" border="0" alt="presentation_model" src="http://ajdotnet.files.wordpress.com/2010/01/presentation_model.gif?w=801&#038;h=409" width="801" height="409" /> </p>
<p>Fowler states it himself: “The essence of a Presentation Model is of a fully self-contained class that represents all the data and behavior of the UI window,” ([<a href="http://martinfowler.com/eaaDev/PresentationModel.html" target="_blank">Fowler-PM</a>]), meaning that the PM constitutes its own data model, and the View does not get access to the Model.</p>
<p>This is actually the defining characteristic of the PM pattern: The PM provides – constitutes – <em>is </em>– a data model, separate from the Model; the View is shielded away from the Model and doesn’t get access to it or its types. (It consequently follows that the pattern requires a duplication of the data model – hence the name Presentation <em>Model </em>– that is largely readily available with the Model.) </p>
<p>Thus the PM has several responsibilities:</p>
<ul>
<li>Defining its own data model </li>
<li>Mapping the data between the two data models (using wrappers or other means) </li>
<li>Handling the controller logic part </li>
<li>Talking to the service (with BO’s rather than DTO’s, it would be their job to do this). </li>
</ul>
<p><strong>The Relation to MVVM</strong></p>
<p>John Gossman’s post “<a href="http://blogs.msdn.com/johngossman/archive/2005/10/08/478683.aspx" target="_blank">Introduction to Model/View/ViewModel pattern for building WPF apps</a>” (written 2005!) is generally referred to as the “introducing post”, bringing MVVM into existence. If only somewhat between the lines, but he introduces and defines MVVM as derivate of the PM pattern (without actually naming it); Wikipedia <a href="http://en.wikipedia.org/wiki/Model_View_ViewModel" target="_blank">declares MVVM</a> “as a specialization of the PresentationModel design pattern”, and the often quoted MSDN article “<a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" target="_blank">WPF Apps With The Model-View-ViewModel Design Pattern</a>” follows the <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx#id0090102" target="_blank">same principles</a>. </p>
<p>Hence MVVM also suffers from the need to replicate the data model. John Gossman states that “only a small subset of application UI can be data bound directly to the Model“, and thus it is feasible to pay for this effort and the implications. However, if you don’t agree with this assessment (like me, for one), you could argue that this leads to meaningless replication.</p>
<blockquote><p>Note: Fowler actually acknowledges that and states: “One area where data binding can work very well is with read-only data, […] The presentation model in this case reveals its internal data set as a property. This allows the form to data bind directly to the cells in the data set.” </p>
<p>However, this is a shortcut (kind of a degeneration) for read-only cases, in order to leverage data binding capabilities. </p>
</blockquote>
<p>And by the way: If this is not exactly what you do if you say “I do Silverlight with MVVM…”, <a href="http://ajdotnet.wordpress.com/2009/08/27/silverlight-bitspieces-part-4-view-model-basics/" target="_blank">welcome to the club</a>. That’s what started this post in the first place. <em>More on this in the next posts…</em></p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<br />Posted in .NET, Silverlight, Software Architecture  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/659/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/659/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/659/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/659/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/659/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/659/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/659/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/659/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/659/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/659/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/659/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/659/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/659/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/659/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=659&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2010/01/01/excursus-presentation-model-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2010/01/presentation_model.gif" medium="image">
			<media:title type="html">presentation_model</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Bits&amp;Pieces &#8211; Part 9: A MessageBox replacement</title>
		<link>http://ajdotnet.wordpress.com/2009/11/28/silverlight-bitspieces-part-9-a-messagebox-replacement/</link>
		<comments>http://ajdotnet.wordpress.com/2009/11/28/silverlight-bitspieces-part-9-a-messagebox-replacement/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 18:01:47 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=632</guid>
		<description><![CDATA[OK, let’s put the brand new service provider model to some good use. Whenever a service call reports an error I want some message box telling me about it (rather than simply swallowing it, which is the default behavior). Whenever the user does something potentially devastating I want some explicit confirmation, read message box, that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=632&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>OK, let’s put the <a href="http://ajdotnet.wordpress.com/2009/11/14/silverlight-bitspieces-part-8-application-extensions/" target="_blank">brand new service provider model</a> to some good use.</p>
<p>Whenever a service call reports an error I want some message box telling me about it (rather than simply swallowing it, which is the default behavior). Whenever the user does something potentially devastating I want some explicit confirmation, read message box, that he knows what he’s doing. <a href="http://msdn.microsoft.com/en-us/library/ms598690(VS.95).aspx" target="_blank"><em>MessageBox.Show</em></a> does all I need (well, it is restricted to OK and OK/Cancel, but one can live with that). Only&#8230; these system message boxes are dull, boring, and not at all a shiny example for a Silverlight application. <em>Enter the message box service provider…</em></p>
<p><strong>Basic implementation of a message box service</strong></p>
<p>The basic implementation will get the infrastructure up and running.</p>
<p>The first step is defining the service contract. Show this and that and a query method. The first (and naive) version looks like this:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_interface1.jpg" /> </p>
<p>The default implementation of our <em>application extension service turned service provider</em> (AES/SP) would use the dull system message boxes to implement that. The code is actually quite straight forward:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_messageboxservice.jpg" /> </p>
<p>Now, I could demand that the app.xaml has this one (or any other service implementing my interface) registered. However, I like to be <a href="http://en.wikipedia.org/wiki/Convention_over_Code" target="_blank">correct by default</a>, thus my accessor will fall back on this implementation if none is registered – and I can be sure that there will <em>always </em>be a respective service. </p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_zugriff2.jpg" /> </p>
<p>All that is left is a search&amp;replace for all calls to <a href="http://msdn.microsoft.com/en-us/library/ms598690(VS.95).aspx" target="_blank"><em>MessageBox.Show</em></a>&#8230; E.g. to show an error:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_verwendung_error.jpg" /> </p>
<p>… and to get confirmation, in this case to return a book:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_verwendung_confirm.jpg" /> </p>
<p>And, of course, it works as expected:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/app_messagebox.jpg" /> </p>
<p><strong>Replacing the Dialog </strong></p>
<p>Second act. Get rid of those dull things.</p>
<p>Create a new “Silverlight Child Window” and style it to look like a message box. I „borrowed“ the images from the Visual Studio Image Library (on my machine under <em>C:\Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary\1033\VS2008ImageLibrary\Objects\png_format\WinVista\</em>) and simply placed all possible images in the dialog. A textbox, two buttons, that’s it. Here is the styled XAML:</p>
<h3><a href="http://ajdotnet.files.wordpress.com/2009/11/xaml_messagebox_new.jpg" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/11/xaml_messagebox_new.jpg" /></a> </h3>
<p>Some code is needed for the initialization. The message has to be set, the correct image made visible, etc.. I could probably have done this with less coding, using some tricks and elaborate databinding. But who cares, it’s straight forward and comprehensible (unlike what I probably would have come up with).</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_dialog.jpg" /> </p>
<p>Setting the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.childwindow.dialogresult(VS.95).aspx" target="_blank"><em>DialogResult </em>property</a> also closes the dialog (sik!).</p>
<p>Finally I need a replacement AES/SP. The main method to show the dialog looks like this:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_messageboxservice_new.jpg" /> </p>
<p>Great? Great! &#8230; GOT YOU! (Fell into the trap myself, actually&#8230; :-/ )</p>
<p><strong>Fixing the Bug</strong></p>
<p>Remember that in Silverlight <em>everything</em> is asynchronous? Well, everything except <em><a href="http://msdn.microsoft.com/en-us/library/ms598690(VS.95).aspx" target="_blank">MessageBox.Show</a></em>? And ‘everything’ includes <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.childwindow.show(VS.95).aspx" target="_blank">ChildWindow.Show</a></em>! Meaning my confirm method will not work this way. To overcome this I decided to pass a delegate to the dialog constructor and made sure it’s called in the OK case: </p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_dialog_callback.jpg" /> </p>
<p>And to be able to pass the delegate I changed the existing AES as well (and the interface respectively):</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_messageboxservice_better.jpg" /> </p>
<blockquote><p>Of course I had to adjust the default implementation using a messagebox:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_messageboxservice_callback.jpg" /> </p>
</blockquote>
<p>The calling code changes respectively, passing a lambda:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_verwendung_confirm_new.jpg" /> </p>
<p>Done. Now my application looks nice, even if it has to show a message box:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/app_messagebox_new.jpg" /> </p>
<p><strong><a href="http://en.wikipedia.org/wiki/ANFSCD" target="_blank">ANFSCD</a>…</strong></p>
<p>This endeavor served actually three purposes: </p>
<ul>
<li>First, I wanted/needed the feature <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  </li>
<li>Second, I wanted to see/demonstrate the service provider pattern from a user’s point of view. </li>
<li>And third – as you may have noticed from some screenshots – I used this implementation to check out VS2010 beta. </li>
</ul>
<blockquote><p>A quick verdict about VS 2010 beta (not really worth a separate post)&#8230;</p>
<p>The core system, i.e. the shell, the C# code editor, build system, etc. feels very good. No apparent bugs, quite fast, including intellisense, and close enough to VS2008 to feel familiar. Considering that big parts of this are complete rewrites, this is quite an achievement.</p>
<p>The visual designer for (Silverlight) XAML works nice for user controls. Designing grids, the property pane, and other tasks, is at first glance en par with Blend, but comes in a more familiar „Visual Studio flavor“; still it feels more rich and mature than VS2008.      <br />However, there are some notable gaps. Editing of styles and templates, animations, and visual state manager are not covered. Thus my guess is that Blend will remain a necessary complement to VS, even if one has to switch less often. BTW: Contrary to <a href="http://timheuer.com/blog/archive/2009/10/22/can-i-use-vs2010-for-silverlight-3-development.aspx" target="_blank">what Tim wrote</a>, I could work with Blend on VS2010 solutions (the project that cannot be loaded is only the web project), I just refrained from manipulating my project files with Blend.</p>
<p>Other areas I touched briefly have been less satisfying. <a href="http://msdn.microsoft.com/en-us/library/dd997841(VS.100).aspx" target="_blank">IntelliTrace</a> didn’t work, but I didn’t spend too much time on that. The architecture and modeling area for example has changed, but is by no means bug free (to the point of “not yet usable”). The profiler has evolved, but IMO still lacks what DevPartner offered nearly 10 years ago: <a href="http://www.microfocus.com/products/DevPartner/StudioProfessionalEditionCapabilities.asp#6" target="_blank">a decent call graph</a>. </p>
<p>Oh, one bright spot for any dev lead: code analysis (FxCop) rules are now <a href="http://blogs.msdn.com/fxcop/archive/2008/11/12/fun-with-code-analysis-rulesets.aspx" target="_blank">maintained in separate files</a>, projects reference these files by name.</p>
<p>Anyway, I have been using VS2010 beta since I installed it and was never compelled to switch back to VS2008. I’m going to have to reinstall my machine anytime soon, and I’m planning on going along with VS2010 beta, not installing VS2008 at all.</p>
</blockquote>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2009/11/28/silverlight-bitspieces-part-9-a-messagebox-replacement/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/11/28/silverlight-bitspieces-part-9-a-messagebox-replacement/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, C#, Silverlight, Software Architecture, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/632/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/632/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/632/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/632/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/632/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/632/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/632/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/632/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=632&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/11/28/silverlight-bitspieces-part-9-a-messagebox-replacement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_interface1.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_messageboxservice.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_zugriff2.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_verwendung_error.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_verwendung_confirm.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/app_messagebox.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/xaml_messagebox_new.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_dialog.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_messageboxservice_new.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_dialog_callback.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_messageboxservice_better.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_messageboxservice_callback.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_verwendung_confirm_new.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/app_messagebox_new.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/11/28/silverlight-bitspieces-part-9-a-messagebox-replacement/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Bits&amp;Pieces &#8211; Part 8: Application Extensions</title>
		<link>http://ajdotnet.wordpress.com/2009/11/14/silverlight-bitspieces-part-8-application-extensions/</link>
		<comments>http://ajdotnet.wordpress.com/2009/11/14/silverlight-bitspieces-part-8-application-extensions/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 10:20:34 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=629</guid>
		<description><![CDATA[Note: This is part of a series, you can find the related posts here… The last post used the new Application Extension Services (AES for short) to include security into the application. This time I’m going to take AES one step further, laying out yet another piece of basic infrastructure. As a quick recap: An [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=629&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is part of a series, you can find the related posts <a href="http://ajdotnet.wordpress.com/category/silverlight/" target="_blank">here</a>…</p>
</blockquote>
<p>The last post used the new <a href="http://msdn.microsoft.com/en-us/library/dd833084(VS.95).aspx" target="_blank">Application Extension Services</a> (AES for short) to include security into the application. This time I’m going to take AES one step further, laying out yet another piece of basic infrastructure.</p>
<blockquote><p>As a quick recap: An AES is a simple class, implementing a simple interface (<em><a href="http://msdn.microsoft.com/en-us/library/system.windows.iapplicationservice(VS.95).aspx" target="_blank">IApplicationService</a></em>) and optionally another one (<em><a href="http://msdn.microsoft.com/en-us/library/system.windows.iapplicationlifetimeaware(VS.95).aspx" target="_blank">IApplicationLifetimeAware</a></em>). It is then registered by the developer via the <em>app.xaml</em>. SL3 instantiates the AES at runtime and calls the respective callback methods on said interfaces, including <a href="http://msdn.microsoft.com/en-us/library/system.windows.iapplicationservice.startservice(VS.95).aspx" target="_blank"><em>StartService</em></a><em>, </em><a href="http://msdn.microsoft.com/en-us/library/system.windows.iapplicationservice.stopservice(VS.95).aspx" target="_blank"><em>StopService</em></a><em>,</em> and others. The recommended way to use these services is to maintain a static property and reference the class <a href="http://msdn.microsoft.com/en-us/library/dd833084(VS.95).aspx#accessing_extension_services_from_application_code" target="_blank">accordingly</a>.</p>
</blockquote>
<p>Basically AES solve one problem: <em>How do I extend the global application class, without actually replacing it, i.e. without providing a derived class?</em></p>
<blockquote><p>The problem here is that many libraries need some kind of global anchor and in the past, tool developers often chose to provide this by subclassing the next available central artifact (e.g. the page class or the application). And the next tool developer doing the same rendered those two libraries mutually exclusive, just by employing an adverse implementation strategy.</p>
</blockquote>
<p>However, SL3 solves only the <em>providing </em>part of the equation, the part related to the application class and the instantiation of the AES. But look <a href="http://ajdotnet.wordpress.com/2009/11/08/silverlight-bitspieces-part-7-application-permissions/" target="_blank">again</a> at the <em>consumer</em> code:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_checksecurity.jpg" /> </p>
<p>Following the <a href="http://msdn.microsoft.com/en-us/library/dd833084(VS.95).aspx#accessing_extension_services_from_application_code" target="_blank">recommendations</a>, I get singleton access to some object. Worse, the calling code is directly and tightly coupled to the AES class. But frankly, do I need SL3 to implement a singleton? Certainly not. Then why use AES in the first place? </p>
<p>What I’d love is to have the consumer code depend on some service (read interface), not on the actual implementation. And the ability to swap those services in and out, without affecting the caller. Matter of fact, the calling code doesn’t and shouldn’t care whether I use a <em>SecurityServiceThatGetsItsInformationFromTheServer </em>or a <em>SecurityServiceThatGetsItsInformationFromWindowsAzure </em>(or google account, open id, whatever).</p>
<p>If I could get that, AES would become a very valuable feature… .&#160; </p>
<p><strong>Introducing Service Providers</strong></p>
<p>OK, what the calling code needs is some service in terms of a contract, say <em>ISecurityService</em>, that it can ask for. And the same is true for any crosscutting concern, such as error reporting, tracing, caching, you name it. And actually .NET has already addressed this need with the <a href="http://msdn.microsoft.com/en-us/library/system.iserviceprovider(VS.95).aspx" target="_blank">service provider pattern</a>. This pattern has been used for example <a href="http://msdn.microsoft.com/en-us/library/ms734738.aspx" target="_blank">in WF</a> (e.g. to introduce workflow instance persistence), and <a href="http://msdn.microsoft.com/en-us/library/ms171822.aspx" target="_blank">quite extensively</a> in the Visual Studio <a href="http://msdn.microsoft.com/de-de/magazine/cc163634(en-us).aspx" target="_blank">design time infrastructure</a>.</p>
<blockquote><p>OK, I can hear you crying out <a href="http://en.wikipedia.org/wiki/Dependency_Injection" target="_blank">DI</a>. And the chorus chanting <a href="http://msdn.microsoft.com/en-us/library/dd362339.aspx" target="_blank">Unity</a> or <a href="http://ninject.org/" target="_blank">Ninject</a> (to name just two that support SL). But think again. Would you (or rather a library developer) mandate a specific DI container without reason? And you can always wire your pet container into this pattern by providing a <em>IFactory </em>service using whatever container you like. After all, the pattern handles <em>access </em>to services, not <em>instantiation </em>of them. (Which is what AES does, but again, Microsoft chose not to provide a fully fledged DI container…)</p>
</blockquote>
<p>What do I need to make this approach tick? I need a <em>GetService </em>method that iterates all AES – they are available via <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.application.applicationlifetimeobjects(VS.95).aspx" target="_blank">Application.ApplicationLifetimeObjects</a></em>. And I need something to attach this method to. Using an extension method I can actually attach it to the application class:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_getservice.jpg" /></p>
<p>The method iterates all AES, checks whether one implements the requested (interface) type. It also checks whether any AES itself follows the pattern and implements <em>IServiceProvider, </em>and respectively forwards the request if it does. (This allows me to build up a chain of providers.)</p>
<p>That’s it. Long talk, short implementation, all set <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><strong>Reimplementing the SecurityService</strong></p>
<p>Now I need the rework the SecurityService and the calling code to comply with the pattern. The service interface is simple enough:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_interface.jpg" /> </p>
<p>And my revised security service looks like this:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_service2.jpg" /> </p>
<p>The base class <em>ApplicationServiceBase </em>implements the two interfaces with respective empty virtual methods, thus I only had to overwrite <em>StartService</em>. Aside from some reformatting the most notable difference with the <a href="http://ajdotnet.wordpress.com/2009/11/08/silverlight-bitspieces-part-7-application-permissions/" target="_blank">previous implementation</a> is the absence of the static <em>Current </em>property to access the service instance at runtime. I also renamed the class to reflect what it does. Since the calling code won’t refer to that name any more, this is now feasible.</p>
<p>Accessing the service at runtime is done – drum roll please – using the service provider pattern. This (admittedly not exactly nice) code can be hidden in a simple static property, adding a little convenience. I did this with a class that provides a static property, but also allows calling an extension method on the <em>Application </em>class:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_zugriff1.jpg" /></p>
<blockquote><p>BTW: Wouldn’t it be nice to have <a href="http://ajdotnet.wordpress.com/2008/02/10/extensively-using-extension-methods/" target="_blank">extension properties</a> that I could attach to the application class…?</p>
</blockquote>
<p>And the calling code, i.e. the access to the user object changes to:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_verwendung1.jpg" />&#160; </p>
<p>Now the calling code is completely decoupled from the actual implementation of the security service, meaning I could replace it without affecting the calling code.</p>
<p><strong>A look ahead: Building on the pattern</strong></p>
<p>There are several use cases for this pattern that I will employ (they may or may not be addressed in later posts, but at least this list should give you some ideas):</p>
<ul>
<li>Last chance exception handling: A service will react to the <a href="http://msdn.microsoft.com/en-us/library/system.windows.application.unhandledexception(VS.95).aspx" target="_blank">unhandled exception event</a> and gather context information. It will then use another service to report the error. </li>
<li>Message boxes: I will need message boxes for errors, information, and confirmation. The system <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.messagebox(VS.95).aspx" target="_blank">MessageBox</a> </em>is however somewhat dull. A service will cover that and a later implementation will replace the boring system dialogs with nice and shiny replacements. </li>
<li>Logging and tracing: At some point I will have to tackle these demands. </li>
<li>… </li>
</ul>
<p>I’m sure you can think of other examples, like navigation with parameter passing, global state, caching, …. Anyway, I think this is motivation enough to roll out some additional infrastructure. </p>
<blockquote><p>As a side note: Actually I had a completely homegrown implementation of this pattern for SL2. When SL3 came out and offered AES I quickly jumped on the bandwagon and threw away most of that code. If only Microsoft had not stopped one step short of my needs… . I’d rather have the platform support that out-of-the-box. And given the simplicity of the remaining implementation this shouldn’t have been too much of an issue.</p>
</blockquote>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2009/11/14/silverlight-bitspieces-part-8-application-extensions/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/11/14/silverlight-bitspieces-part-8-application-extensions/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, C#, Silverlight, Software Architecture, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/629/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/629/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/629/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/629/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/629/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/629/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/629/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/629/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/629/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/629/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/629/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/629/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/629/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/629/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=629&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/11/14/silverlight-bitspieces-part-8-application-extensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_checksecurity.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_getservice.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_interface.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_service2.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_zugriff1.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_verwendung1.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/11/14/silverlight-bitspieces-part-8-application-extensions/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Bits&amp;Pieces &#8211; Part 7: Application Permissions</title>
		<link>http://ajdotnet.wordpress.com/2009/11/08/silverlight-bitspieces-part-7-application-permissions/</link>
		<comments>http://ajdotnet.wordpress.com/2009/11/08/silverlight-bitspieces-part-7-application-permissions/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 18:55:23 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=612</guid>
		<description><![CDATA[OK, back down from vacation – proud about the accomplishment and perhaps with some new perspectives. It really makes you think about the effects of the financial crisis if you happen to work primarily for banks… . Well. Note: This is part of a series, you can find the related posts here… The last post [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=612&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>OK, back <a href="http://en.wikipedia.org/wiki/Mount_Kilimanjaro" target="_blank">down from vacation</a> – proud about the accomplishment and perhaps with some <a href="http://www.nation.co.ke/News/-/1056/672082/-/uo06q9/-/index.html" target="_blank">new perspectives</a>. It really makes you think about the <a href="http://www.ifpri.org/publication/2009-global-hunger-index-facts-and-findings-sub-saharan-africa-east-africa" target="_blank">effects of the financial crisis</a> if you happen to work primarily for banks… . Well.</p>
<blockquote><p>Note: This is part of a series, you can find the related posts <a href="http://ajdotnet.wordpress.com/category/silverlight/" target="_blank">here</a>…</p></blockquote>
<p>The last post (pre-Kili <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) provided me with the necessary infrastructure to address the next topic: application security.</p>
<p>Silverlight is “secure by design”. It runs in a sandbox, only allowing restricted access to the local machine. Regarding server calls it supports HTTPS and windows authentication for intranets, it restricts <a href="http://msdn.microsoft.com/en-us/library/cc189008(VS.95).aspx" target="_blank">URL access</a> and allows only calls to servers explicitly <a href="http://msdn.microsoft.com/en-us/library/cc645032(VS.95).aspx" target="_blank">opted in for</a>. From a .NET perspective it has a <a href="http://blogs.msdn.com/shawnfa/archive/2007/05/09/the-silverlight-security-model.aspx" target="_blank">changed programming model</a>, no longer supporting <a href="http://msdn.microsoft.com/en-us/library/930b76w0(VS.71).aspx" target="_blank">CAS</a>, but a more simple model that takes the restrictions into account that are already in place. It has the well-known interfaces <em><a href="http://msdn.microsoft.com/en-us/library/system.security.principal(VS.95).aspx" target="_blank">IPrincipal and IIdentity</a></em><em> </em>in place, yet no implementation and no anchor to ask for them, like <em><a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx" target="_blank">HttpContext.User</a> </em>in web applications.</p>
<p><em>Silverlight is so secure, it doesn’t even tell you, who you are.</em></p>
<p>From a purely technical perspective this is perfectly in order. The services I call are running on the server and it’s their job to make sure no one does something or gets to know something he isn’t entitled to.<br />
On the other hand, many intranet applications need to know the user name, if only to display it. And they need the permissions granted to the user to hide buttons, menu entries or make edit fields read only – none of that for actual security reasons (the server would take care that the user couldn’t do any harm, anyway), but to improve the user experience, not letting him do things and telling him afterwards that he has had no permission to do what he did in the first place.</p>
<p>User and roles are available at the server at the ASP.NET runtime, and one “only” needs to make it available to the client. Matter of fact, ASP.NET provides the necessary service implementation <a href="http://blogs.msdn.com/brada/archive/2008/05/03/accessing-the-asp-net-authentication-profile-and-role-service-in-silverlight.aspx" target="_blank">readily available</a>. This is also the way to integrate with ASP.NET forms authentication.</p>
<p>There are two caveats with this approach, though: These ASP.NET services provide roles and all, but they just don’t include the user name. Also, being services, I would have to call them asynchronously, which would incur at least a little time lag after starting the application, that I would have to deal with. A time lag that is unnecessary in intranet applications where the user is determined by windows authentication.</p>
<p>Thus my solution is as follows:</p>
<ol>
<li>On the server include the information about user name and his roles in the <em>initparams</em>, so that it is available for the SL application right form the start, without any lag.</li>
<li>On the client pick up that information and mimic <em><a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx" target="_blank">HttpContext.User</a> </em>to have a similar developer experience.</li>
</ol>
<blockquote><p>Of course, someone could fake this data, which might at first glance be a security flaw. But as I said, this information is only used to improve the user experience. Even if someone masqueraded as a different user, the sandbox on the client side still uses the actual user’s restrictions. And the same is true for the services that still have the responsibility to enforcing security anyway. I’m also not revealing sensitive information, since user name and permissions are not exactly protected data. And finally I could load the web page containing this data via HTTPS. Thus, form a security perspective I’m on the save side.</p></blockquote>
<p><strong>Server side</strong></p>
<p>The server side is easy enough, since the necessary work has already been done. Step one is to include the information in the initparams within the ASP.NET page:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/asp_initparams.jpg" alt="" /></p>
<p>Step to is the respective implementation:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_getuserinformation.jpg" alt="" /> </p>
<p><strong>Client side</strong></p>
<p>Mimic <em>HttpContext.User? </em>Well, there is no <em><a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx" target="_blank">HttpContext</a></em>, but we have the <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.application(VS.95).aspx" target="_blank">Application</a></em> object which can be seen as a pendant of sorts. (I wouldn’t relate it to the <em><a href="http://msdn.microsoft.com/en-us/library/system.web.httpapplication.aspx" target="_blank">HttpApplication</a></em>, though, since an application in the ASP.NET sense spans all users.) Yet I’m reluctant to provide a base class to inject my pet feature, because that would bring me into conflict with any other library that may one day choose to do the same.</p>
<p>Luckily SL3 introduced the new concept of <a href="http://msdn.microsoft.com/en-us/library/dd833084(VS.95).aspx" target="_blank">Application Extension Services</a> (AES for short). AES have to implement <a href="http://msdn.microsoft.com/en-us/library/system.windows.iapplicationservice(VS.95).aspx" target="_blank">a simple interface</a> and are registered via the <em>app.xaml</em>. SL3 instantiates them and calls the <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.iapplicationservice.startservice(VS.95).aspx" target="_blank">StartService</a></em> and <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.iapplicationservice.stopservice(VS.95).aspx" target="_blank">StopService</a></em> method to provide the hooks for initialization and shutdown. There will be another post about AES, thus I’ll leave it at that for now. Anyway, here’s the respective implementation:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_securityservice.jpg" alt="" /></p>
<p>It’s straight forward, it merely parses the information provided via the <em>initparams</em>. And the registration that will create the service at runtime is quite simple:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/xaml_application.jpg" alt="" /></p>
<p>This is backed by boilerplate implementations of <em>IPrincipal</em>…</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_principal.jpg" alt="" /></p>
<p>… and <em>IIdentity</em>:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_identity.jpg" alt="" /></p>
<p>From here I can use the user information at leisure, as I need it, and as I’m used to do. For example:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/11/code_checksecurity.jpg" alt="" /> </p>
<p><span style="color:#008000;">That’s all for now folks,<br />
<strong>AJ.NET</strong></span></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2009/11/08/silverlight-bitspieces-part-7-application-permissions/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/11/08/silverlight-bitspieces-part-7-application-permissions/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, C#, Silverlight, Software Architecture, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/612/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/612/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/612/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/612/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/612/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/612/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/612/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/612/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/612/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/612/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/612/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/612/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/612/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/612/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=612&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/11/08/silverlight-bitspieces-part-7-application-permissions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/asp_initparams.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_getuserinformation.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_securityservice.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/xaml_application.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_principal.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_identity.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/11/code_checksecurity.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/11/08/silverlight-bitspieces-part-7-application-permissions/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>das erste B&#252;rgerrecht&#8230; [MOVED]</title>
		<link>http://ajdotnet.wordpress.com/2009/10/07/das-erste-brgerrecht/</link>
		<comments>http://ajdotnet.wordpress.com/2009/10/07/das-erste-brgerrecht/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 08:44:40 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=590</guid>
		<description><![CDATA[Moved: http://alexanderj.wordpress.com/2009/10/07/das-erste-buergerrecht/ Posted in Miscellaneous<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=590&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Moved: <a href="http://alexanderj.wordpress.com/2009/10/07/das-erste-buergerrecht/">http://alexanderj.wordpress.com/2009/10/07/das-erste-buergerrecht/</a></p>
<br />Posted in Miscellaneous  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/590/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/590/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/590/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/590/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/590/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/590/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/590/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/590/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/590/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/590/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/590/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/590/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/590/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/590/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=590&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/10/07/das-erste-brgerrecht/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Bits&amp;Pieces &#8211; Part 6: Application Configuration</title>
		<link>http://ajdotnet.wordpress.com/2009/10/03/silverlight-bitspieces-part-6-application-configuration/</link>
		<comments>http://ajdotnet.wordpress.com/2009/10/03/silverlight-bitspieces-part-6-application-configuration/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 14:53:45 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=587</guid>
		<description><![CDATA[Note: This is part of a series, you can find the related posts here… Configuration of ASP.NET applications is quite potential. Simple application settings, database connection strings, complex configuration data. All editable by the administrator after deployment. Configuration of SL applications is virtually non-existent. While a Silverlight application may have less need for configuration than [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=587&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is part of a series, you can find the related posts <a href="http://ajdotnet.wordpress.com/category/silverlight/" target="_blank">here</a>…</p>
</blockquote>
<p>Configuration of ASP.NET applications is quite potential. Simple application settings, database connection strings, complex configuration data. All editable by the administrator <em>after </em>deployment.</p>
<p><em>Configuration of SL applications is virtually non-existent. </em></p>
<p>While a Silverlight application may have less need for configuration than a web application – part of the logic still remains server side in respective services anyway – it’s not as if there is no need at all. </p>
<p>The service URLs (or a base URL) themselves, for example. Service proxies are created with the very URL that was used to provide the meta information baked into the code. Since this is probably a local address on the developers machine it needs to be adjusted during runtime. And preferably the administrator should be able to reconfigure the SL application if the service URL changes.    <br />Other use cases include the usual: Whatever you want to put in some <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx" target="_blank">appSettings</a> replacement. Enabling debug features. Just have a look at your last web application’s configuration and you’ll probably find some good candidates.</p>
<p><strong>Silverlight configuration</strong></p>
<p>Looking at the object tag for a Silverlight control on a web page (the ASP.NET <a href="http://msdn.microsoft.com/en-us/library/cc838274(VS.95).aspx" target="_blank">server side control</a> we had with SL2 is gone with SL3), there is some technical parameterization available:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/10/asp_objecttag1.jpg" /> </p>
<p>You can find a complete list of available parameters <a href="http://msdn.microsoft.com/en-us/library/cc838259(VS.95).aspx" target="_blank">here and below</a>. </p>
<p>Of particular interest right now is the <a href="http://msdn.microsoft.com/en-us/library/cc838255(VS.95).aspx" target="_blank">initParams</a> property. It allows me to pass arbitrary information to the SL client. It is however not suited to be maintained by an administrator, as I certainly don’t want him to mangle my web page. However nobody says I cannot provide code that reads the information from somewhere else, like so:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/10/asp_objecttag2.jpg" /> </p>
<p>and the respective code, obviously intended to read in the contents of a config file:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/10/asp_script.jpg" /> </p>
<p>That config file is a simple analogon to the standard ASP.NET <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx" target="_blank">appSettings</a>:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/10/xml_config.jpg" />&#160; </p>
<blockquote><p>Note: I could have returned the web.config appSettings section. Yet using a separate file helps keeping client and server configuration cleanly separated.</p>
</blockquote>
<p>So, what’s left is the actual implementation of that <em>InitParams </em>class, I’ve been using…</p>
<p><strong>Implementation </strong></p>
<p>The <em>InitParams </em>class is merely a little helper, providing a fluent interface over a dictionary and convenience methods, as I needed them:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/10/code_initparams1.jpg" /> </p>
<p>Reading the config file is equally simple with XLinq at our disposal:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/10/code_initparams2.jpg" /> </p>
<p>And I will complement that with additional helpers in upcoming posts.</p>
<p><strong>What’s it worth?</strong></p>
<p>So now I have the ability to provide configuration to my client, the information readily available to be picked up <a href="http://msdn.microsoft.com/en-us/library/system.windows.startupeventargs_properties(VS.95).aspx" target="_blank">during the startup event</a> or anytime from <a href="http://msdn.microsoft.com/en-us/library/system.windows.interop.silverlighthost.initparams(VS.95).aspx" target="_blank">Application.Host</a>. For simple values I have the configuration file, for other information I can extend my helper class anytime I want (and I will!), the infrastructure is there.</p>
<p>Could that have been done otherwise? Well, a respective services would have been another option. But providing the information via the <em>initparams</em> has the advantage of being readily available to the client without delay. And configuring the configuration service via the configuration service…? Well.</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f10%2f03%2fsilverlight-bitspieces-part-6-application-configuration%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f10%2f03%2fsilverlight-bitspieces-part-6-application-configuration%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, C#, Silverlight, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/587/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/587/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/587/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/587/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/587/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/587/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/587/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=587&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/10/03/silverlight-bitspieces-part-6-application-configuration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/10/asp_objecttag1.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/10/asp_objecttag2.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/10/asp_script.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/10/xml_config.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/10/code_initparams1.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/10/code_initparams2.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f10%2f03%2fsilverlight-bitspieces-part-6-application-configuration%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Die gr&#246;&#223;te Gefahr f&#252;r unseren Rechtsstaat&#8230; [MOVED]</title>
		<link>http://ajdotnet.wordpress.com/2009/09/29/die-grte-gefahr-fr-unseren-rechtsstaat/</link>
		<comments>http://ajdotnet.wordpress.com/2009/09/29/die-grte-gefahr-fr-unseren-rechtsstaat/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 15:11:26 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=579</guid>
		<description><![CDATA[Moved: http://alexanderj.wordpress.com/2009/09/29/die-groesste-gefahr-fuer-unseren-rechtsstaat/ Posted in Miscellaneous<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=579&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Moved: <a href="http://alexanderj.wordpress.com/2009/09/29/die-groesste-gefahr-fuer-unseren-rechtsstaat/">http://alexanderj.wordpress.com/2009/09/29/die-groesste-gefahr-fuer-unseren-rechtsstaat/</a></p>
<br />Posted in Miscellaneous  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/579/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=579&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/09/29/die-grte-gefahr-fr-unseren-rechtsstaat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>PDC 08 &#8211; Recap</title>
		<link>http://ajdotnet.wordpress.com/2009/09/27/pdc-08-recap/</link>
		<comments>http://ajdotnet.wordpress.com/2009/09/27/pdc-08-recap/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 12:13:26 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Software Developers]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=575</guid>
		<description><![CDATA[So, PDC09 is not far away. But, sadly, I’m not going to make it this time. I had thought for a longer time about posting some pictures from PDC08 as kind of a retrospective – but you know how it is, other things coming up, not much time, well. And then this nut showed up, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=575&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img style="display:inline;margin:0 0 5px 5px;" align="right" src="http://ajdotnet.files.wordpress.com/2009/09/pdc09.png" />So, PDC09 is not far away. But, sadly, I’m not going to make it this time. </p>
<p>I had thought for a longer time about posting some pictures from PDC08 as kind of a retrospective – but you know how it is, other things coming up, not much time, well.</p>
<p>And then this nut showed up, hijacked my blog and posted this nonsense about some crime that should have happened last PDC? Come on! Here’s the list of what I can only call a real good example of real dumb accusations:</p>
<ul>
<li><a href="http://ajdotnet.wordpress.com/2009/08/31/pdc08-the-unrevealed-crime-part-1/" target="_blank">PDC08 – the unrevealed crime</a> (featuring <a href="http://en.wikipedia.org/wiki/Anders_Hejlsberg" target="_blank">Anders Hejlsberg</a>) </li>
<li><a href="http://ajdotnet.wordpress.com/2009/09/03/pdc08-the-crime-part-2-management-panics/" target="_blank">Part 2: Management Panics</a> (featuring <a href="http://en.wikipedia.org/wiki/Ray_Ozzie" target="_blank">Ray Ozzie</a>) </li>
<li><a href="http://ajdotnet.wordpress.com/2009/09/05/pdc08-the-crime-part-3-early-responses/" target="_blank">Part 3: Early Responses</a> (featuring <a href="http://www.microsoft.com/presspass/exec/bobmuglia/" target="_blank">Bob Muglia</a>, <a href="http://en.wikipedia.org/wiki/Steven_Sinofsky" target="_blank">Steven Sinofski</a>, and others) </li>
<li><a href="http://ajdotnet.wordpress.com/2009/09/12/pdc08-the-crime-part-4-one-special-response/" target="_blank">Part 4: One Special Response</a> (featuring <a href="http://www.simplegeek.com/" target="_blank">Chris Anderson</a> and <a href="http://en.wikipedia.org/wiki/Don_Box" target="_blank">Don Box</a>) </li>
<li><a href="http://ajdotnet.wordpress.com/2009/09/13/pdc08-the-crime-part-5-the-investigation/" target="_blank">Part 5: The Investigation</a> (featuring <a href="http://channel9.msdn.com/" target="_blank">Channel 9</a> and the audience!) </li>
<li><a href="http://ajdotnet.wordpress.com/2009/09/18/pdc08-the-crime-part-6-a-copy-cat/" target="_blank">Part 6: A Copy Cat</a> (featuring <a href="http://en.wikipedia.org/wiki/Scott_Guthrie" target="_blank">Scott Guthrie</a>) </li>
<li><a href="http://ajdotnet.wordpress.com/2009/09/19/pdc08-the-crime-part-7-the-revelation/" target="_blank">Part 7: The Revelation</a> (featuring <a href="http://www.microsoft.com/presspass/exec/bobmuglia/" target="_blank">Bob Muglia</a> again) </li>
<li><a href="http://ajdotnet.wordpress.com/2009/09/21/pdc08-the-crime-part-8-the-guilty/" target="_blank">Part 8: The Guilty</a> (featuring <a href="http://en.wikipedia.org/wiki/Don_Box" target="_blank">Don Box</a> – <em>talk about </em><a href="http://www.tonysneed.com/media/DonBoxBath.wmv" target="_blank"><em>nuts</em></a>) </li>
<li><a href="http://ajdotnet.wordpress.com/2009/09/26/pdc08-the-crime-part-9-aftermath/" target="_blank">Part 9: Aftermath!</a> (featuring <a href="http://microsoftpdc.com/" target="_blank">PDC</a>, <a href="http://en.wikipedia.org/wiki/Los_Angeles" target="_blank">L.A.</a> and <a href="http://en.wikipedia.org/wiki/Halloween" target="_blank">Halloween</a>) </li>
</ul>
<p>Let me stress that again: <em>There is no proof whatsoever to this story! As I see it, all these accusations are groundless, all people addressed are innocent victims. So, please, do not accuse anyone of installing LINUX on somebody&#8217;s machine if you don’t have proof. Much less on the grounds of this story! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </em></p>
<p>All that remains for me is some complementary pictures:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/09/img_1148_400.jpg" />&#160;<a href="http://ajdotnet.wordpress.com/2008/12/20/explaining-azure/" target="_blank">Windows Azure</a> was THE big announcement at PDC08, and it’s going to be one of the major topic for PDC09. Microsoft really <a href="http://ajdotnet.wordpress.com/2008/11/16/about-azure/" target="_blank">has something</a> here that might change a lot in the long run. <em>If </em>they remove the two road blockers, that is: One, they need to make this infrastructure available for enterprise customers to lower the barrier to entry. Two, they need to do what they always did: attract developers and create a prosperous community of enthusiasts around Azure. To achieve that, they need to <a href="http://www.microsoft.com/azure/pricing.mspx" target="_blank">offer the platform for free</a>. All with reasonable constraints of course. And this is just my opinion.&#160;&#160;&#160; </p>
<p>&#160;</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/09/img_1078_400.jpg" /> Oslo, and M, was another major topic. But I can’t help thinking that this was mainly because it was the “Don Box-Topic”. It’s been relatively quiet around it since then, and unfortunately this also includes the somewhat related “Dublin”, which I think is a very important step in the services area.</p>
<p>&#160;</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/09/img_1146_400.jpg" /> Hands-On-Labs was as always the best way to lay your hands on the stuff you heard about for the first time just this very morning. <em>If </em>you had the time.</p>
<p>&#160;</p>
<p>Talking about the location, the first and the last thing you saw about PDC was L.A. …</p>
<p>&#160;</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/09/img_0940_400.jpg" /> the Convention Center…</p>
<p>&#160;</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/09/img_0955_400.jpg" /> … and if you didn’t use the shuttle system, it was probably Pico Station, featuring a great view at <a href="http://en.wikipedia.org/wiki/Downtown_Los_Angeles" target="_blank">Downtown</a>.</p>
<p><em>However</em>, I have been attending 3 PDCs so far, all of them in L.A. I’d really like to see some other city next time? (Microsoft, I could give you a list of areas in the U.S., I haven’t visited so far <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ). </p>
<p>So much for my little retrospective. CU at PDC<em>next</em>… . </p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f09%2f27%2fpdc-08-recap%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f09%2f27%2fpdc-08-recap%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in Fun, Miscellaneous, Software Developers  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/575/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=575&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/09/27/pdc-08-recap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.tonysneed.com/media/DonBoxBath.wmv" length="5057503" type="video/x-ms-wmv" />
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc09.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/img_1148_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/img_1078_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/img_1146_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/img_0940_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/img_0955_400.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f09%2f27%2fpdc-08-recap%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>PDC08 &#8211; THE CRIME Part 9: Aftermath!</title>
		<link>http://ajdotnet.wordpress.com/2009/09/26/pdc08-the-crime-part-9-aftermath/</link>
		<comments>http://ajdotnet.wordpress.com/2009/09/26/pdc08-the-crime-part-9-aftermath/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 12:40:14 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=565</guid>
		<description><![CDATA[Hi had barely recovered from the shock when I realized that I needed proof and witnesses if anyone was supposed to believe this story, and not dismiss it as a conspiracy theory. It was a foregone failure… I tried various channels:&#160;&#160; Officials didn’t know (or reveal) anything! &#160; Other attendees searched for some kind of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=565&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><font face="Comic Sans MS">Hi had barely recovered from the shock when I realized that I needed proof and witnesses if anyone was supposed to believe this story, and not dismiss it as a </font><a href="http://en.wikipedia.org/wiki/Conspiracy_theory" target="_blank"><font face="Comic Sans MS">conspiracy theory</font></a><font face="Comic Sans MS">. It was a foregone failure…</font></p>
<p><font face="Comic Sans MS">I tried various channels:&#160;&#160; </font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1057_400.jpg" /> Officials didn’t know (or reveal) anything!</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1058_400.jpg" /> Other attendees searched for some kind of evidence – no success either.</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1318_400.jpg" />&#160; </font><font face="Comic Sans MS">The local muscle knew nothing.</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1328_400.jpg" /> Law enforcement was as confused as I was.</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1083_400.jpg" /> When the PDC closed the doors for the last time, after sunset in L.A., I know that everything was lost.</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS">The next day was <a href="http://en.wikipedia.org/wiki/Halloween" target="_blank">October, 31st</a>, and I still remember </font><font face="Comic Sans MS">this strange girl, claiming to know something, but not really telling. Beyond some slightly insane giggle…</font></p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1311_400.jpg" /> </p>
<p>&#160;</p>
<p><font face="Comic Sans MS"></font></p>
<p><font face="Comic Sans MS"></font></p>
<p><font face="Comic Sans MS">PS: This is it. I told it all. Obviously I will not come to this years PDC, not to watch an even more horrid crime unfold. To those still planning to go there: I wish you all a good time and – above all – an uneventful stay and a save return home! </font></p>
<p align="right"><font color="#800000" face="Comic Sans MS">Anonymous</font></p>
<br />Posted in Fun  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/565/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/565/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/565/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/565/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/565/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/565/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/565/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/565/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/565/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/565/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/565/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/565/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/565/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/565/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=565&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/09/26/pdc08-the-crime-part-9-aftermath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1057_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1058_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1318_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1328_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1083_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1311_400.jpg" medium="image" />
	</item>
		<item>
		<title>PDC08 &#8211; THE CRIME Part 8: The Guilty</title>
		<link>http://ajdotnet.wordpress.com/2009/09/21/pdc08-the-crime-part-8-the-guilty/</link>
		<comments>http://ajdotnet.wordpress.com/2009/09/21/pdc08-the-crime-part-8-the-guilty/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 17:56:15 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=552</guid>
		<description><![CDATA[Hi there, I hope, you’ve recovered from the shock? If you’re like me, you’ll want those… those… seriously punished. Of course, due to the cover-up they couldn’t discipline them as they deserved. That would have caused to much public notice. But they found means, obviously,… . For one thing they gave each of them a… [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=552&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><font face="Comic Sans MS">Hi there, I hope, you’ve recovered from the shock? If you’re like me, you’ll want those… those… seriously punished. Of course, due to the cover-up <em>they </em>couldn’t discipline them as they deserved. That would have caused to much public notice. But <em>they </em>found means, obviously,… .</font></p>
<p><font face="Comic Sans MS">For one thing they gave each of them a… <em>mentor</em>.&#160; </font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1071_400.jpg" /> “Someone stole my belt…” “No Don, no one <em>stole </em>your belt!”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1072_400.jpg" /> </font><font face="Comic Sans MS">“Chris was supposed to be here but he ‘volunteered’ for toilet cleaning!” “Now Don, isn’t that nice? Doing something <em>positive</em>?”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS">Apparently Don didn’t take that all very good. He reverted to drinking…</font><font face="Comic Sans MS">&#160;</font></p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1073_400.jpg" /> </p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS">And then happened what made me shiver, and, ultimately, break the silence…&#160; </font><font face="Comic Sans MS">Don’s mood changed… </font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1074_400.jpg" /> “You know what?”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1075_400.jpg" /> “I just got a <em>wonderful </em>idea….” “Don? Don’t start something foolish. Again. You know what happened…” </font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1076_400.jpg" /> “YES! But you will not catch me NEXT TIME. Wait until PDC 09!”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS">I can tell you, I was in shock. I don’t remember how I got back to the hotel. My colleagues have been wondering about my apparent paranoia ever since then. I can’t help it, I always have this… image… of … LINUX … running on my … and that of other innocent and less prepared victims… oh no, I can’t take it no longer. I had to tell you and I’m sorry I had to give you nightmares. But you have to be prepared. Someone had to warn you… </font></p>
<p align="right"><strong><font color="#800000" face="Comic Sans MS">Anonymous</font></strong></p>
<p><font face="Comic Sans MS"></font></p>
<br />Posted in Fun  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/552/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/552/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/552/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/552/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/552/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/552/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/552/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=552&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/09/21/pdc08-the-crime-part-8-the-guilty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1071_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1072_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1073_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1074_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1075_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1076_400.jpg" medium="image" />
	</item>
		<item>
		<title>PDC08 &#8211; THE CRIME Part 7: The Revelation</title>
		<link>http://ajdotnet.wordpress.com/2009/09/19/pdc08-the-crime-part-7-the-revelation/</link>
		<comments>http://ajdotnet.wordpress.com/2009/09/19/pdc08-the-crime-part-7-the-revelation/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 12:16:54 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=543</guid>
		<description><![CDATA[Despite the the cover-up, they couldn’t prevent the public revelation. They most likely simply didn’t know what Bob had in mind when he entered the stage. Otherwise they would have done everything to restrain him. Anyway, finally he broke the silence. Not only did he reveal who was behind THE CRIME, but he also made [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=543&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><font face="Comic Sans MS">Despite the the cover-up, <em>they </em>couldn’t prevent the public revelation. <em>They </em>most likely simply didn’t know what Bob had in mind when he entered the stage. Otherwise <em>they </em>would have done everything to restrain him. </font></p>
<p><font face="Comic Sans MS">Anyway, finally he broke the silence. Not only did he reveal who was behind THE CRIME, but he also made clear how high this conspiracy ranked, if he himself knew about it&#8230;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_0999_400.jpg" /> “I, Bob M., do confess that I knew from the very beginning about…”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_0991_400.jpg" /> “Chris and Don are not bad people, really, …”</font></p>
<p><font face="Comic Sans MS">THERE! SEE! HE NAMED THEM! </font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_0992_4001.jpg" /> “… they are just misguided, maybe hung out with the wrong people…”</font></p>
<p><font face="Comic Sans MS">HE EVEN DEFENDS THEM!&#160; </font></p>
<p><font face="Comic Sans MS"></font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1000_400.jpg" /> “… we have to help them. Make them see the wrong in their doing.”</font></p>
<p><font face="Comic Sans MS"></font></p>
<p><font face="Comic Sans MS">Of course this part was cut out of the official recordings of the key notes. I also couldn’t ask him personally later on because he supposedly <em>started his vacation earlier than planned</em>. Yeah, right. But he is still alive, I mean, <em>they </em>didn’t go that far… so far.</font></p>
<p align="right"><strong><font color="#800000" face="Comic Sans MS">Anonymous</font></strong></p>
<p><font face="Comic Sans MS"></font></p>
<br />Posted in Fun  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/543/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/543/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/543/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/543/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/543/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/543/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/543/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/543/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/543/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/543/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/543/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/543/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/543/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/543/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=543&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/09/19/pdc08-the-crime-part-7-the-revelation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_0999_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_0991_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_0992_4001.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1000_400.jpg" medium="image" />
	</item>
		<item>
		<title>PDC08 &#8211; THE CRIME Part 6: A Copy Cat</title>
		<link>http://ajdotnet.wordpress.com/2009/09/18/pdc08-the-crime-part-6-a-copy-cat/</link>
		<comments>http://ajdotnet.wordpress.com/2009/09/18/pdc08-the-crime-part-6-a-copy-cat/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 18:51:11 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=535</guid>
		<description><![CDATA[By the time I was left out of custody the cover-up was firmly in place. It was really spooky. Hence not many attendees may have noticed the copy cat incident… “That hideous crime … scratch that, I’m not allowed to talk about that any longer. Anyway, I can live with LINUX. I mean, as long [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=535&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><font face="Comic Sans MS">By the time I was left out of custody the cover-up was firmly in place. It was really spooky. Hence not many attendees may have noticed the copy cat incident…</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1032_400.jpg" /> “That hideous crime … scratch that, I’m not allowed to talk about that any longer. Anyway, I can live with LINUX. I mean, as long as I can install Visual Studio it could be running on DOS….”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1033_400.jpg" /> “What… What is ‘Booting Linux Kernel’ supposed to mean?&#160; … Wait! Where’s my Visual Studio? …”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS">&#160;<img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1035_400.jpg" /> </font><font face="Comic Sans MS">Fortunately the forensics where still around. They secured the evidence and got the machine running in no time. Real pros, I have to say.</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1034_400.jpg" /> Later the “problem” was explained as some ‘glitch’ in an early Windows 7 version. (There was some talk about a run-in, Scott supposedly had with Steven later that day, but I could never confirm that.)</font></p>
<p><font face="Comic Sans MS">Stay tuned, I’m getting closer. You’ll never believe the truth… </font></p>
<p><font face="Comic Sans MS"></font></p>
<p align="right"><strong><font color="#800000" face="Comic Sans MS">Anonymous</font></strong></p>
<p><font face="Comic Sans MS"></font></p>
<br />Posted in Fun  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/535/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/535/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/535/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/535/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/535/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/535/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/535/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/535/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/535/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/535/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/535/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/535/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/535/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/535/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=535&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/09/18/pdc08-the-crime-part-6-a-copy-cat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1032_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1033_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1035_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1034_400.jpg" medium="image" />
	</item>
		<item>
		<title>PDC08 &#8211; THE CRIME Part 5: The Investigation</title>
		<link>http://ajdotnet.wordpress.com/2009/09/13/pdc08-the-crime-part-5-the-investigation/</link>
		<comments>http://ajdotnet.wordpress.com/2009/09/13/pdc08-the-crime-part-5-the-investigation/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 13:06:22 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=527</guid>
		<description><![CDATA[Nobody around? OK. It’s not that I’m paranoid. OK, I may be a … well, that doesn’t mean they’re not… . But the following may explain…. Anyway, it was not long until the professionals arrived. Some forensics specialists… &#160; Some, let’s call them detectives,… – see that innocent looking guy right in front? Did you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=527&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><font face="Comic Sans MS">Nobody around? OK. It’s not that I’m </font><a href="http://en.wikipedia.org/wiki/Paranoid_(song)" target="_blank"><font face="Comic Sans MS">paranoid</font></a><font face="Comic Sans MS">. OK, I may be a … well, that doesn’t mean they’re not… . But the following may explain….</font></p>
<p><font face="Comic Sans MS">Anyway, it was not long until the professionals arrived.</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1144_400.jpg" /> Some forensics specialists… </font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/img_0967_400.jpg" /> Some, let’s call them <em>detectives</em>,… – see that innocent looking guy right in front? Did you notice that he is obviously watching the audience in front of him, rather than what’s going on on the stage? See? And two rows behind him, probably his assistant, looking directly at ME?&#160;&#160; </font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_0976_400.jpg" /> But most important was </font><a href="http://en.wikipedia.org/wiki/The_Arrival_(film)" target="_blank"><font face="Comic Sans MS">the arrival</font></a><font face="Comic Sans MS"> of THE INVESTIGATOR. Nobody knew him. At first nobody even knew he was there; he was inconspicuous to the point of invisibility. But he had a reputation of sneaking up on the criminal and put him in handcuffs before I even knows what happened to him… me… </font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1023_400.jpg" /> He would spot the suspect in a crowd like a blood hound. Hunt him down… hunt me… OH NO!!</font></p>
<p><font face="Comic Sans MS">&#160; </font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1124_400.jpg" /> … and finally confront me. “Excuse me?… … Who me, sir?… … No sir, I know nothing about no LIN… uhm… what did you call that?”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS">I took a while and I had to admit some of my lesser crimes (like installing </font><a href="http://en.wikipedia.org/wiki/OS/2" target="_blank"><font face="Comic Sans MS">OS/2</font></a><font face="Comic Sans MS"> when I was young, or </font><a href="http://www.youtube.com/watch?v=tKEgINHXQds" target="_blank"><font face="Comic Sans MS">laughing at Bill Gates</font></a><font face="Comic Sans MS">), but finally I could convince him that I was an innocent bystander. Yet I still shudder from the experience…. It was so…. Sorry, I’m too stirred up right now to continue…</font></p>
<p align="right"><strong><font color="#800000" face="Comic Sans MS">Anonymous</font></strong></p>
<p align="right"><strong><font color="#800000" face="Comic Sans MS"></font></strong></p>
<p align="right"><strong><font color="#800000" face="Comic Sans MS"></font></strong></p>
<p><font face="Comic Sans MS"></font></p>
<p><font face="Comic Sans MS"></font></p>
<p><font face="Comic Sans MS"></font></p>
<p><font face="Comic Sans MS"></font></p>
<p><font face="Comic Sans MS"></font></p>
<p><font face="Comic Sans MS"></font></p>
<p><font face="Comic Sans MS"></font></p>
<br />Posted in Fun  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/527/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=527&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/09/13/pdc08-the-crime-part-5-the-investigation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1144_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/img_0967_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_0976_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1023_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1124_400.jpg" medium="image" />
	</item>
		<item>
		<title>PDC08 &#8211; THE CRIME Part 4: One Special Response</title>
		<link>http://ajdotnet.wordpress.com/2009/09/12/pdc08-the-crime-part-4-one-special-response/</link>
		<comments>http://ajdotnet.wordpress.com/2009/09/12/pdc08-the-crime-part-4-one-special-response/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 14:58:49 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=520</guid>
		<description><![CDATA[Still about the initial reaction… . There where two guys especially concerned. Who would have thought… – but I don’t want to tell too much yet. “This is plain disgusting…” “Oh yeah!” &#160; &#160; “Could you imagine something more vile?” “No never. Do you think they’ll catch him?” &#160; &#160; “No, I don’t think so. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=520&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><font face="Comic Sans MS">Still about the initial reaction… . There where two guys especially concerned. Who would have thought… – but I don’t want to tell too much yet.</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1047_400.jpg" /> “This is plain <em>disgusting</em>…” “Oh yeah!”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1048_400.jpg" />&#160; “Could you imagine something more vile?” “No never. Do you think they’ll catch him?”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1049_400.jpg" />&#160; “No, I don’t think so. They’ll never find out that w…” <font size="1"><em><strong>“Uhmm!”</strong></em></font> “… ahm, I mean, we will never find out who did it!” <font size="1">”He he.” “YES!”</font></font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1050_400.jpg" /> “Oh, I’m still sooo shocked.“ “I have no words…” </font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1051_400.jpg" /> “Let’s write some letter of condolence…” “OK, shot! I’ll write.” “You can’t write.” “Yes, I can!” “OK…”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1052_400.jpg" /> “Dear Mr. Assassin…” “D-e-a-r… M… where is the M…” </font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS">I was deeply move by such caring guys. It was really touching. </font></p>
<p><font face="Comic Sans MS">But soon thereafter the whole affair became dirty. <em>But I’d better switch my location again…</em></font></p>
<p align="right"><strong><font color="#800000" face="Comic Sans MS">Anonymous</font></strong></p>
<p><font face="Comic Sans MS"></font></p>
<br />Posted in Fun  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/520/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=520&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/09/12/pdc08-the-crime-part-4-one-special-response/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1047_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1048_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1049_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1050_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1051_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1052_400.jpg" medium="image" />
	</item>
		<item>
		<title>PDC08 &#8211; THE CRIME Part 3: Early Responses</title>
		<link>http://ajdotnet.wordpress.com/2009/09/05/pdc08-the-crime-part-3-early-responses/</link>
		<comments>http://ajdotnet.wordpress.com/2009/09/05/pdc08-the-crime-part-3-early-responses/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 19:26:17 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=511</guid>
		<description><![CDATA[… that was false alarm. This time. Anyway, about the reactions I managed to catch: “What on earth is a human being thinking, installing LINUX on a machine of an innocent person…” &#160; “… never understood those freaks. Must be some personality disorder…” &#160; “You heard what happened?” “Yes, I was told that there were [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=511&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><font face="Comic Sans MS">… that was false alarm. This time. </font></p>
<p><font face="Comic Sans MS">Anyway, about the reactions I managed to catch: </font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_0992_400.jpg" /> “What on earth is a human being thinking, installing LINUX on a machine of an innocent person…”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_0990_400.jpg" /> <font face="Comic Sans MS">“… never understood those freaks. Must be some personality disorder…”</font></p>
<p>&#160;</p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1015_400.jpg" /> “You heard what happened?” “Yes, I was told that there were three of them…” “Hush, they’re going to cover-up. This is a marketing disaster.”</font></p>
<p><font face="Comic Sans MS">&#160; </font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_1027_400.jpg" /> “Now personally I can understand that someone would get rid of Vista. But Anders actually had Windows 7 running and THAT is the real crime here….”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS">There were some more reactions, but I have to leave… </font></p>
<p align="right"><strong><font color="#800000" face="Comic Sans MS">Anonymous</font></strong></p>
<p><font face="Comic Sans MS"></font></p>
<br />Posted in Fun  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/511/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/511/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/511/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/511/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/511/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/511/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/511/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=511&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/09/05/pdc08-the-crime-part-3-early-responses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_0992_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_0990_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1015_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_1027_400.jpg" medium="image" />
	</item>
		<item>
		<title>PDC08 &#8211; THE CRIME Part 2: Management Panics</title>
		<link>http://ajdotnet.wordpress.com/2009/09/03/pdc08-the-crime-part-2-management-panics/</link>
		<comments>http://ajdotnet.wordpress.com/2009/09/03/pdc08-the-crime-part-2-management-panics/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 17:15:34 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=502</guid>
		<description><![CDATA[OK, I’m back. Nobody is watching me… right now…, so I can reveal some more information. Just after the incident nobody thought about cover-up. That came later. Rather THE CRIME quickly got management attention. The shock obviously went deep. “My dear friends. Before I get to the finest newest technology in the world, I have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=502&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><font face="Comic Sans MS">OK, I’m back. Nobody is watching me… right now…, so I can reveal some more information.</font></p>
<p><font face="Comic Sans MS">Just after the incident nobody thought about cover-up. That came later. Rather THE CRIME quickly got management attention. The shock obviously went deep.</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_0984_400.jpg" /> “My dear friends. Before I get to the finest newest technology in the world, I have to bring you some very sad news…”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_0983_400.jpg" /> “… I’m still deeply shocked myself…”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_0982_400.jpg" /> “… I implore you to help us solve this… this… <em>lèse-majesté</em>!” </font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS">That rambling went on for some time, but Ray certainly kept his dignity. In the end he even offered some consolation to the equally shocked audience.</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_0985_400.jpg" /> “But rest assured! We WILL find this criminal and we WILL bring him to justice…”</font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/09/pdc_0986_400.jpg" /> </font><font face="Comic Sans MS">“We shall not allow this to happen again!” </font></p>
<p><font face="Comic Sans MS">&#160;</font></p>
<p><font face="Comic Sans MS">I also got some reactions…. <em>Excuse me? Uhm, no, this is just a personal e-mail… </em>(Sorry, have to leave…)</font></p>
<p align="right"><strong><font color="#800000" face="Comic Sans MS">Anonymous</font></strong></p>
<p align="right"><font color="#800000" face="Comic Sans MS"></font></p>
<p align="right"><font color="#800000" face="Comic Sans MS"></font></p>
<p align="right"><font color="#800000" face="Comic Sans MS"></font></p>
<p align="right"><font color="#800000" face="Comic Sans MS"></font></p>
<p align="right"><font color="#800000" face="Comic Sans MS"></font></p>
<br />Posted in Fun  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/502/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=502&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/09/03/pdc08-the-crime-part-2-management-panics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_0984_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_0983_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_0982_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_0985_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/09/pdc_0986_400.jpg" medium="image" />
	</item>
		<item>
		<title>PDC08 &#8211; the unrevealed crime (Part 1)</title>
		<link>http://ajdotnet.wordpress.com/2009/08/31/pdc08-the-unrevealed-crime-part-1/</link>
		<comments>http://ajdotnet.wordpress.com/2009/08/31/pdc08-the-unrevealed-crime-part-1/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 16:20:18 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=481</guid>
		<description><![CDATA[Alright, this blog is hijacked! I’m not going to tell you who I am, and it’s up to you whether you believe me or not. But I’m here to tell you the truth! The truth about what happened last PDC. I have to be careful, though. Once the word gets around, I will be in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=481&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="left"><font face="Comic Sans MS">Alright, this blog is hijacked! I’m not going to tell you who I am, and it’s up to you whether you believe me or not. But I’m here to tell you the truth! The truth about what happened last PDC. <font face="Comic Sans MS">I have to be careful, though. Once the word gets around, I will be in grave danger. Thus I have to keep my anonymity. Nobody will be happy about me telling the world about… <em>THE CRIME</em>. </font></font></p>
<p align="left"><font face="Comic Sans MS">You never heard about it? No wonder. Ask someone who was at the last PDC to tell you something about THE CRIME. You’ll see people hunching down, backing off, finding excuses to leave, or otherwise evading the topic. It’s the dirty secret we all share and that to the best of my knowledge, nobody has told yet. It’s a hideous crime, and the cove-up that ensued is on par with the </font><a href="http://en.wikipedia.org/wiki/Apollo_Moon_Landing_hoax_conspiracy_theories" target="_blank"><font face="Comic Sans MS">fake moon landing</font></a><font face="Comic Sans MS">. (You know the moon landing <a href="http://www.youtube.com/watch?v=lYVLpC_8SQE" target="_blank">never happened</a>, don’t you?)</font></p>
<p align="left"><font face="Comic Sans MS">But this time, it’s going to be different. This time the truth will be told. <em>I </em>will tell it, for I cannot bear the burden of endangering the attendees of the </font><a href="http://microsoftpdc.com/" target="_blank"><font face="Comic Sans MS">upcoming PDC</font></a><font face="Comic Sans MS"> on my conscience. </font></p>
<p align="left"><strong><font face="Comic Sans MS">THE CRIME</font></strong></p>
<p align="left"><font face="Comic Sans MS">It happened to the most revered, and well regarded, father of Turbo Pascal. (And some other languages, I guess. He never managed </font><a href="http://en.wikipedia.org/wiki/Modula" target="_blank"><font face="Comic Sans MS">Modula</font></a><font face="Comic Sans MS">, though, but that’s really NOT AN EXCUSE!): </font><a href="http://en.wikipedia.org/wiki/Anders_Hejlsberg" target="_blank"><font face="Comic Sans MS">Anders Hejlsberg</font></a><font face="Comic Sans MS">!</font></p>
<p align="left"><img src="http://ajdotnet.files.wordpress.com/2009/08/pdc_1154_400.jpg" /> </p>
<p align="left"><font face="Comic Sans MS">&#160;</font></p>
<p align="left"><font face="Comic Sans MS">I was a witness and I happened to have my camera ready to document THE CRIME first-hand (and I sneaked it out when all cameras where confiscated!). See for yourself:</font></p>
<p align="left"><font face="Comic Sans MS"><img src="http://ajdotnet.files.wordpress.com/2009/08/pdc_1152_400.jpg" />&#160;</font><font face="Comic Sans MS">“What’s that…?” </font><font face="Comic Sans MS">“No… that can’t be…? Must be some hardware problem…”</font></p>
<p align="left"><font face="Comic Sans MS"><img style="display:inline;margin-left:0;margin-right:0;" src="http://ajdotnet.files.wordpress.com/2009/08/pdc_1156_400.jpg" />&#160;</font><font face="Comic Sans MS">“Really it has to do with these cables…?”     <br /></font><font face="Comic Sans MS">“No Anders, look at your screen. If the problem is not on the screen, it’s probably in front of it.”</font></p>
<p align="left"><font face="Comic Sans MS">&#160; </font></p>
<p align="left"><font face="Comic Sans MS">Note: In the interest of the innocent I’ll leave out the rather pitiful scenes and groundless accusations that followed. Suffice it to say that Anders eventually had to accept the fact that <em><strong>somebody installed </strong></em></font><a href="http://en.wikipedia.org/wiki/Linux" target="_blank"><em><font face="Comic Sans MS"><strong>LINUX</strong></font></em></a><font face="Comic Sans MS"><em><strong> on his machine</strong></em>! Imagine the insolence! The effrontery! the sheer impudence! A penguin mocking a distinguished person like Anders, and along with him the whole assembled Microsoft celebrity!</font></p>
<p align="left"><font face="Comic Sans MS"></font></p>
<p align="left"><font face="Comic Sans MS">Of course that didn’t amuse Anders in the slightest way…</font></p>
<p align="left"><font face="Comic Sans MS">&#160;</font></p>
<p align="left"><font face="Comic Sans MS"><img style="display:inline;margin-left:0;margin-right:0;" src="http://ajdotnet.files.wordpress.com/2009/08/pdc_1160_400.jpg" />&#160;</font><font face="Comic Sans MS">“I’m usually a nice and likable guy, …”</font></p>
<p align="left"><img style="display:inline;margin-left:0;margin-right:0;" src="http://ajdotnet.files.wordpress.com/2009/08/pdc_1158_400.jpg" />&#160;<font face="Comic Sans MS">“… but let me get my hands on this culprit, this evildoer, this…” (again, I have to protect the innocent.)</font></p>
<p align="left"><font face="Comic Sans MS"></font></p>
<p align="left"><font face="Comic Sans MS">&#160;</font></p>
<p align="left"><font face="Comic Sans MS">And yet, this… abomination… was only the beginning of the story…. <em>But I have to go, that guy over there is eying me suspiciously. More when I’m save again…</em></font></p>
<p align="right"><font color="#800000" face="Comic Sans MS"><strong>Anonymous</strong></font></p>
<br />Posted in Fun  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/481/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=481&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/08/31/pdc08-the-unrevealed-crime-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/pdc_1154_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/pdc_1152_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/pdc_1156_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/pdc_1160_400.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/pdc_1158_400.jpg" medium="image" />
	</item>
		<item>
		<title>Silverlight Bits&amp;Pieces &#8211; Part 5: Service Call Basics</title>
		<link>http://ajdotnet.wordpress.com/2009/08/30/silverlight-bitspieces-part-5-service-call-basics/</link>
		<comments>http://ajdotnet.wordpress.com/2009/08/30/silverlight-bitspieces-part-5-service-call-basics/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 13:21:41 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=469</guid>
		<description><![CDATA[Note: This is part of a series, you can find the related posts here… This time, building on the last post, I’m going over the basics of getting data to the client. The order of the day is just get it working, I’ll come back later to address some issues. The Service I have to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=469&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is part of a series, you can find the related posts <a href="http://ajdotnet.wordpress.com/category/silverlight/" target="_blank">here</a>…</p>
</blockquote>
<p>This time, building on the <a href="http://ajdotnet.wordpress.com/2009/08/27/silverlight-bitspieces-part-4-view-model-basics/" target="_blank">last post</a>, I’m going over the basics of getting data to the client. The order of the day is <em>just get it working</em>, I’ll come back later to address some issues.</p>
<p><strong>The Service</strong></p>
<p>I have to provide the service first. This is easiest done by adding a <em>Silverlight-enabled WCF service</em>, located in the “Create New Item” dialog, under the <em>Silverlight </em>group. It comes with the necessary configuration, ready to use. After defining the EF model, a first service operation delivering recently acquired books may look like this:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/code_servicemethod.jpg" /> </p>
<p>Note the <em>Sleep</em>. I like to stress the asynchronous nature of the SL client and I want the client code to handle this properly, thus the <em>Sleep </em>makes the time lag very apparent. </p>
<blockquote><p>Note: This way I know very early where I should provide visual feedback, or disable controls. This is especially important considering that on my development machine I will hardly spot any delay, but once the application goes into production and network performance and latency demand their toll, this will likely change.     <br />Thus I recommend you do the same, perhaps surrounding with <em>#if DEBUG </em>and making it configurable.</p>
</blockquote>
<p><strong>Calling a service</strong></p>
<p>After running the web application, Cassini provided a live version, which I needed to create the client side proxy. This generates respective code, of course including the data defined in the contract. Those classes already (by default) implement <em>INotifyPropertyChanged </em>and use <em>ObservableCollection&lt;T&gt;. </em>It certainly will give you a head start if you can use these classes as your model.</p>
<p>For every service operation there is a respective <em>MyOperationAsync() </em>method that initiates the asynchronous call and a <em>MyOperationCompleted </em>event that delivers the result. (No synchronous version by design!)</p>
<p>One hint: Creating the client proxy also created a <em>ServiceReferences.ClientConfig</em> file in the service assembly. This file is needed in the UI project to be available for the client. It works quite well to include it in the UI project be <em>setting a reference, </em>rather than just copying the file (“add existing item”, “add as link”), and this way you won’t have to keep a copy in sync.</p>
<p><strong>Wiring it Together</strong></p>
<p>The idiom is documented well enough, thus without further ado, my first version looks like this:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/code_viewmodel1.jpg" /> </p>
<p>The client instance is also used to detect whether the last call is still under way, and to suppress further calls.</p>
<p>The UI includes a button to trigger the server call (just for now, in this case the call will eventually be made from the c’tor), and the <em>DataGrid </em>to present the result:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/xaml_ui1.jpg" /> </p>
<p>The respective event handler is trivial as well:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/code_eventhandler.jpg" /> </p>
<p>Now, running the app looks like this:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/app_1.jpg" /> </p>
<p>Clicking the button… waiting… that’s why I put the <em>Sleep</em> in… . Oh, and I can click the button as I like? … Finally the result appears:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/app_2.jpg" /> </p>
<p>Regarding the “I can still click the button…”, I wanted to make this point specifically, because I have already seen people ignore that time lag too easily. It no only makes your application “feel unresponsive” in case of longer operations, because the user doesn’t get any indication whether the application has actually accepted his button click. It also may makes your logic more complex if it had to deal with multiple calls at the same time. My code simply ignored them, but there is no reason why they shouldn’t be processed as they come in. Even canceling the previous call may make sense, because it may be obsolete due to changed parameters (most operations are certainly not as simple as the one used in this example). You may want to cancel if the criteria actually changed and ignore the subsequent call if the criteria stayed the same… . See? Quickly the complexity adds up. The easy way around is disabling the button and making the user experience a sequential one. </p>
<p><strong>Providing visual feedback</strong></p>
<p>So, the logical step is to add a respective property <em>CanLoadBooks </em>and use it for the binding…</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/code_viewmodel2.jpg" /> </p>
<p>After that, disabling the button can be done via data binding the <em>IsEnabled </em>property: </p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/xaml_ui2.jpg" /> </p>
<p>And nicely my application provides visual feedback and at the same time prevents the user from redoing what he did:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/app_3.jpg" /> </p>
<p><strong>The stage…</strong></p>
<p>This post sort of completes the initial setup of the stage for my Silverlight application. I have a <a href="http://ajdotnet.wordpress.com/2009/08/19/silverlight-bitspieces-part-2-silverlight-solution/" target="_blank">solution</a>, the <a href="http://ajdotnet.wordpress.com/2009/08/21/silverlight-bitspieces-part-3-first-layout/" target="_blank">basic layout</a> is in place, the general <a href="http://ajdotnet.wordpress.com/2009/08/27/silverlight-bitspieces-part-4-view-model-basics/" target="_blank">application architecture</a> and data binding strategy is set up, and with this post I can talk to the server.    <br />From here I will go exploring various aspects, probably at random, but now I have the means to do so.    <br />And there is a lot of aspects to cover anyway. The services part I addressed in this post is by no means covered exhaustively, neither is data binding. Other topics haven’t yet been mentioned at all, like basic application services, visual state manager, navigation, or configuration.</p>
<p>Anyway, I will have to work on it before I can write about it. So this series is certainly not coming to an end, however further posts may take some more time. And I have a small by-project running, some mischief I’m up too <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2009/08/30/silverlight-bitspieces-part-5-service-call-basics/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/08/30/silverlight-bitspieces-part-5-service-call-basics/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, C#, Silverlight, Software Architecture, Software Development, WCF  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/469/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=469&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/08/30/silverlight-bitspieces-part-5-service-call-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/code_servicemethod.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/code_viewmodel1.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/xaml_ui1.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/code_eventhandler.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/app_1.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/app_2.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/code_viewmodel2.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/xaml_ui2.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/app_3.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/08/30/silverlight-bitspieces-part-5-service-call-basics/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Bits&amp;Pieces &#8211; Part 4: View Model Basics</title>
		<link>http://ajdotnet.wordpress.com/2009/08/27/silverlight-bitspieces-part-4-view-model-basics/</link>
		<comments>http://ajdotnet.wordpress.com/2009/08/27/silverlight-bitspieces-part-4-view-model-basics/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 18:48:40 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=456</guid>
		<description><![CDATA[Note: This is part of a series, you can find the related posts here… Displaying and manipulating data on the client – the one and only purpose of any LOB application – includes two things if it comes to Silverlight: a) The asynchronous server calls and b) the client architecture. I will be going over [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=456&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is part of a series, you can find the related posts <a href="http://ajdotnet.wordpress.com/category/silverlight/" target="_blank">here</a>…</p>
</blockquote>
<p>Displaying and manipulating data on the client – the one and only purpose of any LOB application – includes two things if it comes to Silverlight: a) The asynchronous server calls and b) the client architecture. I will be going over them in a cursory fashion and come back later to address each one in more depth. This time the client architecture.</p>
<p><strong>View Model basics</strong></p>
<p>The client code is largely guided by the employment of the <a href="http://en.wikipedia.org/wiki/Model_View_ViewModel" target="_blank">Model-View-ViewModel</a> (M-V-VM, or MVVM) approach, which is the predominant architectural approach used with SL and <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" target="_blank">WPF</a>. The reason probably being that it is a natural counterpart to the WPF and Silverlight data binding features, the two work extremely well together.</p>
<p>Cook book style:</p>
<ul>
<li>For every page (the <em>view</em>) there is a respective class (the <em>view model</em>) that manages the data (the <em>model</em>). </li>
<li>For each control on the view that shall be populated dynamically with data, the view model has a corresponding property providing the model. </li>
<li>For each control state, such as enabled or visible, that shall be controlled by the logic, the view model has a corresponding property, probably boolean. </li>
<li>For each action triggered by the UI the view model has a respective method. </li>
</ul>
<p>The view model is very closely associated with its view, so there is not much reuse here, but then, it largely consists of properties and forwards to service calls. Or so the theory says. (Subsequent posts will gave deal with the shortcomings….)</p>
<blockquote><p>Please note that it is debatable whether the data provided by the view model actually <em>is </em>the model. Another approach would be to expose a view related data model, namely <em>view entities</em>. The view model would have to map them to the data model (<u>the</u> <em>model</em>) the lower layer exposes, probably some service proxy.</p>
<p>Both approaches have pros and cons, however you’ll mostly see the former approach, since it’s well supported by the tools (service proxy generation, etc.). Still, it has some cons…</p>
</blockquote>
<p>Anyway, the only technical demand for view models in SL is due to the intended use for data binding: Classes subject to fully fledged data binding need to support the <em>INotifyPropertyChanged </em>interface for simple properties, while collections have to support <em>INotifyCollectionChanged</em>. The later one comes for free if you use <em>ObservableCollection&lt;T&gt; </em>consequently. (Please note that data binding works with conventional properties, but only to a limited degree.)</p>
<p>For <em>INotifyPropertyChanged </em>a little base class comes in handy:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/code_npcb.jpg" /> </p>
<p>Note the generic overload. That’s a little trick to avoid typos in the property name argument.</p>
<p>With this class as base a property implementation usually follows this idiom:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/code_prop.jpg" /> </p>
<p>(Without that trick one would have to pass the property name as string. A source of errors due to typos, and a pitfall during refactoring.)&#160; </p>
<p><em>BookFilter </em>is a data class that, again, follows the same pattern, i.e. it supports <em>INotifyPropertyChanged</em>.</p>
<blockquote><p>Hint: This begs for a code snippet! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
</blockquote>
<p><strong>The View Model</strong></p>
<p>Any book shelf has a collection of books, so does my application. The book list page should provide a means to filter the book list (two text boxes), a button to trigger the search, and to show the result (a data grid):</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/app_page.jpg" /> </p>
<p>Not especially nice and the grid is a little degenerated for now, but that will change. In XAML:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/xaml_page.jpg" /> </p>
<p>Thus the first view model implementation may look like this (including some simple test data, the next post will deal with the server call):</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/code_viewmodel.jpg" /> </p>
<p><strong>Databinding</strong></p>
<p>For the actual binding I need to wire that up with the page. The usually presented manual way looks like this:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/code_page.jpg" /> </p>
<p>The view model class is created in the c’tor, and assigned to the <em>DataContext</em>. A property provides a more convenient access to it. This is already used in the button event handler that triggers the book search.     <br />However, I recommend against this way. Rather I did the data binding in Blend…</p>
<p>Opening the page, selecting the first textbox, finding the <em>Text</em> property in the properties and clicking the text box (or that tiny little dot to the right) brings up the context menu. </p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/08/blend_binding0.png" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/08/blend_binding0_tn.png" /></a> </p>
<p>Then I choose data binding, the <em>Data Field </em>tab, and the <em>+CLR Object </em>button:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/08/blend_binding1.png" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/08/blend_binding1_tn.png" /></a> </p>
<p>That left finding the view model class and selecting it:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/08/blend_binding2.png" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/08/blend_binding2_tn.png" /></a> </p>
<p>This way I <em>could </em>add various “data sources”, yet I only want one for now, and according to M-V-VM, for ever. Afterwards the dialog lets me browse the class structure and select the property to bind against:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/08/blend_binding3.png" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/08/blend_binding3_tn.png" /></a> </p>
<p>On second thought, I selected the <em>StackPanel </em>which contains the filter textboxes and bound it against the <em>BookFilter </em>property, in order to narrow the available context. Afterwards the textboxes could be bound via the <em>Explicit Data Context </em>tab:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/08/blend_binding4.png" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/08/blend_binding4_tn.png" /></a> </p>
<p>I had to expand the lower area to set the binding to <em>TwoWay</em>. </p>
<p>But I didn’t have to go through the dialog armada for every field. Blend also provides the data tab that lets me browse through the available data sources. Drag’n’drop of field simply works and generally uses the last settings from the dialog, i.e. it includes the <em>TwoWay </em>setting. Also it binds by against the default property, but if I hold the shift key down it lets me choose the property. And some other stuff I leave to you to explore. Really nice.</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/08/blend_binding5.jpg" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/08/blend_binding5_tn.jpg" /></a> </p>
<p>Anyway, this is what Blend just created for us in markup speak (just the relevant part):</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/xaml_datasource.jpg" /> </p>
<p>It registered the namespace to locate the view model class, created the view model as resource, set the <em>DataContext </em>of the <em>LayoutRoot </em>element to this resource, and it added the usual binding to the subsequent controls.</p>
<p>Changing the generated prefix to <em>viewModel </em>was all I did. Otherwise I could live very well with that, given that is achieves all I need and it allows me to do my data binding much more efficient and less error prone in Blend. The manual way was opaque to Blend, thus it couldn’t assist me in any way.</p>
<p>The only thing left was removing the manual instantiation from the c’tor and changing the <em>ViewModel </em>property to use the <em>LayoutRoot </em>control. I may have moved the binding to the page instead, but I prefer to work <em>with </em>the tools, not against them.</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/code_vmprop.jpg" /> </p>
<p>After running the application and clicking on the button, it shows the respective test data:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/app_page2.jpg" /> </p>
<p>The next post will deal with the actual server call. </p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET </strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2009/08/27/silverlight-bitspieces-part-4-view-model-basics/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/08/27/silverlight-bitspieces-part-4-view-model-basics/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, C#, Design Time, Silverlight, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/456/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=456&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/08/27/silverlight-bitspieces-part-4-view-model-basics/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/code_npcb.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/code_prop.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/app_page.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/xaml_page.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/code_viewmodel.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/code_page.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/blend_binding0_tn.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/blend_binding1_tn.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/blend_binding2_tn.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/blend_binding3_tn.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/blend_binding4_tn.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/blend_binding5_tn.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/xaml_datasource.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/code_vmprop.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/app_page2.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/08/27/silverlight-bitspieces-part-4-view-model-basics/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Bits&amp;Pieces &#8211; Part 3: First Layout</title>
		<link>http://ajdotnet.wordpress.com/2009/08/21/silverlight-bitspieces-part-3-first-layout/</link>
		<comments>http://ajdotnet.wordpress.com/2009/08/21/silverlight-bitspieces-part-3-first-layout/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 19:48:55 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=422</guid>
		<description><![CDATA[Note: This is part of a series, you can find the related posts here… One thing is as true with SL as it was with HTML and CSS: Starting with a basic layout of the pages and a “site map” really helps a lot. (Trying to work with a style system that you don’t know [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=422&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is part of a series, you can find the related posts <a href="http://ajdotnet.wordpress.com/category/silverlight/" target="_blank">here</a>…</p>
</blockquote>
<p>One thing is as true with SL as it was with HTML and CSS: Starting with a basic layout of the pages and a “site map” really helps a lot. (Trying to work with a style system that you don’t know doesn&#8217;t.)</p>
<p>The application created by the template looks like this:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/app_template.jpg" /> </p>
<p>It’s a navigation application with head area (including menu) and remaining work area. It uses a <em>Grid </em>control, yet only as kind of canvas, all controls are placed via margins and alignments. I find this, well, curious, there <em>is </em>a canvas control after all. But the layout doesn’t suit me anyway. </p>
<p>So the first step is to get rid of all styles, i.e. I cleaned <em>Assets/Styles.xaml</em>. That included removing all references to these styles, as in this fragment:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/xaml_hyperlink.jpg" /> </p>
<p>Searching with a little regular expression solves that problem. Now for the intended layout:</p>
<p>I want to have a head area with application title and other information. A left area containing the menu. A bottom line with legal information. And finally the remaining area for our pages. And some space between for some visual separation.</p>
<p>In SL this is done with a <em>Grid</em>. Curiously enough, for this is akin to table layout in HTML. I wonder when the CSS gang will show up and cry wolf <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Most samples show and explain how to write the markup to define rows and columns. But then, most samples are pre-created and reiterated, and I have problems “mind rendering” the markup. With the Silverlight 2 SDK there was at least a kind of preview in VS, but with SL3 that preview does not work (the document outline may help to navigate larger XAML files, though):</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/08/vs_designer.jpg" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/08/vs_designer_tn.jpg" /></a> </p>
<p>So I chose a different way and put Blend to its first use…</p>
<p><strong>Grid layout</strong></p>
<p>Defining the desired <em>Grid </em>layout can be done easily in Blend. Placing rows and columns is just a mouse click away: Clicking on the areas to the left or the top adds new rows and columns. Clicking on the symbols changes the type. If you don’t see them, change the layout mode by clicking in the upper left icon.</p>
<p>&#160;<a href="http://ajdotnet.files.wordpress.com/2009/08/blend_grid.jpg" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/08/blend_grid_tn.jpg" /></a> </p>
<p>Once the rough layout is done, it can be saved and one can switch back to VS. The resulting markup is very clean, Blend generally does a good job producing clean markup and at the same time leaving your markup as it was. </p>
<p><strong>Placing the contents</strong></p>
<p>Next step was creating controls for the three areas (head, menu, footer) and move the respective content from the page there (copy &amp; paste in VS). The markup now only contains the navigation frame, which is the working area. Drag &amp; drop and some more mouse jostling in Blend positions that control in the correct cell:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/08/blend_position1.png" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/08/blend_position1_tn.png" /></a> </p>
<p>And sizing it correctly:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/08/blend_position2.png" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/08/blend_position2_tn.png" /></a> </p>
<p>Also – after recompiling the solution – Blend picked up the user controls and offered them as assets if you select <em>Project</em>. Again some mouse jostling later (and with different backgrounds colors for each user control to distinguish them) the result looks like this:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/08/blend_usercontrols.png" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/08/blend_usercontrols_tn.png" /></a> </p>
<p>Blend automatically generated a namespace definition as prefix for the controls, using a veeerrrryyyy long prefix name. But that’s easy to solve and to replace with <em>control</em>. The final markup is, again, very clean:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/08/xaml_layout.jpg" /> </p>
<p>After some working on the user controls and some styling… <em>alright, it may take some time, but had it ready from some internal application, and besides it was done by a colleague, for if I had done it myself if would probably cause eye cataracts… </em>, the end result looks like this:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/08/app_bookshelf1.png" target="_blank"><img src="http://ajdotnet.files.wordpress.com/2009/08/app_bookshelf_tn1.png" /></a> </p>
<p>This may all seem trivial if you’ve been through this experience once. Bottom line I guess is <em>the way </em>I worked through this (which may or may not work for you). It’s the combination of VS and Blend, working with both tools at the same time. Even if you are a markup guy rather than design time worker in ASP.NET, my recommendation is that you give Blend a chance. It’s far more stable than the ASP.NET designer in VS ever was. I’m not saying you should switch to Blend, just get the best of both, VS and Blend.</p>
<p>The next post will contain some real code, promise <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2009/08/21/silverlight-bitspieces-part-3-first-layout/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/08/21/silverlight-bitspieces-part-3-first-layout/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, Design Time, Silverlight, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/422/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/422/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/422/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/422/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/422/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/422/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/422/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/422/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/422/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/422/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/422/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/422/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/422/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/422/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=422&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/08/21/silverlight-bitspieces-part-3-first-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/app_template.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/xaml_hyperlink.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/vs_designer_tn.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/blend_grid_tn.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/blend_position1_tn.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/blend_position2_tn.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/blend_usercontrols_tn.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/xaml_layout.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/app_bookshelf_tn1.png" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/08/21/silverlight-bitspieces-part-3-first-layout/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Bits&amp;Pieces &#8211; Part 2: Silverlight Solution</title>
		<link>http://ajdotnet.wordpress.com/2009/08/19/silverlight-bitspieces-part-2-silverlight-solution/</link>
		<comments>http://ajdotnet.wordpress.com/2009/08/19/silverlight-bitspieces-part-2-silverlight-solution/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 16:36:47 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=386</guid>
		<description><![CDATA[Note: This is part of a series…. Well, it will be &#160; You can find the related posts here… Alright, let’s start looking into some Silverlight 3 (SL3) development. Specifically of business applications. First step is a respective solution. I created a new “Silverlight Navigation Application”, with SL hosted in a web site, and got [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=386&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is part of a series…. Well, it will be <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> &#160; <br />You can find the related posts <a href="http://ajdotnet.wordpress.com/category/silverlight/" target="_blank">here</a>…</p>
</blockquote>
<p>Alright, let’s start looking into some Silverlight 3 (SL3) development. Specifically of business applications.</p>
<p> <a href="http://ajdotnet.files.wordpress.com/2009/08/sln_orig.jpg" target="_blank"><img style="display:inline;border-width:0;margin:0 0 5px 5px;" border="0" align="right" src="http://ajdotnet.files.wordpress.com/2009/08/sln_orig_small.jpg" /></a>
<p>First step is a respective solution. I created a new “Silverlight Navigation Application”, with SL hosted in a web site, and got the typical solution structure. Needless to say, that this structure doesn’t meet my requirements.</p>
<p>First, I’m going to have a bunch more assemblies. And since SL assemblies are different from “ordinary” assemblies – they work against a different runtime and use different libraries – I like to have them clearly distinguishable. I did this a) with respective solution folders and b) with an added namespace part “SL3”.</p>
<p><strong>The Server Part</strong></p>
<p> <a href="http://ajdotnet.files.wordpress.com/2009/08/sln_server.jpg" target="_blank"><img style="display:inline;border-width:0;margin:0 5px 5px 0;" border="0" align="left" src="http://ajdotnet.files.wordpress.com/2009/08/sln_server_small.jpg" /></a>
<p>On the server side I added two assemblies:</p>
<p>One data access assembly. This contains the ADO.NET Entity Framework access to the database. For the purpose of this application, this constitutes the business layer. (A little simplistic, but bear with me, the focus is on the client.)</p>
<p>A “Common” assembly. There will be server side parts of logic that may be reused in other applications.</p>
<p>I also made some adjustments to the web application (project properties/web): I changed virtual path to “/xBookshelf”, I don’t like my web apps to occupy the root. And I set the port to “specific port”. It doesn’t matter which one, it’s just a little annoying to have to update service references when the port is changed by VS every now and then. Speaking of services, I’m going to put them in a separate folder.</p>
<p><strong>The Client Part</strong></p>
<p> <a href="http://ajdotnet.files.wordpress.com/2009/08/sln_client.jpg" target="_blank"><img style="display:inline;border-width:0;margin:0 0 5px 5px;" border="0" align="right" src="http://ajdotnet.files.wordpress.com/2009/08/sln_client_small.jpg" /></a>
<p>My naming convention for SL3 assemblies is <em>Company.Application.<strong>SL3</strong>…</em> . Specifically I renamed the SL assembly containing the XAML files to <em><em>SDX.Bookshelf</em>.SL3.<strong>UI</strong></em>. Renaming the .xap file affects the web project and the hosting pages. I also changed the pages to have <em>Page</em> as postfix. </p>
<p>And there are a few additional assemblies as well:</p>
<p><em>SDX.Bookshelf.SL3.<strong>Model </strong></em>contains the view models, as I’m going to use the Model-View-ViewModel pattern.</p>
<p><em>SDX.Bookshelf.SL3.<strong>Service</strong></em> contains all service references. Since this is all generated code, I thought it prudent to cleanly separate it.</p>
<p><em>SDX.SL3.<strong>Common</strong></em> is the counterpart to the server side common assembly. It will contain everything that may be reused in other application.</p>
<p>Setting the project dependencies and getting it all to run again is just a bit tedious, especially because the startup project is the web project, but the application in question is the UI project.</p>
<p><strong>Blend</strong></p>
<p>The final test for the reworked solution is opening it in Blend – which may be not as trivial as it sounds <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>You will at least get one warning dialog telling you that blend does not support solution folders. Never mind, that’s of no consequence.</p>
<p><img style="border-width:0;" border="0" src="http://ajdotnet.files.wordpress.com/2009/08/blend_startup_warning.jpg" /></p>
<p>In one project I also run into a serious issue: Blend refused to open the solution with the following dialog:</p>
<p><img style="border-width:0;" border="0" src="http://ajdotnet.files.wordpress.com/2009/08/blend_startup_error1.jpg" /></p>
<p>Also subsequently I got a large message box with an exception stack trace.</p>
<p>To work around this problem, I removed all projects from the solution and added them again in Blend. I was able to provoke that bug by reordering the sequence of the projects within the .sln file, hence it’s probably due to some project dependencies that blend can’t solve correctly.</p>
<p>Anyway, don’t let that bias your perception. Blend may be awkward, and it takes time getting used to – but is worth the effort.</p>
<p><font color="#008000">That’s all for now,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2009/08/19/silverlight-bitspieces-part-2-silverlight-solution/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/08/19/silverlight-bitspieces-part-2-silverlight-solution/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, C#, Silverlight, Software Architecture, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/386/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=386&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/08/19/silverlight-bitspieces-part-2-silverlight-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/sln_orig_small.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/sln_server_small.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/sln_client_small.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/blend_startup_warning.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/blend_startup_error1.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2009/08/19/silverlight-bitspieces-part-2-silverlight-solution/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Bits&amp;Pieces &#8211; Part 1: Introduction</title>
		<link>http://ajdotnet.wordpress.com/2009/08/17/silverlight-bitspieces-part-1-introduction/</link>
		<comments>http://ajdotnet.wordpress.com/2009/08/17/silverlight-bitspieces-part-1-introduction/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 16:11:24 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=340</guid>
		<description><![CDATA[With Silverlight I was lucky… I never got to look into Silverlight 1, so I avoided the scripting mess For Silverlight 2 I participated in some research efforts on our company and I worked on a business solution (as in business solution, not just a “simple” control). This did not only include the obvious stuff [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=340&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>With Silverlight I was lucky…</p>
<ul>
<li>I never got to look into Silverlight 1, so I avoided the scripting mess <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </li>
<li>For Silverlight 2 I participated in some research efforts on our company and I worked on a business solution (as in <em>business </em>solution, not just a “simple” control). This did not only include the obvious stuff like drawing and driving the UI, but also some necessary groundwork.</li>
<li>Microsoft launched Silverlight 3 officially on Friday, July, 10th; on the following Monday, July, 13th, I was officially in a customer’s Silverlight 3 project. We had just waited for the availability <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </li>
</ul>
<p>And to relay the probably most important experience for me so far: <span style="text-decoration:underline;">Working with Silverlight 3 and Blend is fun!</span></p>
<p>It’s easier to get what you want than with web applications, the programming model is much more concise and powerful than ASP.NET, Blend has a far better user experience than the WebForms designers ever had (after being nearly a decade and several versions old!).<br />
For me, working with Silverlight has a thrill factor comparable to what I encountered when I first started to develop with .NET.</p>
<blockquote><p><em>Note: From now on, I’ll refer to </em>Silverlight 3 <em>simply as </em>SL<em>.</em></p></blockquote>
<p>So, I may have a little head start with SL business applications and their demands, but I’m sure that will wear down over time. Anyway, I thought I might share some of the experiences, insights, and ways I discovered.</p>
<p>This is not going to be me providing a tutorial, or me telling you what to do. It’s about me telling you what worked for me. Some may be outright trivial (especially the first ones, laying the foundation), some may be about the how to do it, rather than the what to do. But then, I also had to tackle a few things that go beyond the usual “My first Silverlight Hello World Application” type of samples.</p>
<blockquote><p>Disclaimer: This is as much about telling you how I did things as it is a learning experience for me. I may be wrong at times. I may tell you in one post to go left and a few posts later that you had better not listened. No warranties here, sorry.</p></blockquote>
<p>And I’ll try something different and keep the posts short and to a certain point <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  (and I admit that this post is already in violation with this intention…).</p>
<p><strong>Preconditions</strong></p>
<p>Just for the record: I’ll base the work on SL as you can get it <a href="http://www.microsoft.com/silverlight/resources/technical-resources/" target="_blank">here</a>. That includes:</p>
<ul>
<li>Microsoft Silverlight Tools for Visual Studio 2008 (includes developer runtime and SDK)</li>
<li>Microsoft Expression Blend 3 + Sketchflow</li>
</ul>
<p>I refrained from using RIA services, because I want to understand the technology bare boned. That being said, I think that RIA services has really great potential and for those interested I recommend <a href="http://blogs.msdn.com/brada/archive/tags/RIAServices/default.aspx" target="_blank">Brad’s series</a>. I also haven’t thought about including the control toolkit, yet.</p>
<p><strong>Setting the stage</strong></p>
<p>My way of learning a new technology is usually a) read about it to understand the idea behind it, b) do some technical prototypes to dive into one or the other feature, and c) take a real world example and see how the technology fares. In my experience, point c is the most important, because it goes beyond the usual samples that are built to suit the technology. Rather it stresses the technology’s abilities to meet actual needs. This is usually when you’ll encounter the pitfalls.</p>
<p>My real world example for SL was kind of a library or book management application. At <a href="http://www.sdx-ag.de/" target="_blank">SDX</a> we maintain our books in a simple SharePoint list, so every colleague knows what books are actually available, where to find them, who has borrowed it currently. This list is more intended to keep people informed, than controlling whether they return the books on time. Weren’t our colleagues dispersed at various customers’ sites, a simple bookshelf with no bureaucracy at all would be sufficient. (And I wouldn’t have to go hunting for lost books every now and then <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  .)</p>
<p><strong>The Database</strong></p>
<p>The database I’m going to use is simple enough. It contains books, information about who borrowed it, and user information:</p>
<p><img style="border-bottom:0;border-left:0;display:inline;margin-left:0;border-top:0;margin-right:0;border-right:0;" title="image" src="http://ajdotnet.files.wordpress.com/2009/08/image.png?w=640&#038;h=263" border="0" alt="image" width="640" height="263" /></p>
<p>Additionally I like to create views as I need them (rather than using EF for this). For example <em>BookInventory </em>contains all books as well as the related information on the currently borrowed books and employees.</p>
<p>And with these conditions set, we are ready to start. The next post will start at the beginning, stay tuned <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><span style="color:#008000;">That’s all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<span style="color:#008000;"><strong> </strong></span></p>
<br />Posted in .NET, .NET Framework, C#, Silverlight, Software Architecture, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/340/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/340/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/340/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=340&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/08/17/silverlight-bitspieces-part-1-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/08/image.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Der Lügen-Limbo der Ursula von der Leyen [MOVED]</title>
		<link>http://ajdotnet.wordpress.com/2009/08/03/der-lugen-limbo-der-ursula-von-der-leyen/</link>
		<comments>http://ajdotnet.wordpress.com/2009/08/03/der-lugen-limbo-der-ursula-von-der-leyen/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 18:32:55 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=334</guid>
		<description><![CDATA[Moved: http://alexanderj.wordpress.com/2009/08/03/der-luegen-limbo-der-ursula-von-der-leyen/ Posted in Miscellaneous<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=334&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Moved: <a href="http://alexanderj.wordpress.com/2009/08/03/der-luegen-limbo-der-ursula-von-der-leyen/">http://alexanderj.wordpress.com/2009/08/03/der-luegen-limbo-der-ursula-von-der-leyen/</a></p>
<br />Posted in Miscellaneous  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/334/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=334&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/08/03/der-lugen-limbo-der-ursula-von-der-leyen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Posting Guards: Guard Classes explained</title>
		<link>http://ajdotnet.wordpress.com/2009/08/01/posting-guards-guard-classes-explained/</link>
		<comments>http://ajdotnet.wordpress.com/2009/08/01/posting-guards-guard-classes-explained/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 09:53:35 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=325</guid>
		<description><![CDATA[A colleague writing an article about code contracts recently asked me about some useful links about Guard classes, something I have been advertising for some time. ‘Sure’, I thought &#8212; and was taught otherwise. There are certainly references to Guard classes. For example this one hinting at an implementation from MS Patterns&#38;Practices, although an outdated [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=325&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A colleague writing an article about <a href="http://www.leading-edge-dev.de/?tag=code-contracts" target="_blank">code contracts</a> recently asked me about some useful links about <em>Guard classes</em>, something I have been advertising for some time. ‘Sure’, I thought &#8212; and was taught otherwise.</p>
<p>There are certainly references to Guard classes. For example <a href="http://msmvps.com/blogs/paulomorgado/archive/2006/10.aspx" target="_blank">this one</a> hinting at an implementation from <a href="http://msdn.microsoft.com/en-us/library/ms998572.aspx" target="_blank">MS Patterns&amp;Practices</a>, although an outdated one and no online documentation available. And <a href="http://www.moserware.com/2008/01/borrowing-ideas-from-3-interesting.html" target="_blank">this one</a> talking about using Guard classes in combination with LINQ.</p>
<p>Still, nothing explaining the concept, nothing on Wikipedia, nothing anywhere. Can it be that Guard classes are far too simple to be worth mentioning? I don’t think so, because while the <i>implementation</i> certainly <i>is</i> simple, I wouldn’t have had to explain the <i>concept</i> that often if that where the reason.</p>
<p><strong>So, what are Guard classes?</strong></p>
<p>First of all, let’s make sure we’re taking about the same thing. Judging from the name, Guard classes are about guarding against something, but this can mean just about anything. Actually I found two incarnations: One, guarding against concurrent access, i.e. some kind of locks. And two, guarding against the passing of invalid parameters into a method – which is what this post is about. (You may have come across Guard classes by the name of <em>ArgChecker</em>, <em>ArgumentHelper</em>, or something similar, or as single helper methods appearing where they don’t belong.)</p>
<p>Straight to the matter: Have a look at the following example:</p>
<blockquote><p>IEnumerable&lt;Employee&gt; FindCustomers1(Guid companyID, EmployeeFilter filter)    <br />{     <br />&#160;&#160;&#160; IEnumerable&lt;Employee&gt; result= <font color="#0000ff">null</font>;     <br />&#160;&#160;&#160; <font color="#0000ff">if</font> (companyID!=Guid.Empty) <font color="#008000"><i>// only hit DB if we have to</i></font>     <br />&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">using</font> (DatabaseDataContext context = <font color="#0000ff">new</font> DatabaseDataContext())     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; result = <font color="#0000ff">from</font> e <font color="#0000ff">in</font> context.Employees     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">where</font> e.FirstName == filter.FirstName &amp;&amp; e.LastName == filter.LastName     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">select</font> e;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }     <br />&#160;&#160;&#160; }     <br />&#160;&#160;&#160; <font color="#0000ff">return</font> result;     <br />} </p></blockquote>
<p>While probably doing its job properly, this method isn’t exactly <i><a href="http://en.wikipedia.org/wiki/Defensive_programming" target="_blank">defensive</a></i>. The issue should be apparent: What happens if the caller passed <em>null</em> for the filter? Not that he is expected to, quite the opposite, but anyway?</p>
<p>You could try to handle that in code and it would probably lead to some ugly code, as <a href="http://www.thehackerchickblog.com/2008/10/just-say-no-to-nulls-or-refactoring.html" target="_blank">Abby rightly complained about</a>. And to be blunt, that approach is wrong right from the start. If caller is not supposed to pass <em>null </em>values into our method, why should we clutter our code with conditions that aren’t supposed to happen anyway.</p>
<p>The better solution is getting rid of unwanted <em>null </em>values by making them illegal. And not only by politely asking in the documentation (and please <a href="http://en.wikipedia.org/wiki/Rtfm" target="_blank">RTFM</a>); rather make it unmistakably apparent, punish any violation, make it impossible to bypass. In other words, check the parameter and throw an <em>ArgumentException</em>.</p>
<p>On second thought, the same reasoning applies also to the properties of our filter object, so we may end up writing the following code, prone to becomes ugly itself:</p>
<blockquote><p><font color="#0000ff">if</font> (filter == <font color="#0000ff">null</font>)       <br /><font color="#0000ff">&#160;&#160;&#160; throw</font> <font color="#0000ff">new</font> ArgumentNullException(„filter“);       <br /><font color="#0000ff">if</font> (filter.FirstName == <font color="#0000ff">null</font>)       <br /><font color="#0000ff">&#160;&#160;&#160; throw</font> <font color="#0000ff">new</font> ArgumentNullException(„filter.FirstName“);       <br /><font color="#0000ff">if</font> (filter.LastName == <font color="#0000ff">null</font>)       <br /><font color="#0000ff">&#160;&#160;&#160; throw</font> <font color="#0000ff">new</font> ArgumentNullException(„filter.LastName“);</p>
</blockquote>
<p><font color="#000000"><em>And</em> we actually did expect some content, so why not go ahead and do some other vanity checks:</font></p>
<blockquote><p><font color="#0000ff">if</font> (filter.FirstName == „“)       <br /><font color="#0000ff">&#160;&#160;&#160; throw</font> <font color="#0000ff">new</font> ArgumentNullException(„filter.FirstName“);       <br /><font color="#0000ff">if</font> (filter.LastName == „“)       <br /><font color="#0000ff">&#160;&#160;&#160; throw</font> <font color="#0000ff">new</font> ArgumentNullException(„filter.LastName“);</p>
</blockquote>
<p>But wait. An empty string is certainly not <em>null</em>. Unfortunately there is no <em>StringEmptyArgumentException</em>. Should we use an <em>ArgumentOutOfRangeException</em>? Or an <em>InvalidOperationException</em>, not an <em>ArgumentException </em>at all? Derive a new one? <em>ArgumentOutOfRangeException </em>may look nicely to me, but my team mate just settled with <em>ArgumentNullException</em>, which is at the least an inconsistency&#8230; .</p>
<p>And what the heck, this is way too much code for nothing anyway. <em>And so we end up not checking our parameters and hoping for the best…</em>?</p>
<p>Now consider this code:</p>
<blockquote><p>IEnumerable&lt;Employee&gt; FindCustomers2(Guid companyID, EmployeeFilter filter)    <br />{     <br />&#160;&#160;&#160; Guard.AssertNotNull(filter, „filter“);     <br />&#160;&#160;&#160; Guard.AssertNotEmpty(filter.FirstName, „filter.FirstName“);     <br />&#160;&#160;&#160; Guard.AssertNotEmpty(filter.LastName, „filter.LastName“);     <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; IEnumerable&lt;Employee&gt; result = <font color="#0000ff">null</font>;     <br />&#160;&#160;&#160; <font color="#0000ff">if</font> (companyID != Guid.Empty) <font color="#008000"><i>// only hit DB if we have to</i></font>     <br />&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">using</font> (DatabaseDataContext context = <font color="#0000ff">new</font> DatabaseDataContext())     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; result = <font color="#0000ff">from</font> e <font color="#0000ff">in</font> context.Employees     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">where</font> e.FirstName == filter.FirstName &amp;&amp; e.LastName == filter.LastName     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">select </font>e;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }     <br />&#160;&#160;&#160; }     <br />&#160;&#160;&#160; <font color="#0000ff">return</font> result;     <br />} </p></blockquote>
<p>We just replaced 5 ugly conditions (10 LOC) with 3 calls. Let me rephrase that: We replaced a bunch of code <i>detailing some implementation</i> with 3 lines <i>revealing the intention</i> – way more <a href="http://ajdotnet.wordpress.com/2007/01/06/coding-conventions-are-a-precondition-to-readability/" target="_blank">readable</a>. Wow! By centralizing the checks, we were able to provide more convenience (putting the <em>null </em>and string empty check in one method), we ensured consistent behavior, we improved the calling code considerably. And finally, we even added some more information to the exception, as you will see in the implementation:</p>
<blockquote><p>[DebuggerStepThrough]    <br /><font color="#0000ff">static</font> <font color="#0000ff">public</font> <font color="#0000ff">void</font> AssertNotEmpty(<font color="#0000ff">string</font> arg, <font color="#0000ff">string</font> paramName)     <br />{     <br />&#160;&#160;&#160; <font color="#0000ff">if</font> (arg == <font color="#0000ff">null</font>)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">throw</font> <font color="#0000ff">new</font> ArgumentNullException(paramName,     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; „Argument ‚“ + (paramName ?? „&lt;missing&gt;“) + „‘ should not be NULL!“);     </p>
<p>&#160;&#160;&#160; <font color="#0000ff">if</font> (arg.Length == 0)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">throw</font> <font color="#0000ff">new</font> ArgumentOutOfRangeException(paramName, arg,     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; „Argument ‚“ + (paramName ?? „&lt;missing&gt;“) + „‘ should not be empty!“);     <br />} </p></blockquote>
<p>You don’t want to put that code in every method. But you <i>do</i> want to call the <em>Guard </em>method, don’t you?</p>
<p>Now that we have established what Guard classes are, let’s look at …</p>
<p><strong>What are Guard classes <i>about</i>?</strong></p>
<p>So far I introduced Guard classes form the coding level, merely as convenient helper classes. But there’s some broader meaning to them, namely in the following areas:</p>
<ul>
<li>Contracting </li>
<li>Self preservation </li>
<li>Robustness </li>
</ul>
<p><strong>Contracting.</strong></p>
<p><i>Contracting</i> as a means has gained attention as important aspect of SOA service design, and also as development approach, namely <a href="http://en.wikipedia.org/wiki/Design_by_contract" target="_blank">design by contract</a>. Contracting may be a major undertaking if it comes to SOA services, yet it can also be employed on a much lower level, designing the public interface of a class.</p>
<p>A little simplified, a contract of a class or service consists of</p>
<ul>
<li>Functional contract: Specifies the operations, the semantics, required call sequences, runtime behavior, error conditions and behavior. Some of this may be expressed using code, some may not. </li>
<li>Data contract: Details parameters and return values, in other words the data that is exchanged during the operations. It defines the legal shape and values of the data, restricting it first by data types, secondly by additional demands, such as stating which parameter is mandatory, which content is required, and which values it is limited to beyond what the data type mandates. Also interdependencies between fields, and so on. </li>
<li>Some other aspects, but that’s not relevant right now. </li>
</ul>
<p>As you see, the data contract goes beyond what the type system is capable to enforce. And Guard classes may serve as a means to express some of those aspects in code. Thus, Guard classes serve to <i>enforce the contract</i> of a class. And since these calls are that obvious, the code is self-documenting its preconditions quite nicely.</p>
<blockquote><p>Note 1: Of course this makes only sense with regard to the <em>technical </em>contract that has to be met by the calling code, i.e. the developer, not a business contact that has to be met by the user. See <a href="http://ajdotnet.wordpress.com/2009/07/19/the-rules-of-the-game/" target="_blank">my post on error handling and responsibilities</a> for more on that topic.</p>
</blockquote>
<blockquote><p>Note 2: In terms of <a href="http://en.wikipedia.org/wiki/Design_by_contract" target="_blank">design by contract</a>, Guard classes express the <i>preconditions</i> of an operation, something that has been baked into <a href="http://en.wikipedia.org/wiki/Eiffel_(programming_language)#Design_by_Contract" target="_blank">other programming languages</a> right from the start. </p>
</blockquote>
<p><strong>Self preservation.</strong></p>
<p>If you are working in a team, you inadvertedly have to work with other team members. Good ones, bad ones. <em>And you may want to protect yourself against the later… .</em></p>
<p>Face it: If a <em>NullReferenceException </em>arises, the developer who wrote that particular code fragment – mayhap <em>you </em>– is held responsible (<a href="http://en.wikipedia.org/wiki/Gunshot_injury" target="_blank">shot on first sight</a>, so to speak). Even if it turned out later that the calling code passed some illegal <em>null </em>value… . Well, problem solved, but the stigma sticks, and anyone will only remember that the exception was thrown in <i>your</i> code.</p>
<p>How do you protect yourself against that? Guard classes. If the calling code just passed some crap data – despite you having told that guy what to pass a hundred times – just throw it right back into his face. That’s what <em>ArgumentException</em>s are for: complaining loud and clear about someone unduly misusing your code. Be the accusator, not the accused!</p>
<blockquote><p>BTW: If you’re on the callers side and the method you just called returned a value, you may achieve something similar with <em>Debug.Assert</em>.</p>
<p>For example if you had written that code above, and I knew you to be a sloppy developer, I would <i>certainly</i> check the return value. And if I were as mean as you are sloppy, I would deliberately call it passing <em>Guid.Empty </em>as <em>companyID</em>. And if you dared to hand back that pesky <em>null </em>instead of an empty enumeration I would &#8230; . </p>
<p>Well, never mind. You‘re not sloppy, I‘m not mean, and I only put that bug in to stress the fact that Guard classes only work up the call chain, not down. (And yes, it’s a bug to return <em>null</em> in the above case. Methods supposed to be used in a LINQ context have to comply with LINQ demands, which are based on functional programming, which boils down to „no <em>null</em>s please!“)</p>
</blockquote>
<p><strong>Robustness </strong>(or: making errors apparent).</p>
<p>Someone passed <em>null </em>or some other unwanted value to a method. There are actually two bad things that might happen:</p>
<ol>
<li>The application may crash further down.</li>
<li>The wrong value may affect some data, but the application continues to work.</li>
</ol>
<p>Number one may be bad, but at least the application crashes (which is a good thing!). Still, in this case Guard classes will help you identify the error far earlier, possibly avoiding a situation where you’ll have to hunt for the root cause of a problem. This should at least help diagnosing the problem.</p>
<p>Number two is far worse. It’s actually the very situation that you would want to avoid <em>at any cost</em>: A bug that stays unnoticed. A bug that occasionally produces wrong data, and that lingers around long enough to seriously affect data consistency to a degree that renders <em>all </em>data useless, because you have no way of knowing which data was affected and which not. Technically just a tiny slip, but in the long run these bugs are the most harmful.</p>
<p>To guard against these bugs Guard classes put up another safety net. Make sure the data coming in matches the specification. </p>
<p>Essentially both issues neatly demonstrate what „<a href="http://en.wikipedia.org/wiki/Fail-fast" target="_blank">fail early, fails fast</a>“ is about. Making errors apparent, prevent them from being obscured and from causing damage further down the line.</p>
<p><strong>And that’s it…</strong></p>
<p>Quite some task for a tiny little helper – but really worth the effort. Should you need some kick-start to employ this concept yourself, I posted the code for a Guard class <a href="http://ajdotnet.wordpress.com/guard-class/" target="_blank">here</a>. Use it, enhance it, employ it to make you life easier.</p>
<p>HIH!</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f08%2f01%2fposting-guards-guard-classes-explained%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f08%2f01%2fposting-guards-guard-classes-explained%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, C#, Software Developers, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/325/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=325&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/08/01/posting-guards-guard-classes-explained/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f08%2f01%2fposting-guards-guard-classes-explained%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Playing game&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2009/07/26/playing-game/</link>
		<comments>http://ajdotnet.wordpress.com/2009/07/26/playing-game/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 13:17:56 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=314</guid>
		<description><![CDATA[We’ve defined the problem, we’ve established the rules, now we are ready to actually play the game. In other words: We will employ consistent and sufficient exception management in an ASP.NET application. No less! Note: What follows is merely a sample implementation, just to drive the ball home, but it should turn my earlier musings [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=314&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We’ve <a href="http://ajdotnet.wordpress.com/2009/07/12/playing-ball-with-exceptions/" target="_blank">defined the problem</a>, we’ve <a href="http://ajdotnet.wordpress.com/2009/07/19/the-rules-of-the-game/" target="_blank">established the rules</a>, now we are ready to actually play the game. In other words: We will employ <em>consistent and sufficient exception management</em> in an ASP.NET application. No less!</p>
<blockquote><p>Note: What follows is merely a sample implementation, just to drive the ball home, but it should turn my earlier musings into a little more practical advice. And since this is only meant to highlight the principle, not to provide a production ready solution, I’ll keep it simple.</p>
</blockquote>
<p><strong>Exception classes</strong></p>
<p>First let’s try to classify our exceptions, depending on the supposed effect. This classification is sort of the driving force behind the strategy: who is responsible, or more to the point how to tell the responsible people&#8230;</p>
<p>A quick reminder on what our goal is:</p>
<ol>
<li>The user has to solve everything that results from his user user interaction in due process. This includes invalid input, insufficient permissions, or other business conditions that interrupt the current functionality. </li>
<li>The administrator is responsible for infrastructure issues. This includes every call into the „outside world“, such as databases, services, file system. Issues here are manifold, including:
<ul>
<li>unavailable database or service </li>
<li>errors during some operation, e.g. unexpected a constraint violations </li>
<li>erroneous configuration </li>
</ul>
</li>
<li>Everything else: Bugs. Developer. You! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  </li>
</ol>
<p>So consequently:</p>
<ul>
<li>If the user is responsible, we just tell him on the page and let him choose what to do. </li>
<li>If the administrator is responsible, we show a general error page, telling the user that the application is not available, and of course we write some event log entry. </li>
<li>If the developer is responsible, we do the same, but we tell the administrator explicitly to forward the event log information to the development team. </li>
</ul>
<p>I’ll spare you the boilerplate exception implementation details, suffice it to say that we have a <em>UserIsResponsibleException</em> for “user exceptions” and a <em>AdminIsResponsibleException</em> for “admin exceptions”, respectively. Names that wouldn’t make it into <em>my </em>production code, but that’s what their intention is, anyway. Oh, and add a <em>ConcurrencyException</em> exception for respective issues, they may or may not be user exceptions, depending on the context.</p>
<p>Now let’s put the handlers in place. These reside in the UI layer, and from there we can work through the architectural layers towards the databases.</p>
<p><strong>User error handlers</strong></p>
<p>User exceptions have to be handled on the page level. Whenever you call into some business layer method, say from a button click event handler, you wrap the call in a <em>try/catch(respective exceptions)</em>. The exception is then presented to the user, and eaten, meaning it is not thrown along. Something like this:</p>
<blockquote><p><font color="#0000ff">protected</font> <font color="#0000ff">void</font> btnConcurrentUpdate_Click(<font color="#0000ff">object</font> sender, EventArgs e)     <br />{     <br />&#160;&#160;&#160; <font color="#0000ff">try</font>     <br />&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; BusinessLogic bl = <font color="#0000ff">new</font> BusinessLogic();     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; bl.UpdateDatabaseWithConcurrencyIssue(<font color="#800000">&quot;some content&quot;</font>);     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblConcurrentUpdate.Text = <font color="#800000">&quot;did it.&quot;</font>;     <br />&#160;&#160;&#160; }     <br />&#160;&#160;&#160; <font color="#0000ff">catch</font> (UserIsResponsibleException ex)     <br />&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#008000"><i>// just give feedback and we&#8217;re done</i></font>     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; PresentError(ex);     <br />&#160;&#160;&#160; }     <br />&#160;&#160;&#160; <font color="#0000ff">catch</font> (ConcurrencyException ex)     <br />&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#008000"><i>// just give feedback and we&#8217;re done</i></font>     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; PresentError(ex);     <br />&#160;&#160;&#160; }     <br />} </p></blockquote>
<p>The way of presenting the error message is something that has to be decided per application. You could write the message to some status area on the page, you could send some java script to pop up a message box. You could even provide a validator that checks for a recent user exception and works with the validation summary for the feedback.</p>
<p>Statistics:</p>
<ul>
<li>Exception classes: Write once. </li>
<li>Presentation: Write once. </li>
</ul>
<p>The try/catch code is simple enough, yet you have to do it again and again, and should the need for another user exception arise (e.g. some user errors can be handled on the page, some others require leaving the page), the logic is spread across our pages. Thus it makes sense to factor the actual handling into a separate method, in a helper class, or a page base class. Now, catching specific exceptions is still part of our job and that cannot be factored out. To solve this we have three options: </p>
<ol>
<li>Build the exception hierarchy accordingly and catch the base class for user exceptions. </li>
<li>Catch all exceptions and throw the unwanted exceptions on. </li>
<li>Live with the problem. </li>
</ol>
<p>I decided against option 1 because I didn’t want the concurrency exception to be derived from some user exception. Option 3 is what we wanted to avoid in the first place. So my solution is number 2, in the name of ease of use and maintenance, but at the expense of language supported exception handling features:</p>
<blockquote><p><font color="#0000ff">protected</font> <font color="#0000ff">void</font> btnConcurrentUpdate_Click(<font color="#0000ff">object</font> sender, EventArgs e)       <br />{       <br />&#160;&#160;&#160; <font color="#0000ff">try</font>       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; BusinessLogic bl = <font color="#0000ff">new</font> BusinessLogic();       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; bl.UpdateDatabaseWithConcurrencyIssue(<font color="#800000">&quot;some content&quot;</font>);       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblConcurrentUpdate.Text = <font color="#800000">&quot;did it.&quot;</font>;       <br />&#160;&#160;&#160; }       <br />&#160;&#160;&#160; <font color="#0000ff">catch</font> (Exception ex)       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#008000"><i>// since C# does not support exception filters, we need to catch</i></font>       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#008000"><i>// all exceptions for generic error handling; throw those on, that</i></font>       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#008000"><i>// have not been handled…</i></font>       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">if</font> (!HandleUserExceptions(ex))       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">throw</font>;       <br />&#160;&#160;&#160; }       <br />}</p>
</blockquote>
<p>This is boilerplate and unspecific enough to copy&amp;paste it around. The generic handler may look like this:</p>
<blockquote><p><font color="#0000ff">bool</font> HandleUserExceptions(Exception ex)       <br />{       <br />&#160;&#160;&#160; <font color="#0000ff">if</font> (ex <font color="#0000ff">is</font> ConcurrencyException)       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#008000"><i>// just give feedback and we&#8217;re done</i></font>       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; PresentError(ex);       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">return</font> <font color="#0000ff">true</font>;       <br />&#160;&#160;&#160; }       <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#0000ff">if</font> (ex <font color="#0000ff">is</font> UserIsResponsibleException)       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#008000"><i>// just give feedback and we&#8217;re done</i></font>       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; PresentError(ex);       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">return</font> <font color="#0000ff">true</font>;       <br />&#160;&#160;&#160; }       <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#008000"><i>// other errors throw on&#8230;</i></font>       <br />&#160;&#160;&#160; <font color="#0000ff">return</font> <font color="#0000ff">false</font>;       <br />} </p>
</blockquote>
<p>Statistics:</p>
<ul>
<li>Handler method: Write once. </li>
<li>Catching exceptions: Every relevant location, boilerplate copy&amp;paste </li>
</ul>
<p>Please note that <a href="http://msdn.microsoft.com/en-us/library/4dy8x9k9(VS.71).aspx" target="_blank">exception filters</a> might make this a little less coarse, but this is one of the rare occasions, where a CLR feature is not available to C# programmers. Anyway, we just factored all logic into a centralized method which achieves exactly what we asked for.</p>
<p>But wait… . Wouldn’t the <em>Page.Error </em>event provide a better anchor? It’s already there and no need to add try/catch around every line of code. Look how nice:</p>
<blockquote><p><font color="#0000ff">protected</font> <font color="#0000ff">void</font> btnConcurrentUpdate_Click(<font color="#0000ff">object</font> sender, EventArgs e)       <br />{&#160; <br />&#160;&#160;&#160; BusinessLogic bl = <font color="#0000ff">new</font> BusinessLogic();&#160; <br />&#160;&#160;&#160; bl.UpdateDatabaseWithConcurrencyIssue(<font color="#800000">&quot;some content&quot;</font>);&#160; <br />&#160;&#160;&#160; lblConcurrentUpdate.Text = <font color="#800000">&quot;did it.&quot;</font>;       <br />}       </p>
<p><font color="#0000ff">protected</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> OnError(EventArgs e)       <br />{       <br />&#160;&#160;&#160; <font color="#008000"><i>// raise events</i></font>       <br />&#160;&#160;&#160; <font color="#0000ff">base</font>.OnError(e);       <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; var ex = Server.GetLastError();       <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#008000"><i>// if we don&#8217;t clear the error, ASP.NET</i></font>       <br />&#160;&#160;&#160; <font color="#008000"><i>// will continue and call Application.Error</i></font>       <br />&#160;&#160;&#160; <font color="#0000ff">if</font> (HandleUserExceptions(ex))       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Server.ClearError();       <br />}</p>
</blockquote>
<p>Unfortunately at the time the error event is raised, the exception will already have disrupted the page life cycle and rendering has been broken. It may help in case you need a redirect, but not if the page should continue to work.</p>
<p><strong>“Other” error handlers</strong></p>
<p>So, the page handles user exceptions, what about admin and system exceptions? The page doesn’t care, so they wind up the chain and ASP.NET will eventually pass them to the application, via the <em>Application.Error </em>event, available in the <em>global.asax</em>. This is the “last chance exception handler” or LCEH for short.</p>
<p>One thing we did want to do was writing the exception into the event log. I’ll leave actually writing into the event log to you, just remember that creating an event log source requires respective privileges, e.g. running as admin. Just a minor deployment hurdle. </p>
<blockquote><p><font color="#0000ff">protected</font> <font color="#0000ff">void</font> Application_Error(<font color="#0000ff">object</font> sender, EventArgs e)     <br />{     <br />&#160;&#160;&#160; Exception ex = Server.GetLastError();     <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#008000"><i>// unpack the exception</i></font>     <br />&#160;&#160;&#160; <font color="#0000ff">if</font> (ex <font color="#0000ff">is</font> HttpUnhandledException)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ex = ex.InnerException;     <br />&#160;&#160;&#160; Session[<font color="#800000">&quot;exception&quot;</font>] = ex;     <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#008000"><i>// write detailed information to the event log&#8230;</i></font>     <br />&#160;&#160;&#160; WriteInformationToEventLog(ex);     <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#008000"><i>// tell user something went wrong</i></font>     <br />&#160;&#160;&#160; Server.Transfer(<font color="#800000">&quot;Error.aspx&quot;</font>);     <br />}     </p>
<p><font color="#0000ff">private</font> <font color="#0000ff">void</font> WriteInformationToEventLog(Exception ex)     <br />{     <br />&#160;&#160;&#160; <font color="#008000"><i>// an ID as reference for the user and the admin</i></font>     <br />&#160;&#160;&#160; ex.Data[<font color="#800000">&quot;ErrorID&quot;</font>] = GenerateEasyToRememberErrorID();     <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#0000ff">string</font> whatToDoInformation;     <br />&#160;&#160;&#160; <font color="#0000ff">if</font> (ex <font color="#0000ff">is</font> AdminIsResponsibleException)     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; whatToDoInformation = <font color="#800000">&quot;Admin, you better took care of this!&quot;</font>;     <br />&#160;&#160;&#160; <font color="#0000ff">else</font>     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; whatToDoInformation = <font color="#800000">&quot;Admin, just sent the information to the developer!&quot;</font>;     <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#008000"><i>// put as much information as possible into the eventlog, </i></font>    <br />&#160;&#160;&#160; <font color="#008000"><i>// e.g. write all exception properties into one big exception report,</i></font>     <br />&#160;&#160;&#160; <font color="#008000"><i>// including the Exception.Data dictionary and inner exceptions.</i></font>     <br />&#160;&#160;&#160; <font color="#008000"><i>// also include information about the request, the user, etc.        <br /></i></font>    <br />&#160;&#160;&#160; …     <br />} </p></blockquote>
<p>As you can see, there are some details to keep in mind. One, the exception has been wrapped by the ASP.NET runtime, and that exception class doesn’t tell you anything worthwhile. Second, passing information to the error page may be a little tricky in cases where the request has not yet (or not at all) established the session state. The easier approach is to let ASP.NET handle the redirection, yet at the loss of information. Three, be careful regarding the requests: depending on the IIS version you may get only .aspx requests, or any request including static resources. Thus, with this simplistic implementation a missing image will send you to the error page depending on the IIS version and registered handlers. </p>
<p>I would also like to encourage you to spend some time on collecting information for the event log message. A simple <em>ex.ToString() </em>doesn’t reveal that much information if you look closely. You should invest some time to add information about the current request (URL, etc.), the user (name, permissions), and server state (app domain name, to detect recycling issues). And use reflection to get all information from the exception, especially including the <em>Exception.Data </em>dictionary. Also go recursively through the inner exceptions. The more information you provide, the better.</p>
<p>I also hinted at an error ID. It is probably a good idea to give the user some ID to refer to when he talks to the admin. This way, the admin will know exactly what to look for in the event log (especially in multiple event logs of a web farm).</p>
<p>Finally, the exception class tells us whether we should include an “Admin, do your job!” or “Kindly forward this issue to your fellow developer, brownies welcome, too.” message. </p>
<p>And by the way: This is the one and only location in our application that writes to the event log!</p>
<p>Statistics:</p>
<ul>
<li>Global error handler: Write once. </li>
</ul>
<p>Done. We have the handlers in place. Handlers for user exceptions, admin issues, and any other exception that might be thrown. Now we need to take care that error causes are mapped to the respective exception class.</p>
<p><strong>Business layer</strong></p>
<p>The business logic is being called from the UI layer, and calls into the data access layer. Thus it has to check parameters coming in, as well as data handed back from the data source.</p>
<p>Data coming in hast to comply with the contract of the business class, and I’d like to stress the fact that <i>not every data is legal</i>. Meaning the business logic is not expected to accept every crap the UI layer might want to pass. A search method that takes a filter class as parameter? No harm in defining this parameter mandatory and require the UI to pass an instance, even if it is empty. And a violation is not the user’s problem, it’s the programmer’s fault! In these cases we throw an <em>ArgumentException</em>, and that’s it. The LCEH will take care of the rest, blaming the UI developer that is.</p>
<blockquote><p><font color="#0000ff">public</font> IEnumerable&lt;Customer&gt; SearchCustomer(SearchCustomerFilter filter)     <br />{     <br />&#160;&#160;&#160; <font color="#008000"><i>// preconditions have to be met by the calling code</i></font>     <br />&#160;&#160;&#160; Guard.AssertNotNull(filter, <font color="#800000">&quot;filter&quot;</font>);     <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#008000"><i>// input values have to be provided by the user</i></font>     <br />&#160;&#160;&#160; <font color="#0000ff">if</font> (<font color="#0000ff">string</font>.IsNullOrEmpty(filter.Name))     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">throw</font> <font color="#0000ff">new</font> UserIsResponsibleException(<font color="#800000">&quot;provide a filter value&quot;</font>);     <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; DatabaseAccess db = <font color="#0000ff">new</font> DatabaseAccess();     <br />&#160;&#160;&#160; <font color="#0000ff">return</font> db.SearchCustomer(filter);     <br />} </p></blockquote>
<p>Any issue with the content of the data, i.e. the information the user provides, is a user issue. Usually this includes data validations and if you follow the rule book you’ll have to repeat everything the UI already achieved via validators. Whether you do that or just provide additional checks, e.g. dependencies between fields, is something I leave to you. Anyway, throw a user exception if the validation fails.</p>
<p>Calling the data access layer may also result in thrown exceptions. Usually there is no need to catch them at all. Period.</p>
<p>Finally the data you get from the database may ask for some interruption. A customer database may tell you that this particular customer doesn’t pay his dues, thus no business with him. In this case you throw a user exception in order to interrupt the current business operation.</p>
<p>And that’s it.</p>
<p>Statistics:</p>
<ul>
<li>Business validations and interruptions: As the business logic demands… </li>
</ul>
<p>“Uhh, that’s it? And I used to spend so much time on error handlers in my business logic…”. Nice, isn’t it? Just business logic, no unrelated technical demand.</p>
<p><strong>Data access layer</strong></p>
<p>The data access layer is where many exceptions come from. If you call a data source (web service, database, file system, whatever), the call may fail because the service is unavailable. Or it may fail because the called system reports an error (constraint violation, sharing violation, …). It may time out. Some exceptions won’t require any special handling and you can leave them alone. Some need to be promoted to admin or user exceptions, or they may require special handling for some reason. You should&#160; translate those exceptions to respective application exceptions. The reason is&#160; that you don’t want to bleed classes specific to a data source technology (e.g. LINQ 2 SQL exceptions) into the upper layers, introducing undue dependencies. </p>
<p>Luckily all this tends to be as boilerplate as can be. Call/catch/translate. With always the same catches. So, again, we can provide a “once and for all” (at least per data source technology) exception handler, like this one for the ADO.NET Entity Framework:</p>
<blockquote><p><font color="#0000ff">public</font> IEnumerable&lt;Customer&gt; SearchCustomer(SearchCustomerFilter filter)       <br />{       <br />&#160;&#160;&#160; <font color="#0000ff">try</font>       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">using</font> (DatabaseContainer db = <font color="#0000ff">new</font> DatabaseContainer())       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#008000"><i>//&#8230;</i></font>       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br />&#160;&#160;&#160; }       <br />&#160;&#160;&#160; <font color="#0000ff">catch</font> (DataException ex)       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; TranslateException(ex);       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#008000"><i>// any exception not translated is thrown on&#8230;</i></font>       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">throw</font>;       <br />&#160;&#160;&#160; }       <br />}</p>
</blockquote>
<p>And the respective translation method:</p>
<blockquote><p><font color="#0000ff">static</font> <font color="#0000ff">void</font> TranslateException(Exception ex)       <br />{       <br />&#160;&#160;&#160; <font color="#008000"><i>// database not available, command execution errors, mapping errors, &#8230;</i></font>       <br />&#160;&#160;&#160; <font color="#0000ff">if</font> (ex <font color="#0000ff">is</font> EntityException)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">throw</font> <font color="#0000ff">new</font> AdminIsResponsibleException(<font color="#800000">&quot;&#8230;&quot;</font>, ex);       <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#008000"><i>// translate EF concurrency exception to application concurrency exception</i></font>       <br />&#160;&#160;&#160; <font color="#0000ff">if</font> (ex <font color="#0000ff">is</font> OptimisticConcurrencyException)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">throw</font> <font color="#0000ff">new</font> ConcurrencyException(<font color="#800000">&quot;&#8230;&quot;</font>, ex);       <br />&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; <font color="#008000"><i>// constraint violations, etc.</i></font>       <br />&#160;&#160;&#160; <font color="#008000"><i>// this may be caused by inconsistent data</i></font>       <br />&#160;&#160;&#160; <font color="#0000ff">if</font> (ex <font color="#0000ff">is</font> UpdateException)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0000ff">throw</font> <font color="#0000ff">new</font> AdminIsResponsibleException(<font color="#800000">&quot;&#8230;&quot;</font>, ex);       <br />} </p>
</blockquote>
<p>Statistics:</p>
<ul>
<li>Translation method: Write once. </li>
<li>Catching exceptions: Every relevant location, boilerplate copy&amp;paste </li>
</ul>
<p><strong>Conclusion:</strong></p>
<p>Done. Let’s sum up the statistics:</p>
<ul>
<li>Write once (at least partly reusable in other applications):
<ul>
<li>Application exception classes </li>
<li>Last chance exception handler (LCEH) </li>
<li>Handler method for user errors, including presenting the error </li>
<li>Exception translation method in DAL          </li>
</ul>
</li>
<li>Boilerplate copy&amp;paste
<ul>
<li>Catching exceptions in the UI, call handler </li>
<li>Catching exceptions in the DAL, call translation          </li>
</ul>
</li>
<li>Application code that still needs a brain <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />
<ul>
<li>Business validations and interruptions: As the business logic demands… </li>
</ul>
</li>
</ul>
<p>And this is all we have to do with regard to exception handling in our application. I’ll let that speak for itself… .</p>
<p>This post concludes this little series about the state of affairs regarding error handling in an application. I do not claim to have presented something particularly new or surprising. Rather the opposite, this or some similar strategy should be considered best practice. The reason to even start this series was the fact that I regularly encounter code that does exception handling … <em>questionably</em>. And I also regularly met people who look at exception handling only in the scope of the current code fragment, not in light of a broader approach that spans the application.</p>
<p>If you need further motivation to employ proper error handling in the first place, look <a href="http://ajdotnet.wordpress.com/2007/11/04/robust-operations/" target="_blank">here</a>.     <br />A little more on error management in long running, asynchronous scenarios can be found <a href="http://ajdotnet.wordpress.com/2007/11/11/error-handling-is-error-management/" target="_blank">here</a>. </p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f07%2f26%2fplaying-game%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f07%2f26%2fplaying-game%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, ASP.NET, C#, Software Architecture, Software Developers, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/314/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=314&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/07/26/playing-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f07%2f26%2fplaying-game%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>The Rules of the Game</title>
		<link>http://ajdotnet.wordpress.com/2009/07/19/the-rules-of-the-game/</link>
		<comments>http://ajdotnet.wordpress.com/2009/07/19/the-rules-of-the-game/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 12:29:34 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=310</guid>
		<description><![CDATA[With the last post I tried to establish the problem: The fact that exception handling needs more than try/catch. That it needs a proper exception management strategy, which should be part of the application architecture. And I paid special attention to the paradox demand that exception management should work when everything else fails. Now, I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=310&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>With the <a href="http://ajdotnet.wordpress.com/2009/07/12/playing-ball-with-exceptions/" target="_blank">last post</a> I tried to establish the problem: The fact that exception handling needs more than try/catch. That it needs a proper exception management strategy, which should be part of the application architecture. And I paid special attention to the paradox demand that exception management should work when everything else fails.</p>
<p>Now, I cannot provide THE strategy, for there is no such thing. But I may present one feasibly approach that has served me well, quite a few times. I’ll simplify quite a bit, but it is nonetheless a complete approach that may serve as starting point for more complex demands.</p>
<p>OK, let’s play…</p>
<p><a href="http://www.fotocommunity.de/pc/pc/mypics/634598/display/9947597" target="_blank"><img style="display:block;float:none;margin-left:auto;margin-right:auto;" src="http://ajdotnet.files.wordpress.com/2009/07/9947597.jpg?w=800&#038;h=209" width="800" height="209" /></a></p>
<p>To define the playing field: The following is about classical n-Tier ASP.NET web applications, and I have decided to represent user induced issues, like business validation errors, as exceptions.</p>
<p><strong>Some Groundwork</strong></p>
<p>Exceptions are used for different error conditions, but also for non-erroneous situations, which leads to a surprising variety:</p>
<ul>
<li>Exceptions being thrown as result to <strong>infrastructure issues</strong>. E.g. <em>IOException</em>, <em>SecurityException</em>. They may be caused by invalid configurations, by unavailable infrastructure resources, or for other reasons. </li>
<li>Exceptions representing <strong>errors reported by external services</strong>, like database constraint violations or SOAP exceptions. </li>
<li>Exceptions being thrown because the caller did not meet the expectations of the called code, e.g. a <strong>violation of a contract</strong>. (Usually <em>ArgumentExceptions</em>). </li>
<li>Exceptions being thrown because a <strong>developer’s lapse</strong>. <em>NullReferenceException</em>. </li>
<li>Exceptions being thrown to <strong>sidestep the current flow of control</strong>, e.g. <em>HttpResponse.Redirect() </em>throws a <em>ThreadAbortException</em> to prevent an ASP.NET page from further unnecessary processing. </li>
<li><strong>Business validation errors</strong>. The business logic decides that – despite proper input validation – something is not quite as it should be. Not exactly an error in a technical sense, but the processing simply cannot go on. </li>
<li><strong>User concurrency issues</strong>. Like some user wants to update some data that has been changed by someone else in the meantime. And “last one wins” may not be good enough. </li>
</ul>
<blockquote><p>Please note that while <em>Basic Rule Number 1</em> for exception handling (<a href="http://msdn.microsoft.com/en-us/library/ms998547.aspx#scalenetchapt05_topic24" target="_blank">no abuse of exceptions for non-exceptional conditions</a>) is as valid as ever, there are certainly <em>exceptions</em> (no pun intended) to that rule. For example, aborting the request upon redirection certainly makes sense; (ab)using an exception to do so may violate said rule, yet it is far more efficient and convenient than any other alternative. The same may be true for business validation errors. Not exceptional, yet exceptions may be the most convenient way to accommodate them.</p>
</blockquote>
<p>This is a (perhaps surprising) variety and may even be incomplete – actually that variety is a major contributor to the complexity of exception handling. And yet, it is only half of the equation. Exceptions have cause <em>and </em>effect, and I found that tackling exception handling from the opposite angle, the <em>effect </em>that is, has certain advantages. </p>
<p>But before we come to that, there’s a question that has to be answered…</p>
<p><strong>What is the <em>purpose</em>, the <em>intention </em>of throwing exceptions?</strong> (Seriously!)</p>
<p>This is a question one should ask at least once, even so it may seem a bit superfluous. For the answer does <i>not</i> include some of the usually mentioned suspects: Preventing <a href="http://en.wikipedia.org/wiki/Data_consistency" target="_blank">data inconsistencies</a>? Let’s simplify a bit and state that this is the job of <a href="http://en.wikipedia.org/wiki/Database_transaction" target="_blank">transactions</a>. Gracefully shut down? An error happened, what do I care how the application goes down.</p>
<p>Actually it’s far simpler: An error happened! Something which the developer didn’t anticipate or couldn’t cope with. The primary purpose of exceptions is <em><u>to communicate that situation</u></em>. And exception <em>handling </em>in turn it is about notifying everyone involved in the appropriate way, telling them what they are supposed to do now, either to compensate the issue or to prevent it from happening again. In other words: It’s about <em>responsibilities </em>emerging out of this error.</p>
<p>And this is what my strategy revolves around: <strong><em>Responsibilities</em></strong>.</p>
<p><strong>An Exception Handling Strategy</strong></p>
<p>Back to cause and effect, and let’s start by the later one. More to the point, the <em>desired </em>effect, driven by what is actually <em>asked </em>for in case of an error (rather than what could be done). This will lead to a strategy that is more simple, easier to understand, and easier to implement. </p>
<p>As I mentioned ‘responsibilities’ the first question is kind of obvious:</p>
<p><strong>Question #1: <u>Who should be responsible for what?</u></strong></p>
<p>This is no esoteric question aiming at pieces of architecture or code. Rather it’s asking which person has to shoulder the work (or the blame, if you like):</p>
<ol>
<li>The Administrator: He has to solve problems caused by infrastructure issues (such as invalid configuration entries, unavailable databases, and so on). </li>
<li>The User himself: Let him deal with errors caused by invalid input, other users working simultaneously with the same data, or in some other way inherent to the intended usage of the product. <a href="http://en.wikipedia.org/wiki/Rtfm" target="_blank">RTFM</a>! </li>
<li>The developer (YOU!): Anything else falls back on the developer’s desk. </li>
</ol>
<p>Obviously the last point is the inconvenient part: Every exception defaults to that category, unless the developer explicitly “tells” someone else that he is responsible. Let’s stress that: An error caused by an invalid configuration entry is the developer’s problem – unless he explicitly tells the administrator that <em>he </em>should take care of this.</p>
<p>So, now we are back where we started right at the beginning, at the developer’s desk. The difference is that the developer now has some specific goal: Lay the blame on someone else&#8217;s doorstep!</p>
<blockquote><p>This is actually a very important point. Making someone else responsible is in the developer’s own interest. It helps him avoiding unnecessary and annoying future work. Quite motivating if you ask me.</p>
</blockquote>
<p>This makes the next question obvious:</p>
<p><strong>Question #2: <u>How does the developer tell the user or the administrator that <em>he </em>is to take responsibility?</u></strong></p>
<p>The answer is simple: Provide the necessary feedback, e.g. a message box or an event log entry; in more detail:</p>
<ul>
<li>In case of a user error you tell him with a message box, a popup, within some message area or on a special “you did wrong!” page.      <br />You don’t tell the admin, because he doesn’t care for typos. Neither do you as developer. </li>
<li>In case of an infrastructure issue you show a standard message to the user, telling him to call the admin and come back later. You don’t want to include details, because they might include security relevant information, such as the always cited database connection string.      <br />Additionally you have to give the admin all information he needs, usually within the event log. </li>
</ul>
<p>In both cases it’s important that you provide not only the information that an error has occurred (that much is obvious, isn’t it?). You need to include information on <i>how to solve it</i>. Otherwise it will eventually again be up to you, the developer, to solve the issue. That’s why it makes sense not to stop at “couldn’t save data” or “data source not available”. Rather invest some work – in your own self-interest – in providing “Customer data could not be save because it is locked by user ‘XYZ’” or “Database not available, connection string:=…”.</p>
<ul>
<li>Remember the last case: In case of technical issues for which the developer is responsible, you still have to tell the user and the admin something. The user should again get some standard error page (not the ASP.NET error page!), the admin should get an event log entry that tells him to notify the developer. This entry should include as much information as possible for a post mortem diagnosis. </li>
</ul>
<p>So, essentially this paragraph revolved around <em>presenting </em>an exception, at the UI level where the information leaves the area of your application code. It’s quite simple to implement that, because you can rely on centralized features: ASP.NET provides a global error handler that can be used to provide standard event log entries. Presenting user errors on a page should be boilerplate as well, the only distinction being whether the current page and data is still valid (just show a message box) or not (redirect to some business error page). Nice, easy, and no rocket science.</p>
<p>Of course in order to do this we need a means of distinguishing those three cases. For this, all you need is respective exception classes, two actually. One <em>BlameTheUserException </em>and another <em>BlameTheAdminException</em>. You don’t need a <em>BlameTheDeveloperException</em>, because he is already to blame for every other exception, no need to stress that <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p><strong>Question #3: <u>Who to put exceptions to work… ?</u> </strong></p>
<p>If the developer’s goal is to blame someone else, then this goal can guide him answering the more detailed questions, such as, where in his code should he be catching exceptions (where not)? When should he throw exceptions (when not)? What about logging? And so on. Everything else follows as consequence…</p>
<p>First about <strong>throwing exceptions</strong>. Yes, not only the system throws exceptions; you may do the same, and no need to be shy about it. Sprinkle your methods with guard calls throwing argument exceptions, they imply coding errors on the callers side. If the code allows certain conditions that are logically impossible, guard yourself against that impossibility. Throwing exceptions in exceptional cases is no problem at all. Actually it is by far the preferred way to react this harshly, rather than obscuring erroneous conditions because of <a href="http://www.thehackerchickblog.com/2009/05/plane-crashes-software-failures-and.html" target="_blank">falsely understood modesty</a>. Fail early, fail often!</p>
<p><strong>Handling exceptions</strong>, as in solving the problem once and for ever is of course possible. If it <i>is</i> possible – which is in my experience rarely the case. (It had to be mentioned, though.)</p>
<p><strong>Enriching exception information </strong>is a more frequent task. Whenever it makes sense for the post mortem diagnosis, you should add context information to the exception. Adding the actual SQL statement and the connection string to a database error, adding the user name and the accessed resource to security exceptions. This is valuable, if not necessary, to diagnose the root cause of the problem. It’s not even necessary to wrap the exception to do that, since the exception class has a dictionary <em>Data</em> for this very purpose.</p>
<p><strong>Promoting exceptions</strong>: Once your code is able to decide that a certain error is an administration or user problem, you should wrap it in the respective class, thus “promoting” it.     <br />This sentence implies the fact that not every location is suited to make that decision. The database layer should probably never decide whether a particular error is the consequence of some erroneous user action; this usually depends on the business context in which it is called, and should be decided there. Infrastructure issues on the other hand happen very low in the call chain and couldn’t even be decided further up.     <br />The real work here lies in actually putting in the necessary handlers. However they tend to gather in classes that deal with the outside world, the database, configuration, some service, or whatever. They also tend to be very boilerplate.</p>
<p>That’s it. … Wait! … That’s not possible! </p>
<p><strong>Question #4: <u>Can that really be all?</u></strong></p>
<p>Actually this is it. No “every method should…”. No “layer specific exceptions…”. No “log it just in case…”. Actually whenever I tell people how to implement an exception handling strategy in an existing application, the majority of the work is <i>removing</i> exception handlers. Sometimes life can be so easy.</p>
<blockquote><p>In case it escaped you: If the developer doesn&#8217;t have to do something to employ proper exception management, he can’t do anything wrong. We don’t have to rely on him to properly handle his own bugs. We just solved a paradoxon!</p>
</blockquote>
<p>Going further, I even consider it an issue by itself if you did <em>too much </em>exception handling!</p>
<p>For example “shouldn’t we at least log the error, just in case?” No, you shouldn’t. The global error handler is responsible for doing that, so there is no <i>need</i> to log it. Worse, if the calling code decided to handle the situation and carry on, there is by definition no application issue at all. And yet the event log would show one, waking the admins for no reason, or flooding the event log and obscuring the one important entry.</p>
<p><strong>So what? That’s a strategy?</strong></p>
<p><a href="http://www.fotocommunity.de/pc/pc/mypics/634598/display/9965114" target="_blank"><img style="display:inline;margin:0 0 5px 5px;" title="" alt="" align="right" src="http://ajdotnet.files.wordpress.com/2009/07/9965114_1.jpg?w=209&#038;h=300" width="209" height="300" /></a></p>
<p>Yes it is. Check the demands the initial questions if you like, they’re all accounted for. Take some file that doesn’t exist. Either you did nothing to anticipate that situation, then an <em>IOException</em> will ensue. Neither user nor admin are taking care of this, so it’s back on your desk. Or you did handle it and threw a <em>BlameTheAdminException</em>.</p>
<p>Of course I simplified quite a bit, but not at the expense of the concept, only in terms of features. For example you may need to have different reactions for the user, some errors calling for a message box, other calling for a redirect. Similarly some unavailable service may allow retrying rather than requiring aborting the whole application. Or you may need additional exception classes to handle them in code. Anyway, nothing of this affects the strategy as such.</p>
<p>Once you’ve established such a strategy, every decision you make on the code level becomes easier, and more confident. And what’s more, in my experience it streamlines error handling, makes it more robust, and frequently simplifies the code by removing unnecessary exception handling. Because quite often if someone asks for exception handling, the answer is “already taken care of, nothing to do”.</p>
<p>Getting back to baseball, every player on the field now knows exactly what he is supposed to do. Some do all the work, most do nothing most of the time&#8230; .</p>
<p>PS: The ending anecdote: <a href="http://leedumond.com/blog/the-greatest-exception-handling-wtf-of-all-time/" target="_blank">http://leedumond.com/blog/the-greatest-exception-handling-wtf-of-all-time/</a></p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f07%2f19%2fthe-rules-of-the-game%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f07%2f19%2fthe-rules-of-the-game%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, ASP.NET, C#, Software Architecture, Software Developers, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/310/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=310&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/07/19/the-rules-of-the-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/07/9947597.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/07/9965114_1.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f07%2f19%2fthe-rules-of-the-game%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Playing Ball With Exceptions</title>
		<link>http://ajdotnet.wordpress.com/2009/07/12/playing-ball-with-exceptions/</link>
		<comments>http://ajdotnet.wordpress.com/2009/07/12/playing-ball-with-exceptions/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 13:57:30 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=300</guid>
		<description><![CDATA[Ever came across an ASP.NET error page because of a missing configuration entry? Been faced with the question “shouldn’t we at least catch the exception and log it? Just to make sure?” or some statement like “you should catch every exception and throw a new one”? Stumbled over the notorious catch-all or a class whose [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=300&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ever came across an ASP.NET error page because of a missing configuration entry? Been faced with the question “shouldn’t we at least catch the exception and log it? Just to make sure?” or some statement like “you should catch every exception and throw a new one”? Stumbled over the notorious catch-all or a class whose methods all do exception handling a bit differently? Well, those are symptoms of a missing error management strategy.</p>
<p>It’s actually quite frustrating how often that happens. What’s more, many developers don’t even notice that there is something amiss; they’re quite content dealing with exception on a method by method basis, without taking the bigger picture into account. <em>Or </em>they are very well aware that there <em>is </em>something amiss, but they don’t get it. They know they have to do something, so they set out to do a bit here, a bit there, but not with a clear goal in mind, nothing consistent, only aiming to treat the symptoms and quite regularly overdoing it.</p>
<p>I really don’t remember what first brought the analogy with <a href="http://en.wikipedia.org/wiki/Baseball" target="_blank">baseball</a>, of all things, to my mind. Perhaps it was the notion that ‘try’, ‘catch’ and ‘throw’ could be outcries during some ball game, combined with my lack of understanding of baseball (a bit stretching, but that’s how mind twists work). Perhaps it was the idea that many developers do exception handling like they would play baseball if they had never heard of the game.</p>
<p>Stretching or not, that analogy is something I can work with. (And my apologies to everyone who loves and understands that game for everything that follows! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> )</p>
<p><strong>A Quick Evaluation of … Baseball.</strong></p>
<p><a href="http://www.fotocommunity.de/pc/pc/mypics/634598/display/9953377" target="_blank"><img style="display:inline;margin:0 0 5px 5px;" src="http://ajdotnet.files.wordpress.com/2009/07/9953377_1.jpg?w=300&#038;h=177" alt="" width="300" height="177" align="right" /></a></p>
<p>Baseball, like all games has rules. Rules that put the various players into roles they have to fulfill. Most importantly, rules you have to learn if you want to play along. Some are fairly basic “mechanics” of the game: The pitcher throws in the general direction of the batter and the catcher does what his title implies (or so <a href="http://en.wikipedia.org/wiki/Baseball#Rules_and_gameplay" target="_blank">wikipedia tells me</a>).<br />
Some rules are obvious by looking at the game: If the batter hits that ball, he drops the bat and runs, while those guys on the field are trying to catch the ball.<br />
Some rules are rather convoluted and you may have to study some booklet to grasp them; like what the hell is an inning and how do they determine who is winning?</p>
<p>That’s about as much as I understand about baseball. But then, would I want to play baseball, I knew I had a lot to learn before even thinking of entering the field. What rules apply to pitching. What <em>roles</em> do those guys on the field have, what are their responsibilities. How to score points. When to move on to the next round. When does the game end. Under what conditions do the rules change. What is considered foul play and when does it lead to aborting the game.</p>
<p>And this is a surprisingly similar situation to exception handling… . Except that many who play <em>that</em> game play it as if there isn’t even the need for rules, much less asked for them (or have been told about them – which is telling something, too).</p>
<p><strong>Back to Exceptions</strong></p>
<p><a href="http://www.fotocommunity.de/pc/pc/mypics/634598/display/9948007" target="_blank"><img style="display:inline;margin:0 5px 5px 0;" src="http://ajdotnet.files.wordpress.com/2009/07/9948007_1.jpg?w=300&#038;h=200" alt="" width="300" height="200" align="left" /></a></p>
<p>The mechanics of exceptions revolve around try/catch/throw and the implied syntax, exception hierarchies, and understanding the runtime behavior. Knowing that much can be expected from every developer and is usually not an issue at all. It is however only just the mechanics, and merely a starting point to proper exception handling.</p>
<p>In the same way the current situation in a game does play a role in baseball (e.g. the batter’s decisions on whether to play safely or to take some risk), the location and situation of a particular code fragment plays a role in the decision on what to do with regard to exceptions. Dealing with them only in the scope of the current code fragment is simply too shortsighted. One has to ask about the overall <em>application strategy to exception handling </em>and how that respective fragment fits <em>into </em>that strategy.</p>
<p>The caveat is: You have to <em>have </em>such a strategy. And defining that strategy should be part of coming up with an application architecture. Yes, exception handling is an architectural topic, not a coding issue.</p>
<p><strong>Exceptions vs. Errors vs. Complexity</strong></p>
<p>As I said, exception handling is an aspect of static and dynamic application architecture, just like security, transaction handling, state management, whatever. But there’s one thing that sets exception handling apart, and that’s dealing with the <em>unexpected</em>, the contradiction of having to deal with what you didn’t think of in the first place.</p>
<p><a href="http://www.fotocommunity.de/pc/pc/mypics/634598/display/9964950" target="_blank"><img style="display:inline;margin:0 0 5px 5px;" src="http://ajdotnet.files.wordpress.com/2009/07/9964950_1.jpg?w=300&#038;h=271" alt="" width="300" height="271" align="right" /></a></p>
<p>Exceptions come into play under three different conditions:</p>
<ul>
<li>First, as a means to break the current control flow, say to abort a request upon redirection to another page. This is <span style="text-decoration:underline;">intended behavior in a regular situation</span>, not even an error.</li>
<li>Secondly in cases that disrupt the logically correct operation, but you actually planned for that disruption. Say you rely on a file to exist but you know that someone might screw up, so you handled that case, despite the fact that during regular operations it shouldn’t happen at all. This is an error, but an <span style="text-decoration:underline;">intended behavior in an expected irregular situation</span>.</li>
<li>The third condition is the worst of all: Something unintended happens, something you cannot do anything about. It may arise as <em>ArgumentException </em>(telling you that the developer screwed up) or may be as <em>TypeLoadException</em> (telling you that the environment is on quicksand). In any case this is a <span style="text-decoration:underline;">purely unintended</span> error and the only thing you can assume about the state of your application afterwards is, that it is not safe to assume anything.</li>
</ul>
<p>An application architecture should provide provide rules on how to handle these conditions. Add questions like how to deal with the consequences, or deal breaker like parallelism, asynchronicity, or loose coupling, as well as reasonable demands regarding data consistency and error compensation… . And this becomes quite a complex task.</p>
<p>The paradoxical situation however is: Complexity is the very source of errors. Adding complexity is like pouring gasoline into the fire. As developers we already have to deal with the complexity of the problem domain. An exception management strategy should kick in <em>if we fail </em>in that regard. And if he is already doing something wrong, how can we rely on him to do something other (that isn’t even in his line of thinking) right? We can’t!</p>
<p>So, a good exception handling strategy needs to solve that contradiction: The need to deal with different exception conditions on one side. Making things easy for the developers, at the same time <em>not </em>relying on them to do things correctly on the other. Not a small task, indeed. And perhaps this is the very reason that exception handling is usually dealt with so poorly.</p>
<p><strong>Stay Tuned…</strong></p>
<p>OK, this was a lengthy introduction and the actual story is even longer. However I thought it prudent to point out the bigger problem and generally raise the awareness for the topic. Of course I also enjoyed playing with that baseball analogy&#8230; <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . Anyway, in the interest of some readers not interested in such musings I split this one in two distinct posts. This one to explain the problem and make you curious, the next one to provide a solution. Stay tuned if I caught your attention.</p>
<p>PS: Special thanks to <a href="http://www.fotocommunity.de/pc/account/myprofile/634598" target="_blank">Karl</a> for the permission to use his pictures…</p>
<p>PPS: There’s actually more to say about baseball than just <em>baseball</em>. Have a look <a href="http://xkcd.com/540/" target="_blank">here</a>, German readers may find a more thorough explanation <a href="http://usaerklaert.wordpress.com/2009/07/08/sportmetaphern-oder-warum-teenager-baseball-verstehen-sollten/" target="_blank">here</a>. And no, it’s got nothing to do with software development <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><span style="color:#008000;">That’s all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f07%2f12%2fplaying-ball-with-exceptions%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f07%2f12%2fplaying-ball-with-exceptions%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in ASP.NET, C#, Software Architecture, Software Developers, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/300/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=300&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/07/12/playing-ball-with-exceptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/07/9953377_1.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/07/9948007_1.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/07/9964950_1.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f07%2f12%2fplaying-ball-with-exceptions%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>new CloudApp()</title>
		<link>http://ajdotnet.wordpress.com/2009/07/08/new-cloudapp/</link>
		<comments>http://ajdotnet.wordpress.com/2009/07/08/new-cloudapp/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 17:46:59 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[SDX]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=289</guid>
		<description><![CDATA[Microsoft hasn’t even released Azure yet, still they felt compelled to start a little developer competition. And SDX is participating… . During the last 4 weeks a team of my colleagues has put together a working application, simulating an actual business scenario. Starting at point zero, coming up with a meaningful idea – in terms [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=289&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Microsoft hasn’t even released Azure yet, still they felt compelled to start a little <a href="http://www.newcloudapp.com/" target="_blank">developer competition</a>. And SDX is participating… .</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/07/cloudapp-reg.jpg" target="_blank"><img style="display:block;float:none;margin:0 auto 5px;" src="http://ajdotnet.files.wordpress.com/2009/07/cloudapp-reg_small.jpg" /></a></p>
<p>During the last 4 weeks a team of my colleagues has put together a <a href="http://ratingsimulator.cloudapp.net/" target="_blank">working application</a>, simulating an actual business scenario. Starting at point zero, coming up with a meaningful idea – in terms of a cloud solution, and putting together a working application, is quite some achievement. Congrats, guys.</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/07/cloudapp-app.jpg" target="_blank"><img style="display:block;float:none;margin:0 auto 5px;" src="http://ajdotnet.files.wordpress.com/2009/07/cloudapp-app_small.jpg" /></a></p>
<p>Now <em>business scenario</em> sounds a little drab, and banking, especially related to credits, may not actually cause people to applaud hilariously these days. But frankly, since the winner is decided by a community voting and we never thought about that application as particularly “sexy”, we never aimed for that goal. Our aim was to demo <em>the potential of </em><a href="http://ajdotnet.wordpress.com/2008/12/20/explaining-azure/"><em>the cloud</em></a>. Nothing less.</p>
<p>And that’s what the application does. It takes big amounts of data (storage), runs advanced statistical calculations (<a href="http://en.wikipedia.org/wiki/Monte_carlo_simulation" target="_blank">Monte Carlo simulations</a>) (compute), and delivers the results. Since these are peek time usages, we may use several worker roles to scale out the calculations, cutting back when they are not needed (dynamic provisioning). <em>Exactly </em>what the cloud is about.</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/07/cloudapp-arch.jpg" target="_blank"><img style="display:block;float:none;margin:0 auto 5px;" src="http://ajdotnet.files.wordpress.com/2009/07/cloudapp-arch_small.jpg" /></a></p>
<p>And what I really do like is that it doesn’t stop there. Service Bus may be leveraged to integrate this application with “local” solutions, calling back when the calculation has finished. SQL Data Services (once they become available with reporting) may be used for longtime data mining and trend analysis. One can even think of producing information needed to calculate a single credit contract and using Live Mesh to distribute it among the sales people.</p>
<p> So, check it out: <a href="http://ratingsimulator.cloudapp.net/" target="_blank">http://ratingsimulator.cloudapp.net/</a>&#160;&#160;</p>
<p><font color="#008000">That’s all for now folks,      <br /><strong>AJ.NET</strong></font></p>
<br />Posted in Azure, SDX, Software Architecture  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/289/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=289&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/07/08/new-cloudapp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/07/cloudapp-reg_small.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/07/cloudapp-app_small.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/07/cloudapp-arch_small.jpg" medium="image" />
	</item>
		<item>
		<title>Heute mal drei Kreuze&#8230; [MOVED]</title>
		<link>http://ajdotnet.wordpress.com/2009/06/22/heute-mal-drei-kreuze/</link>
		<comments>http://ajdotnet.wordpress.com/2009/06/22/heute-mal-drei-kreuze/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 18:39:11 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=270</guid>
		<description><![CDATA[Moved: http://alexanderj.wordpress.com/2009/06/22/heute-mal-drei-kreuze/ (including comments) Posted in Miscellaneous<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=270&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Moved: <a href="http://alexanderj.wordpress.com/2009/06/22/heute-mal-drei-kreuze/">http://alexanderj.wordpress.com/2009/06/22/heute-mal-drei-kreuze/</a> (including comments)</p>
<br />Posted in Miscellaneous  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/270/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/270/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/270/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=270&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/06/22/heute-mal-drei-kreuze/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Visual Studio 2010 Architecture Edition</title>
		<link>http://ajdotnet.wordpress.com/2009/03/29/visual-studio-2010-architecture-edition/</link>
		<comments>http://ajdotnet.wordpress.com/2009/03/29/visual-studio-2010-architecture-edition/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 16:04:17 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=258</guid>
		<description><![CDATA[Today I’d like to share another left over from the SDX Talk I mentioned earlier: Basically some screenshots from Visual Studio 2010 Architecture Edition (VSArch from now on). Don’t expect something fancy if you already know VSArch, I just couldn’t find all that much information on the Web beyond the two screenshots on the Microsoft [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=258&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I’d like to share another left over from the SDX Talk I mentioned <a href="http://ajdotnet.wordpress.com/2009/03/21/going-parallel/" target="_blank">earlier</a>: Basically some screenshots from <strong><em>Visual Studio 2010 Architecture Edition</em></strong> (<em>VSArch </em>from now on). Don’t expect something fancy if you already know VSArch, I just couldn’t find all that much information on the Web beyond the <a href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx" target="_blank">two screenshots</a> on the Microsoft site.</p>
<p>The main new things within VSArch include the <em>Architecture Explorer</em>, <em>UML Support</em>, and the <em>Layer Diagram</em>.</p>
<p><strong>Architecture Explorer</strong></p>
<p><em>Note: To make the following more tangible I loaded a sample project I use regularly as test harness and took respective screenshots while I analyzed it. Click the images for a larger view…</em></p>
<p>The Architecture Explorer is about getting a better view into existing code. Whether you join a project that is under way, whether you have lost control over your code, or whether you just need to spice up your documentation. Architecture Explorer helps you by visualizing your solution artifacts and dependencies. Artifacts include the classical code artifacts (classes, interfaces, etc.), as well as whole assemblies, files, and namespaces.</p>
<p>Architecture Explorer lets you select those artifacts, display graphs with dependencies, and even navigate along those dependencies and in and out of detail levels.</p>
<p>The following screenshot shows VSArch. The docked pane on the bottom contains the Architecture Explorer that acts as “navigation and control center”. This is where you select your artifacts and visualizations. It could certainly use some improvement from a usability perspective, but it does the job anyway.</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/03/vsarch_assemblies.jpg" target="image"><img src="http://ajdotnet.files.wordpress.com/2009/03/vsarch_assemblies_small.jpg" alt="vsarch_assemblies.jpg" /></a></p>
<p>The screenshot shows two different visualizations of the assembly dependencies in my solution, a matrix view and a directed graph. Just to stress the fact: This was generated out of the solution, by analyzing the project dependencies.</p>
<p>The next screenshot shows a mixture of various artifacts, including classes, interfaces, even files, across parts of or the whole solution.</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/03/vsarch_artifacts.jpg" target="image"><img src="http://ajdotnet.files.wordpress.com/2009/03/vsarch_artifacts_small.jpg" alt="vsarch_artifacts.jpg" /></a></p>
<p>Depending on what filters you set, this graph could give you a high level overview of certain artifacts and their dependencies. For example you could easily spot hot spots, like the one class your whole system depends upon. Or make sure the dependencies are nicely managed via interfaces and find undue relationships. Even spot unreferenced and therefore dead graphs.</p>
<p>Once you go one level deeper, you may want to cluster the artifacts by some category.</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/03/vsarch_relationship.jpg" target="image"><img src="http://ajdotnet.files.wordpress.com/2009/03/vsarch_relationship_small.jpg" alt="vsarch_relationship.jpg" /></a></p>
<p>The image shows again artifacts and their dependencies, but this time grouped by the project to which they belong. It also shows what kind of relationship a line represents and lets you navigate along that dependency.</p>
<p>The Architecture Explorer should help getting a better understanding of your code. It helps you to detect <a href="http://en.wikipedia.org/wiki/Code_smells" target="_blank">code smells</a> or may guide your refactoring.</p>
<p><strong>UML Support</strong></p>
<p>Yes, UML like in, well <a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language" target="_blank">UML</a>. Not extensively, but it includes activity diagram, component diagram, (logical) class diagram, sequence diagram, and use case diagram. I didn’t spend much time investigating them, just drew some diagrams in order to take the screen shots. Generally I can say that Microsoft can draw boxes and lines (big surprise here) but there is a lingering feeling that those diagram editors may not be finished yet (again, hardly surprising on a CTP).</p>
<p>Creating a new diagram is easy enough. Just create a new project of type “Modeling Project” and add an item:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/03/vsarch_dialog.jpg" target="image"><img src="http://ajdotnet.files.wordpress.com/2009/03/vsarch_dialog_small.jpg" alt="vsarch_dialog.jpg" /></a></p>
<p>Everything starts with a use case, so here is our <strong>use case diagram</strong>:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/03/vsarch_usecase.jpg" target="image"><img src="http://ajdotnet.files.wordpress.com/2009/03/vsarch_usecase_small.jpg" alt="vsarch_usecase.jpg" /></a></p>
<p>One can draw the diagram as he likes. As you can see from the context menu, there is something being worked on. Namely the “Link to Artifacts” entry shows the Architecture Explorer, yet I couldn’t quite figure out what’s behind this. Also note the validate entries which didn’t do very much, but we’ll see them later in the Layer Diagram.</p>
<p>Next on the list is <strong>activity diagram</strong>s:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/03/vsarch_activity.jpg" target="image"><img src="http://ajdotnet.files.wordpress.com/2009/03/vsarch_activity_small.jpg" alt="vsarch_activity.jpg" /></a></p>
<p>Works as expected, no surprises, no hidden gems that I’ve found.</p>
<p>The same is true for the <strong>component diagram</strong>:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/03/vsarch_component.jpg" target="image"><img src="http://ajdotnet.files.wordpress.com/2009/03/vsarch_component_small.jpg" alt="vsarch_component.jpg" /></a></p>
<p>Just a diagram, no surprises.</p>
<p>The <strong>logical class diagram </strong>gets more interesting:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/03/vsarch_logicalclass.jpg" target="image"><img src="http://ajdotnet.files.wordpress.com/2009/03/vsarch_logicalclass_small.jpg" alt="vsarch_logicalclass.jpg" /></a></p>
<p>As you can see, it contains very .NETy stuff like enumerations. It also has these menu entries that hint on more to come in the future &#8212; right now the selected menu entry brings up the error message asking for a stereotype, yet I didn’t even find a way to set those. Also the editor may still need some work, e.g. one cannot drag classes in and out of packages.</p>
<p>As a side note: The relation between this logical class diagram and the already existing class diagram escapes me. At least they are a little redundant.</p>
<p>Next on the list is the <strong>sequence diagram</strong>. Rather than drawing one myself I reverse engineered the existing code:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/03/vsarch_sequence.jpg" target="image"><img src="http://ajdotnet.files.wordpress.com/2009/03/vsarch_sequence_small.jpg" alt="vsarch_sequence.jpg" /></a></p>
<p>Quite nice and again, used this way it can help you documenting or just plain understanding existing code.</p>
<blockquote><p>Note: If you want to try that yourself, the CTP has a bug: You need to have a modeling project and at least one diagram before the menu entry “Generate Sequence Diagram” appears. And while you will be presented with a dialog asking what call depth to analyze, it usually works only for one level.</p></blockquote>
<p><strong>Layer Diagram.</strong></p>
<p>Now for the most dreadfully looking diagram (though Microsoft has a <a href="http://www.microsoft.com/visualstudio/en-us/content/images/screencap3.png" target="_blank">more colorful one</a> on its site…): Some boring connected blocks, meant to represent the layers of your architecture.</p>
<p><a href="http://ajdotnet.files.wordpress.com/2009/03/vsarch_layer.jpg" target="image"><img src="http://ajdotnet.files.wordpress.com/2009/03/vsarch_layer_small.jpg" alt="vsarch_layer.jpg" /></a></p>
<p>Actually this is one of the most interesting features for any architect and dev lead: <em>It’s a living beast! <img src='http://s2.wp.com/wp-includes/images/smilies/icon_evil.gif' alt=':evil:' class='wp-smiley' /> </em> </p>
<p>You can add assemblies as well as other artifacts to the bleak boxes. Afterwards you can actually validate whether the dependencies between those artifacts match or violate the dependencies implied by the diagram. In the screenshot you can see that I deliberately misplaced an assembly and consequently got a respective error. Using this feature an architect can ensure that all layer related architectural decisions are honored during development.</p>
<p><strong>To conclude… </strong></p>
<p>The Architecture Explorer is certainly a worthwhile feature and I also like the validation feature of the Layer Diagram. That’s certainly something new and not to be found in other products.</p>
<p>Generating sequence diagrams is nice but it remains to be seen whether this will allow roundtrip engineering. The logical class diagram doesn’t yet meet my expectations and it’s not quite clear to me how it will evolve. The other diagrams? Well, they just work. However in this group is nothing exciting for you if you already have another modeling tool like <a href="http://www.sparxsystems.com/products/ea/index.html" target="_blank">Enterprise Architect</a> (no advertising intended, just happens to be the one I’ve used recently…). And a dedicated tool probably will provide a more complete UML coverage. UML 2.0 has <a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language#Diagrams_overview" target="_blank">13 types of diagrams</a>, including state diagrams, which is in my opinion the biggest gap in VSArch UML support.</p>
<p>Anyway, if that caught your attention and your interested in more details there are two options: One, <a href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx" target="_blank">download the CTP</a> and try for yourself. Two, if you want it more condensed and avoid the hassle with a VPC, watch a video with VSArch at work. For that there are two links I can provide:</p>
<ol>
<li>Peter Provost’s talk at the PDC. Go to the <a href="https://sessions.microsoftpdc.com/public/timeline.aspx" target="_blank">timeline on the PDC site</a>, search for TL15 and you should find “TL15 Architecture without Big Design Up Front”, which is about VSArch, despite the title. His talk was the role model for my analysis of VSArch, yet seeing it live could still give better insights.</li>
<li><a href="http://channel9.msdn.com/posts/VisualStudio/Visual-Studio-Team-System-2010-Week-on-Channel-9/" target="_blank">Visual Studio Team System 2010 Week on Channel 9</a> has a bunch of videos, especially the “Architecture Day” ones. “top down” and “bottom up” show VSArch at work.</li>
</ol>
<p>The final question however will be if all those features are compelling enough to actually <em>buy </em>the … <a href="http://www.microsoft.com/visualstudio/en-us/products/teamsystem/default.mspx#compare_products" target="_blank">Visual Studio Team Suite</a> (i.e. the “you get everything” package). Why not the Architecture Edition? Well, if you are a developer as well as an architect, the Architecture Edition lacks too much in the other areas. Given that there is usually quite a monetary gap between dev edition and team suite, that gap might very well be used to buy a 3rd party UML tool instead… .</p>
<p><span style="color:#008000;">That’s all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f03%2f29%2fvisual-studio-2010-architecture-edition%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f03%2f29%2fvisual-studio-2010-architecture-edition%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, C#, Design Time, Software Architecture, Software Developers, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/258/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=258&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/03/29/visual-studio-2010-architecture-edition/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/vsarch_assemblies_small.jpg" medium="image">
			<media:title type="html">vsarch_assemblies.jpg</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/vsarch_artifacts_small.jpg" medium="image">
			<media:title type="html">vsarch_artifacts.jpg</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/vsarch_relationship_small.jpg" medium="image">
			<media:title type="html">vsarch_relationship.jpg</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/vsarch_dialog_small.jpg" medium="image">
			<media:title type="html">vsarch_dialog.jpg</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/vsarch_usecase_small.jpg" medium="image">
			<media:title type="html">vsarch_usecase.jpg</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/vsarch_activity_small.jpg" medium="image">
			<media:title type="html">vsarch_activity.jpg</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/vsarch_component_small.jpg" medium="image">
			<media:title type="html">vsarch_component.jpg</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/vsarch_logicalclass_small.jpg" medium="image">
			<media:title type="html">vsarch_logicalclass.jpg</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/vsarch_sequence_small.jpg" medium="image">
			<media:title type="html">vsarch_sequence.jpg</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/vsarch_layer_small.jpg" medium="image">
			<media:title type="html">vsarch_layer.jpg</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f03%2f29%2fvisual-studio-2010-architecture-edition%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Being parallel?</title>
		<link>http://ajdotnet.wordpress.com/2009/03/27/being-parallel/</link>
		<comments>http://ajdotnet.wordpress.com/2009/03/27/being-parallel/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 14:40:10 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[manycore; parallel]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=231</guid>
		<description><![CDATA[As a follow-up to the last post, I’d like to review one question I got after the talks I held. That one was particularly interesting, because it highlights a certain aspect of the changes that we have to face with multiple cores and some misconceptions some people might have: Doesn’t today’s multithreaded software profit from [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=231&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As a follow-up to <a href="http://ajdotnet.wordpress.com/2009/03/21/going-parallel/" target="_blank">the last post</a>, I’d like to review one question I got after the talks I held. That one was particularly interesting, because it highlights a certain aspect of the changes that we have to face with multiple cores and some misconceptions some people might have:</p>
<p><strong>Doesn’t today’s multithreaded software profit from more cores <em>automatically</em>?</strong></p>
<p>The answer is a definite <em>yes and no</em>. <span style="text-decoration:underline;">Server software</span> like IIS or SQL Server has always been optimized for throughput (performance only secondary) and as long as the processing is CPU bound it will certainly put more cores to good use. That should result in better throughput (i.e. more requests handled at the same time), but not necessarily in better performance (i.e. the time to complete one request).</p>
<p>The more interesting observation however is on the client: <span style="text-decoration:underline;">Client applications</span> follow different use cases for multithreading, actually mainly two of them:</p>
<ol>
<li><strong>Avoid blocking of some task </strong>while processing something else. Examples include keeping the Windows UIs responsive (i.e. work around the UI’s thread affinity), Windows Services (their <a href="http://msdn.microsoft.com/en-us/library/ms685149.aspx" target="_blank">service control handler</a> is invoked by the SCM and <a href="http://ajdotnet.wordpress.com/2007/10/14/hosting-wf/" target="_blank">has to return</a> in a certain amount of time).</li>
<li>Be able to spend processing time on something valuable while <strong>one task is blocked waiting for something </strong>to happen. Blocking regularly happens during some kind of I/O, especially network calls. This is the „call WebService asynchronously and do something worthwhile until the call returns“ scenario.</li>
</ol>
<p>Just different sides of the same coin actually. Please note that neither use case has been about <em>actual </em>performance, as in doing things really faster. The first one is about <em>perceived </em>performance by reducing latency for some favored task, the second one improves performance, albeit not by doing things faster but by avoiding unnecessary wait times. Anyway, this works quite well even (or rather especially) on single core machines.</p>
<p>Let’s dig deeper into an example: Say a lengthy CPU intensive calculation is triggered by a button. The time spend on updating the UI and doing the calculation is denoted in the following picture, the red line represents the executing thread:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/03/mt1.jpg" alt="" /></p>
<p>The calculation is done on the UI thread, giving it peek performance, but at the same time freezing the UI until the calculation has finished. The typical “optimization” is putting the calculation on a second thread, e.g. using the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx" target="_blank">BackgroundWorker</a> component. That way, the UI keeps updating itself rather than degenerating to one of those white and unresponsive windows:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/03/mt2.jpg" alt="" /></p>
<p>The UI and the calculation run on different threads (yet still on one core), thus the UI can update itself even during the calculation is still running. However, now it has to deal with that intermediary state (denoted by the striped blocks). And every time the UI thread uses the core, that time is lost to the calculation, so the time to completion will actually be longer than with A.</p>
<p><em>Now switch gears to our new, say quad core, machine…</em></p>
<p>What happens on a quad core is that both tasks now get executed in parallel:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/03/mt3.jpg" alt="" /></p>
<p>As you can see, actual processing time is now back to the same it was with A, yet it manages to avoid freezing the UI as in B; again at the expense of having to deal with the intermediary state. However that’s about as good as it becomes. But the application doesn’t get faster, neither will a third or fourth core be utilized at all (other than ensuring that other applications can run there rather then interfering with the cores we just occupied).</p>
<p>So, while the potential in “classical multithreading” lies in <em>shifting </em>or <em>arranging </em>calculations of disparate tasks, the potential of parallelism with many cores lies in doing <em>more </em>calculations of CPU bound tasks <em>at the same time</em>. Like so:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/03/mt4.jpg" alt="" /></p>
<p>This time the calculation has been split into parts and been distributed on different threads on top of the UI thread. This eventually caused better performance than A. However this is not the way today’s multithreaded applications are written, because on a single core it actually leads to worse performance, due to <a href="http://msdn.microsoft.com/en-us/library/ms682453.aspx" target="_blank">memory pressure</a> if used excessively, thread context switches, synchronization and contention, etc..</p>
<p><strong><span style="text-decoration:underline;">The verdict…</span></strong></p>
<p>Today&#8217;s multithreaded client software may profit from more cores, but to a far lower degree than one might think at first. And what’s more: It might even stop running altogether because <em>actual </em>parallelism opens the door for error conditions that were simply theoretical threats on a single core system but become a reality on multi cores. Something like accessing some memory while another core is still in the middle of an instruction doing the same.</p>
<p><strong>PS: And by the way: the future is now! </strong></p>
<p>I just started in a new project and got my new machine last week: An <a href="http://search.hp.com/query.html?cc=us&amp;lang=en&amp;qt=hp+xw6600&amp;la=en" target="_blank">HP wx6600</a>, with 2 quad cores @ 3GHz, 4GB <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':grin:' class='wp-smiley' /> </p>
<p>This is a task manager screenshot, showing 8 nice little cores, sitting under my desk, waiting for me to send them on one or the other errand…</p>
<p><img src="http://ajdotnet.files.wordpress.com/2009/03/taskmgr_hp.jpg" alt="" /></p>
<p>A single core is such a lonesome entity… <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><span style="color:#008000;">That’s all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f03%2f27%2fbeing-parallel%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f03%2f27%2fbeing-parallel%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, Software Architecture, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/231/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=231&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/03/27/being-parallel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/mt1.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/mt2.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/mt3.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/mt4.jpg" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/taskmgr_hp.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f03%2f27%2fbeing-parallel%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Going parallel&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2009/03/21/going-parallel/</link>
		<comments>http://ajdotnet.wordpress.com/2009/03/21/going-parallel/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 16:46:47 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=216</guid>
		<description><![CDATA[The so-called „many core shift“ is happening. It’s not a thing of the future, it’s not „just around the corner“, it has already begun. And it will change our developers’ life. Last week we had some customer events, containing some talks about PDC and other stuff and how it will affect the near term future. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=216&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The so-called „<a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=633F9F08-AAD9-46C4-8CAE-B204472838E1&amp;displaylang=en" target="_blank">many core shift</a>“ is happening. It’s not a thing of the future, it’s not „just around the corner“, it has already begun. And it will change our developers’ life.</p>
<p>Last week <a href="http://www.sdx-ag.de/" target="_blank">we</a> had some customer events, containing some talks about PDC and other stuff and how it will affect the near term future. Among other things I tried to describe the many core shift as well as its consequences. Curiously the audience was largely aware of the facts, yet the consequences had yet escaped the vast majority. So let me try to repeat the gist and see whether this is maybe a common symptom&#8230;</p>
<p><strong>What’s the many core shift, anyway?</strong></p>
<p><a href="http://en.wikipedia.org/wiki/Moores_law" target="_blank">Moore’s Law</a> states that the number of transistors on an integrated circuits doubles every two years. Until not long ago, and accompanied by more complex designs and higher clock speeds, that meant faster CPUs. This was sometimes called the „free lunch for developers“, because if one happened to write a slow application… not that anyone ever would <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  , all he had to do was wait two years and it ran twice as fast.</p>
<p>However this evolution has reached its physical limits (clock speed, power consumption, etc.). Yet, still the number doubles… .<br />
So instead of building faster and more complex CPUs, the manufacturers started placing <em>more </em>CPUs, read cores, on a chip. It started 2006 with <a href="http://ajdotnet.wordpress.com/2006/07/15/intels-core-2-extreme-core-2-duo-the-empire-strikes-back/" target="_blank">Intel’s dual cores</a>, today you won’t find a single core desktop machine anymore. High end consumer machines come with quad cores, and servers with 16 cores (delivered as 4 quad cores). Have a look at the extrapolation:</p>
<p><img class="alignnone size-full wp-image-214" title="cores" src="http://ajdotnet.files.wordpress.com/2009/03/cores.jpg" alt="cores" width="610" height="431" /></p>
<p>The “lower” line shows cores on a CPU, starting 2006 with 2 cores, while the steeper one assumes 4 CPU sockets. And just in case the conclusion escaped you: Five years from now we will have between 32 and 128 cores. And remember, we are talking “consumer grade stuff”, that is <em>the box under <span style="text-decoration:underline;">your</span> desk</em>, not something special! Impressive?</p>
<p><strong>So that’s the many core shift. But what does it mean?</strong></p>
<p>Well, it probably means that today’s software runs a bit faster. Not much, mind you, certainly not the 32 times faster a 64 core machine is supposed to be compared to my dual core. Why is that? Well, have a look at the following task manager of a 64 core machine:</p>
<p><img class="alignnone size-full wp-image-215" title="taskmgr_64" src="http://ajdotnet.files.wordpress.com/2009/03/taskmgr_64.jpg" alt="taskmgr_64" width="614" height="508" /><br />
(<em>That’s a fake of course, but have a look at </em><a href="http://blogs.technet.com/markrussinovich/archive/2008/07/21/3092070.aspx" target="_blank"><em>Marks’s blog</em></a><em> for a real one.</em>)</p>
<p>Now look at your own desktop and count the open applications. Outlook, Word, perhaps PowerPoint, Internet Explorer, Acrobat Reader? OK, say half a dozen applications, add 10 more for the OS stuff actually doing something. That’s 16 applications, using the upper row of cores, perhaps even to 100% and yearning for more, while the other 3 rows just sit there and twiddle their thumbs. That sad truth is: <em>Most of today’s applications simply are not capable of employing these cores appropriately.</em> Consequence: In order to leverage these cores <strong><span style="text-decoration:underline;">we have to change the way we write our software!</span></strong></p>
<p>Two questions come to mind: Do we actually <em>need </em>that kind of processing power? And if so, how do we <em>open it up</em>?</p>
<p><strong>Seriously, does the average user need 64 cores?</strong></p>
<p>Well, yes he does. If for no other reason, he did need the increase in processing power during the last years, why should that change?</p>
<p>So, what does he need it for? Gamers are always at the forefront of processing power demand. We have the generally increasing demand in UI technology: 3D, animations, visual effects are becoming mainstream with windows, WPF and <a href="http://silverlight.net/" target="_blank">Silverlight</a>. The trend to digital photography has had its effect on the demand for graphics software. On my dual core, <a href="http://www.dxo.com/" target="_blank">DXO</a> needs about 1 hour per 150 pictures, so there’s certainly room for improvement (I brought 2500 pics from my last vacation in <a href="http://en.wikipedia.org/wiki/Tanzania" target="_blank">Tanzania</a>. Do the math <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ). Background encryption, compression, virus scanning, etc. also add up.</p>
<p>Even if you are an “ordinary business user”: Word just sits and waits for your input most of the time? Well, open a non trivial 100 page document and see how long Word takes for pagination, spell checking, or updating the TOC. Change the formatting and watch again. So while Word mostly does nothing exciting, there are „burst times“ when it could really need those cores.</p>
<p>And I did not even mention Visual Studio and the compiler yet&#8230;</p>
<p><strong>How do I, Joe Developer, put 64 cores to good use?<br />
</strong>And how do I make sure the app doesn’t degrade on an old dual core beyond reasonable limits?</p>
<p>Here we are right at the center of the problem: <a href="http://en.wikipedia.org/wiki/Multithreading" target="_blank">Multithreading</a> is not exactly something new, we’ve had that for <a href="http://en.wikipedia.org/wiki/Os/2" target="_blank">more than 20 years</a> on PC’s now. So why do I even have to ask that question? It’s because we didn’t actually use multithreading within our applications if we didn’t have to. Because it’s laborious, error prone, awkward. You have to deal with thread synchronization, race conditions, dead locks, error management, communication between threads. You can’t debug it, tracing doesn’t help very much either. In short: <em>It’s a pain in the &#8230;</em>, well.</p>
<p>So let’s face it:<em> Most developers have avoided multithreading altogether (perhaps the lucky ones). And those who did do multithreading probably did it just for optimizations in very distinct areas. </em></p>
<p>But what we need to leverage those cores is quite the opposite: <em>We need multithreading to become mainstream</em>, kind of ubiquitous. For that it needs to be easier to employ parallelism. Complexity has to be pushed out of our code into the platform. Somewhat like nobody thinks any longer about virtual memory (while some of us are <a href="http://en.wikipedia.org/wiki/VZ200" target="_blank">old enough</a> to remember the days of physical addressing).</p>
<p>In other words: <em>In order to deal with the parallelization demands, we need new patterns, libraries, and tools. </em></p>
<p>Microsoft is going to give us a first delivery on that with the next <a href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx" target="_blank">Visual Studio 2010</a> and .NET wave. Optimized runtimes (e.g. the thread pool), better tools (e.g. the debugger) and not the least, new libraries, introducing new patterns (e.g. <a href="http://msdn.microsoft.com/en-us/magazine/cc163340.aspx" target="_blank">Task Parallel Library</a>). There’s more in the unmanaged world (e.g. <a href="http://msdn.microsoft.com/en-us/magazine/dd434652.aspx" target="_blank">Parallel Patterns Library</a>), more on the server side (<a href="http://www.microsoft.com/ccrdss/" target="_blank">CCR</a>), more on the language front (<a href="http://msdn.microsoft.com/en-us/fsharp/default.aspx" target="_blank">F#</a>), more in the research area (<a href="http://blogs.msdn.com/stmteam/default.aspx" target="_blank">transactional memory</a>).<br />
Microsoft even devoted a whole “<a href="http://msdn.microsoft.com/en-us/concurrency/default.aspx" target="_blank">developer center</a>” to parallel computing (look there for more details). And quite rightly so, because there is no single solution to parallelization, it comes in different flavors (e.g. data parallelism vs. task based parallelism) and we can expect further developments in this area in the future.</p>
<p>Also it’s noteworthy that the OSes, namely Windows Server 2008 R2 and Windows 7 which share the same kernel, can manage 256 cores. Compared to <a href="http://technet.microsoft.com/en-us/windowsserver/bb430827.aspx" target="_blank">what they supported before</a> this is quite a jump.</p>
<p><strong>Conclusion</strong></p>
<p>So, parallelization is here to stay and we are going to have to deal with it. If anything, the trend is going to accelerate. It’s reasonable to assume that eventually processor manufacturers will trade single core performance for number of cores, i.e. put more but less capable cores on a chip, in order to save power consumption (green IT and mobility being two other major trends).</p>
<p>Looking even further, the many core shift may reach a break even where standard desktop systems will cease to profit from additional cores (how parallel can you become after all?), the problems of memory access may limit the amount of cores. Asynchronous multi cores may evolve, e.g. having cores optimized for certain tasks…</p>
<p>See, there’s a lot to look forward to. Our profession certainly remains interesting <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>PS: See <a href="http://ajdotnet.wordpress.com/2009/03/27/being-parallel/">Being Parallel?</a> for some thoughts on whether today&#8217;s multithreaded client software will profit from additional cores&#8230;</p>
<p><span style="color:#008000;">That’s all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f03%2f21%2fgoing-parallel%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f03%2f21%2fgoing-parallel%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, Software Architecture, Software Developers, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/216/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=216&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/03/21/going-parallel/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/cores.jpg" medium="image">
			<media:title type="html">cores</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2009/03/taskmgr_64.jpg" medium="image">
			<media:title type="html">taskmgr_64</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2009%2f03%2f21%2fgoing-parallel%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Explaining Azure&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2008/12/20/explaining-azure/</link>
		<comments>http://ajdotnet.wordpress.com/2008/12/20/explaining-azure/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 19:51:50 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=197</guid>
		<description><![CDATA[&#8230; is something I did explicitly not want to do! Not that it is not necessary to do so. It&#8217;s just that I expected a lot of bloggers, especially from Microsoft itself, trying to spread the news and foster understanding of what is ahead of us. Well, the Microsoft folks became kind of hushed, as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=197&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8230; is something I did explicitly <em>not </em>want to do!</p>
<p>Not that it is not necessary to do so. It&#8217;s just that I expected a lot of bloggers, especially from Microsoft itself, trying to spread the news and foster understanding of what is ahead of us. Well, the Microsoft folks became kind of hushed, as if ducking down and counting the shrapnels after having thrown the bomb at the PDC. So I changed my mind&#8230;</p>
<p><em>Preface&#8230;</em></p>
<p>Given what Microsoft unveiled at the PDC &#8212; A new vision, a new strategy, a new technology stack, and a mish mash of existing, sometimes overlapping, not yet consistent, much less complete applications and services &#8212; it&#8217;s no wonder that it took me some time to grasp the idea. And when I thought I might have understood the gist I was still, well, unsure of whether I had gotten it all right.<br />
The breakthrough came at the <a href="http://www.microsoftpdc.com/Agenda/UnSessions.aspx#ask-the-experts" target="_blank">ask-the-experts</a>. More to the point I had the chance to talk to <a href="http://blogs.msdn.com/oriamiga/" target="_blank">Ori Amiga</a> (the guy that did the “BB04 Live Services: A Lap around the Live Framework and Mesh Services” <a href="https://sessions.microsoftpdc.com/public/timeline.aspx" target="_blank">talk</a>). Other than joking about the various ways to pronounce “Azure” and the fact that Americans always manage to get it wrong (sorry guys <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  &#8212; and sorry Ori, hope I didn’t give you away too badly <img src='http://s1.wp.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ) ), this little chat really turned “suspected functionality” into “understood technology” (at least I do hope so&#8230;).</p>
<p>Explaining Azure worked not on explaining the ever present <a href="http://ajdotnet.files.wordpress.com/2008/11/azure-services-platform.gif" target="_blank">Azure picture</a> as is. It worked on <em>developing </em>the pieces of the picture, bit by bit, and relating it to other concepts. And since I worked for me, I thought I might share the gist of that conversation in much the same style, hoping I&#8217;m providing new insights rather than reiterating already available information. Actually I&#8217;m going to use the very sheet of paper we (mostly Ori) drew throughout said discussion. </p>
<p><em>Enough of the preliminaries, here we go…</em></p>
<p>First of all, keep in mind that there’s two Azures: <em>Windows Azure </em>and the <em>Azure Services Platform</em>. They are not the same and neither presents the full picture. I&#8217;ll try to dissect that picture layer by layer, like a cream gateau&#8230;</p>
<p><strong>It starts with the cake bottom: <span style="text-decoration:underline;">Windows Azure</span> </strong></p>
<p>Windows Azure is the basic “infrastructure” (to avoid the term “Operating System” for now) to run applications on, highlighted in the following picture in red:</p>
<p align="center"><a href="http://ajdotnet.files.wordpress.com/2008/12/azure1windows-azure.jpg" target="_blank"><img style="border-width:0;" src="http://ajdotnet.files.wordpress.com/2008/12/azure1windows-azure-thumb.jpg?w=660&#038;h=394" border="0" alt="azure.1.windows_azure" width="660" height="394" /></a></p>
<p>That includes computing capabilities, basic storage, management of applications (i.e. deployment, including upgrading), and operations (e.g. handling failures). These concepts are abstractions from the underlying OS (Windows 2008 actually), machines, and storage devices.</p>
<p>The terms to think of are <em>service instances </em>rather than processes or (virtual) machines. This is similar to the way virtual memory abstracts physical memory. While any memory access obviously has to happen on physical memory, the virtual memory manager is free to relocate it, even to swap it out to disk. This not only makes applications independent of the amount of physical memory, it also optimizes resource usage, allowing other applications to use the memory my application has claimed but does not access at the moment.</p>
<p>Yet, while Microsoft Azure is one level of abstraction above the machine’s OS, it has similar concepts (highlighted in the above picture in blue):</p>
<ul>
<li>computing ~ job scheduling, etc. (NT Kernel);</li>
<li>storage ~ file system (NTFS);</li>
<li>management ~ application installer;</li>
<li>operations ~ task manager, event manager, etc..</li>
</ul>
<p>Thus it is quite feasible to call Windows Azure an <em>Operating System </em>for the datacenter (or for the cloud if you’re a marketing guy), even if that may not match exactly what you learned in university about <a href="http://en.wikipedia.org/wiki/Operating_system" target="_blank">operating systems</a>.</p>
<p><em>The implications of </em><a href="http://msdn.microsoft.com/en-us/library/dd179441.aspx" target="_blank"><em>deploying</em></a><em> an application to Windows Azure (i.e. how the application has to be </em><a href="http://msdn.microsoft.com/en-us/library/dd179341.aspx" target="_blank"><em>built</em></a><em> and how the fabric manages it) is actually quite interesting &#8230; but a whole new blog post, thus I will skip that for now.</em></p>
<p><strong>Let’s move on to the second layer of the cake: <span style="text-decoration:underline;">The Azure Services Platform</span> </strong></p>
<p>A barebone OS like Windows Azure would be of limited use if it were not completed with other general purpose services. Which services exactly that includes may be debatable, yet, again, the similarity with our local environment may help depicting the features we as developers have come to expect from the platform we are developing on: database service, user accounts, IPC, etc..</p>
<p>Again, the following picture highlights the services in red and similarities in blue:</p>
<p align="center"><a href="http://ajdotnet.files.wordpress.com/2008/12/azure2azure-services-platform.jpg" target="_blank"><img style="border-width:0;" src="http://ajdotnet.files.wordpress.com/2008/12/azure2azure-services-platform-thumb.jpg?w=660&#038;h=394" border="0" alt="azure.2.azure_services_platform" width="660" height="394" /></a></p>
<p>Microsoft decided that the following services may be good ones to start with:</p>
<ul>
<li>.NET Services: basic infrastructure services for application security (access control), application communication (Service Bus), and workflow (three guesses&#8230;?).</li>
<li>SQL Services: database related stuff; not exactly a SQL Server, but aspiring to be&#8230;</li>
<li>Live Services: All around social applications (community, devices, etc.)</li>
<li><em>Core application services: This is a set of higher level application services, such as SharePoint Services and CRM Services (explicitly not including the UI!). In my opinion they are there because they were readily available, not because they are particularly necessary. </em></li>
</ul>
<p>Oh, and not to forget the reoccurring three dots in the PDC slides; those dots tell us that these are not closed and sealed sets. Actually Microsoft said that every major server application will eventually be made available on Azure.</p>
<p><strong>Now for the chocolate and the cream: the <span style="text-decoration:underline;">applications</span> running on the Azure Services Platform</strong></p>
<p>While Ori included the application layer in the platform, any PDC slide puts it on top:</p>
<p align="center"><a href="http://ajdotnet.files.wordpress.com/2008/12/azure3applications.jpg" target="_blank"><img style="border-width:0;" src="http://ajdotnet.files.wordpress.com/2008/12/azure3applications-thumb.jpg?w=660&#038;h=394" border="0" alt="azure.3.applications" width="660" height="394" /></a></p>
<p>Where you put the label is of no consequence anyway, because this is no more than a logical hierarchy. However, please don&#8217;t misinterpret this hierarchy by assuming that those applications have to run on Azure and only applications running on Azure can leverage the Azure services! Au contraire!</p>
<p>If you have an application deployed on Azure it is (technically speaking) no different from other services. The difference only lies in the purpose, or the consumer if you wish. And still applications and services are free to call <em>any </em>services, not just those running on Azure. Likewise if your application is running on your local machine or network it can use services deployed on Azure to store data or integrate with whatever, that&#8217;s fine as well. Actually the best example for this flexibility is coming from Microsoft itself: Live Mesh.</p>
<p><strong>The cherry on the cream: <span style="text-decoration:underline;">Live Mesh</span></strong></p>
<p>Technically speaking the Live Mesh Desktop and Live Services are just another set of applications and services running on the Azure Services Platform, complemented with applications running somewhere else and using those services. This limited view however would miss much of the capabilities of Live Mesh, and the way it enhances the platform.</p>
<p align="center"><a href="http://ajdotnet.files.wordpress.com/2008/12/azure4live-mesh.jpg" target="_blank"><img style="border-width:0;" src="http://ajdotnet.files.wordpress.com/2008/12/azure4live-mesh-thumb.jpg?w=660&#038;h=394" border="0" alt="azure.4.live_mesh" width="660" height="394" /></a></p>
<p>Live Mesh aims no less than to <em>connect people, devices, and applications</em>. Live Services contains services for identity (LiveID), presence, etc., and Mesh Services to maintain users, devices, applications, and &#8212; a corner stone &#8212; synchronization. The resource model organizes mesh objects (data, news, etc.) in feeds and entries, which in turn are subject to synchronization among the applications being “deployed” to Live Mesh. “Deploying” an application means either actual deployment on Azure, or storing it for (seamless) installation on your local device, via Live Mesh Client, offline capable if built to be.</p>
<p>Still with me? Well, to make this mess, pardon <em>mesh</em>, a little more tangible, let’s recap the example of Ori’s talk (<a href="http://mschnlnine.vo.llnwd.net/d1/pdc08/PPTX/BB04.pptx" target="_blank">PPTX</a> <a href="http://mschnlnine.vo.llnwd.net/d1/pdc08/WMV/BB04.wmv" target="_blank">WMV</a>, <em>images taken from there</em>):</p>
<p><a href="http://ajdotnet.files.wordpress.com/2008/12/livemesh-app.jpg" target="_blank"><br />
<img style="border-right:0;border-top:0;border-left:0;border-bottom:0;margin:0 5px 5px 0;" src="http://ajdotnet.files.wordpress.com/2008/12/livemesh-app-thumb.jpg?w=244&#038;h=145" border="0" alt="livemesh_app" width="244" height="145" align="left" /></a></p>
<p><a href="http://ajdotnet.files.wordpress.com/2008/12/livemesh-mobile2.jpg" target="_blank"><br />
<img style="border:0;margin:0 0 5px 5px;" src="http://ajdotnet.files.wordpress.com/2008/12/livemesh-mobile-thumb2.jpg?w=129&#038;h=244" border="0" alt="livemesh_mobile" width="129" height="244" align="right" /></a></p>
<p>He had his media center PC connected to the Live Mesh, advertising its meta data, like favorites, recordings, etc.. That information was synchronized to the Live Desktop (running in the browser), so he could pick a TV show there and “start” recording. (Actually that “start” was some little piece of data, synchronized back to the media center PC which in turn did, surprise!, start recording.) He then started a locally installed application that showed the TV guide and had the typical red recording sign right at the respective TV show. That application was offline capable, so he could have planed his TV recordings on the airplane and have it synchronized when he gets back online. Finally he also showed the same TV Guide on his mobile phone simulation.<br />
The only thing missing was integration with other people, but I think it was in a key note where they showed an application that allowed sharing of film critics with some friends.<br />
All in all, <em>that’s what I call ubiquitous computing!</em></p>
<p><strong>Spicing the cake: <span style="text-decoration:underline;">Developer tools</span></strong></p>
<p>This part is actually not in the picture, but it’s no less essential: Where does your application or 3<sup>rd</sup> party code fit in? How does it get there? Those parts in red may be <em>your </em>application or service:</p>
<p align="center"><a href="http://ajdotnet.files.wordpress.com/2008/12/azure5development.jpg" target="_blank"><img style="border-width:0;" src="http://ajdotnet.files.wordpress.com/2008/12/azure5development-thumb.jpg?w=660&#038;h=394" border="0" alt="azure.5.development" width="660" height="394" /></a></p>
<p>It’s actually quite easy: You can write applications that run on Azure and provide services (just like the basic services Microsoft provides), or an UI (just like Microsoft&#8217;s applications). You can access any of those services from the cloud or your local application, no matter whether Microsoft provided it or someone else. And you can Mesh-enable any of these applications and services as you like. <em>This is an open platform! </em></p>
<p>Also Microsoft provides a simulated local environment for Azure, called <a href="http://msdn.microsoft.com/en-us/library/dd179455.aspx" target="_blank">development fabric</a>, along with Visual Studio integration. Thus it is possible to develop your application locally, test it locally, and only afterwards deploy it to the cloud.<br />
Regarding Live Mesh Matthias has more information on <a href="http://www.leading-edge-dev.de/?p=111" target="_blank">developing with Live Framework</a>.</p>
<p><em>Postscript&#8230;</em></p>
<p>That&#8217;s it. You can find the complete untampered drawing <a href="http://ajdotnet.files.wordpress.com/2008/12/azure_by_ori.jpg" target="_blank">here</a>. That scrawl at the bottom of the drawing is actually Ori&#8217;s signature, but you should attribute any error, misunderstanding and adverse opinion in this post to me.</p>
<p>Finally two links for some alternate explanations (already repeated a thousand times over, but what the heck, they’re good):</p>
<ul>
<li>&#8220;Manuvir Das: Introducing Windows Azure&#8221;: Manuvir explains a little deeper how Windows Azure works.<br />
<a href="http://channel9.msdn.com/posts/Charles/Manuvir-Das-Introducing-Windows-Azure/" target="_blank">http://channel9.msdn.com/posts/Charles/Manuvir-Das-Introducing-Windows-Azure/</a></li>
<li>&#8220;Windows Azure (aka “Red Dog”) explained in 145 seconds&#8221;: funny and enlightening (presented on a site you might find interesting as well)<br />
<a title="http://www.azurejournal.com/2008/11/windows-azure-aka-red-dog-explained-in-145-seconds/" href="http://www.azurejournal.com/2008/11/windows-azure-aka-red-dog-explained-in-145-seconds/" target="_blank">http://www.azurejournal.com/2008/11/windows-azure-aka-red-dog-explained-in-145-seconds/</a></li>
</ul>
<p><span style="color:#008000;">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f12%2f20%2fexplaining-azure%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f12%2f20%2fexplaining-azure%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in Azure, Software Architecture, Software Developers, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/197/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=197&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/12/20/explaining-azure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
<enclosure url="http://mschnlnine.vo.llnwd.net/d1/pdc08/WMV/BB04.wmv" length="117636563" type="video/x-ms-wmv" />
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/12/azure1windows-azure-thumb.jpg" medium="image">
			<media:title type="html">azure.1.windows_azure</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/12/azure2azure-services-platform-thumb.jpg" medium="image">
			<media:title type="html">azure.2.azure_services_platform</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/12/azure3applications-thumb.jpg" medium="image">
			<media:title type="html">azure.3.applications</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/12/azure4live-mesh-thumb.jpg" medium="image">
			<media:title type="html">azure.4.live_mesh</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/12/livemesh-app-thumb.jpg" medium="image">
			<media:title type="html">livemesh_app</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/12/livemesh-mobile-thumb2.jpg" medium="image">
			<media:title type="html">livemesh_mobile</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/12/azure5development-thumb.jpg" medium="image">
			<media:title type="html">azure.5.development</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f12%2f20%2fexplaining-azure%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>About Azure&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2008/11/16/about-azure/</link>
		<comments>http://ajdotnet.wordpress.com/2008/11/16/about-azure/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 16:48:27 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=180</guid>
		<description><![CDATA[This post (and probably some more) is about coming to grips with Microsoft&#8217;s latest announcement at the PDC: Windows Azure and the Azure Services Platform. Matter of fact, I’m constantly turning this thing over and over, trying to discuss it with various different people, trying to think different scenarios through, and I’m constantly adjusting my [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=180&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://ajdotnet.files.wordpress.com/2008/11/ray-ozzie-pdc-keynote.jpg"><img style="border-width:0;margin:0 0 5px 5px;" src="http://ajdotnet.files.wordpress.com/2008/11/ray-ozzie-pdc-keynote-thumb.jpg?w=244&#038;h=177" border="0" alt="Ray Ozzie, Keynote PDC 2008" width="244" height="177" align="right" /></a> This post (and probably some more) is about coming to grips with Microsoft&#8217;s latest announcement at the PDC: Windows Azure and the Azure Services Platform. Matter of fact, I’m constantly turning this thing over and over, trying to discuss it with various different people, trying to think different scenarios through, and I’m constantly adjusting my perception. Frankly, if anybody tells you he has understood what is ahead of us, who says he knows how all that stuff will evolve, you’ve met a fool.</p>
<p><em>Now for this fool’s current view… </em></p>
<p>I&#8217;ll not try to explain it in technical details (not this time anyway, start at <a href="http://www.microsoft.com/azure/" target="_blank">here</a> or <a href="http://en.wikipedia.org/wiki/Windows_Azure" target="_blank">here</a> to come up to speed — anyway, there are probably books being written about it right now). And I&#8217;m certainly not going to join the debate, whether Azure is an operating system or not.</p>
<blockquote><p>I was still at the PDC when I started a Google search to see what reactions Azure triggered. <em>That</em> particular question was a predominant topic — and utterly without any consequence. (I couldn’t find that again though, it’s buried under millions of near identical pages describing Azure.)</p></blockquote>
<p>So let&#8217;s talk about what Azure is about. For me, for you, for the companies we work for, for the industry.</p>
<p><strong>Hailstorm — or what Azure is <em>not</em>&#8230;</strong></p>
<p>When I first heard about some of the Azure stuff I immediate thought &#8220;Wait, didn&#8217;t they announce something very similar in 2001? Called <a href="http://www.microsoft.com/presspass/features/2001/mar01/03-19hailstorm.mspx" target="_blank">Hailstorm</a> a.k.a .NET Building Blocks a.k.a. <a href="http://www.watchit.com/PGDSCR.cfm?c_acronym=MSMS" target="_blank">My Services</a>?&#8221;. It turns out that I was not the only one with this particular <a href="http://www.google.com/search?hl=en&amp;q=hailstorm+azure" target="_blank">déjà-vu</a>&#8230;</p>
<p>Taking a closer look, however, there are some significant differences in strategy between Hailstorm and Azure: Hailstorm was about Microsoft providing services to manage your <em>data</em>. Azure is about providing a platform for your <em>services</em>. In other words: With Hailstorm Microsoft said &#8220;give us your data and identity, keep the apps&#8221;, with Azure they say &#8220;give us your apps, you may keep the data and the identity (or you may choose to let us handle that as well)&#8221;. This is certainly a noteworthy change in attitude.</p>
<p>There&#8217;s another thing that changed since 2001. In 2001 Hailstorm was a new approach. It was visionary. It was the first time that someone asked me to let him manage my identity, appointments, even my wallet! And it was the evil empire that asked this very question&#8230; .<br />
Today, hosting providers are a common thing and trusting Google or online communities with personal information is quite normal. Going even further, Amazon already offers a service platform with <a href="http://aws.amazon.com/" target="_blank">AWS</a>, based on virtual machines (EC2), storage (S3 and SimpleDB), and a queuing service (SQS) as messaging bus. <a href="http://code.google.com/appengine/" target="_blank">Google App Engine</a> provides scalable application hosting (Python apps) and complements that with their identity system (<a href="http://code.google.com/appengine/kb/general.html#auth" target="_blank">Google Accounts</a>). So, the good news for Microsoft is that they are for once not the bad guys. Of course, Microsoft being Microsoft, that probably only means that they will be accused of being the copycat again&#8230; .</p>
<p><strong>What Azure may eventually become&#8230;</strong></p>
<p>Still, what’s the big deal about Azure? I mean, doesn&#8217;t my hosting provider offer virtual or dedicated servers? Aren&#8217;t there enough storage offerings, many of them for <a href="http://lifehacker.com/5064688/online-storage-feature+by+feature-comparison-chart" target="_blank">free</a>? Aren&#8217;t there Internet communities, online applications, service providers, &#8230;?</p>
<p><a href="http://ajdotnet.files.wordpress.com/2008/11/azure-services-platform.gif"><img style="border-width:0;margin:0 0 5px 5px;" src="http://ajdotnet.files.wordpress.com/2008/11/azure-services-platform-thumb.gif?w=244&#038;h=116" border="0" alt="Azure Services Platform" width="244" height="116" align="right" /></a> Well, looking at Azure piece by piece, there’s nothing new, nothing especially exciting. But take a step back and look at the big picture, at the strategy. With Azure&#8230;</p>
<p><strong>Microsoft becomes a <em>service</em> hoster and operator</strong>. Not just a <em>server</em> hoster. They don’t stop at booting a VM. They <em>operate</em> your applications, load balance them, restart them on failures, scale them, provision them, provide an upgrade mechanism that doesn’t disrupt 24/7.</p>
<p><strong>Microsoft becomes an application service provider as well as a<em> service </em>provider</strong>. They do not stop at providing fully fledged business applications like CRM or other. They offer basic infrastructure services like SQL Data Services or Workflow Services. You could even build your own CRM System, run it on Azure, competing with Microsoft’s CRM — and Microsoft couldn’t do anything about it (for if they would, that would put them out of business at the speed of light).</p>
<p><strong>Microsoft becomes a service integrator</strong>. They don’t stop at getting applications <em>into</em> the cloud. They offer bridges to your company’s private network. Using Access Control you can leverage your local AD to control security. Using Service Bus you can integrate with any application on premise or in the cloud, even let business partners integrate with you.</p>
<p><strong><a href="http://ajdotnet.files.wordpress.com/2008/11/life-mesh.gif"><img style="border-width:0;margin:0 0 5px 5px;" src="http://ajdotnet.files.wordpress.com/2008/11/life-mesh-thumb.gif?w=244&#038;h=160" border="0" alt="Life Mesh &quot;ZEN&quot;" width="244" height="160" align="right" /></a> Microsoft becomes a device integrator</strong>. They don’t stop at central storage or some device specific app for synchronizing contacts and appointments. The let you sync any application data on any Live enabled device on the fly, including handling offline cases.</p>
<p><strong>Microsoft becomes a <em>people</em> integrator</strong>. They don’t stop at providing some social application. They allow you to collaborate with other people within your own application. &#8220;People&#8221; being users authenticated by your AD, LiveID, OpenID, and probably any other well-known ID provider. All based on &#8220;claims&#8221; in order to build trust between app and user.</p>
<p>And most important: <strong><span style="text-decoration:underline;">They do all this at once!</span></strong> Putting it all together Microsoft offers a far more complete, comprehensive, and concrete vision of what the hazy term &#8220;<a href="http://en.wikipedia.org/wiki/Cloud_computing" target="_blank">cloud computing</a>&#8221; means than anybody else out there. It&#8217;s the vision of interconnected, intertwined applications, devices, networks, &#8230; the next level of <a href="http://en.wikipedia.org/wiki/Ubiquitous_computing" target="_blank">ubiquitous computing</a>.</p>
<p>OK, I may have been carried away. Currently Azure is rudimentary, not yet version 1 (and we know what <em>version 1 </em>usually means at Microsoft) and many questions remain unanswered. I cannot help but think that the mixture of various existing apps and services with hosting and a big bunch of announcements, all wrapped up in a nice <a href="http://www.itworld.com/saas/56780/oops-microsoft-forgets-trademark-windows-azure" target="_blank">name</a>, is more like a stew, thrown together but not yet readily cooked.</p>
<p>But then I might not. After all, <a href="http://www.microsoft.com/presspass/exec/ozzie/10-27PDC08dayone.mspx" target="_blank">Ray Ozzie said it loud and clear</a>:</p>
<blockquote><p>&#8220;[…] the systems that we&#8217;re building right now for cloud-based computing are setting the stage for the next 50 years of systems, both outside and inside the enterprise.&#8221;</p></blockquote>
<p>and</p>
<blockquote><p>&#8220;[..] we&#8217;re betting on Azure ourselves, and as the system scales out, we&#8217;ll be bringing more and more of our own key apps and key services onto Windows Azure because it will be our highest scale, highest availability, most economical, and most environmentally sensitive way of hosting services in the cloud.&#8221;</p></blockquote>
<p><em>That&#8217;s </em>what I call an announcement.</p>
<p><strong>Does Azure stand a chance?</strong></p>
<p><a href="http://en.wikipedia.org/wiki/Cloud_computing" target="_blank">Cloud computing</a> and <a href="http://en.wikipedia.org/wiki/Software_as_a_service" target="_blank">Software-as-a-Service</a> is widely seen as a coming trend, Azure or not. Microsoft is entering this market with vision, data centers, and service offerings. <em>And </em>a huge developer community and tooling support. This <em>will</em> change the IT industry and not many companies will be able to compete with that.</p>
<p>But a small statistic may be funny:</p>
<p>Google search for „Windows 7“: about 35,000,000 hits<br />
Google search for „Windows Azure“: about 1,830,000 hits<br />
Google search for „Amazon AWS“: about 13,000,000 hits<br />
(measured 12. Nov.´08; add one for this post <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  )</p>
<p>That&#8217;s 20 times more hits for Windows 7 than for Azure. Quite a poor result for the thing that denotes a <a href="http://www.microsoft.com/presspass/exec/ozzie/10-27PDC08dayone.mspx" target="_blank">change in strategy</a> for the worlds biggest software company, the thing that Microsoft is betting its future on.<br />
On the other hand, 2 million hits is &#8220;not too shabby&#8221; just two weeks after its announcement on the PDC. And it starts to shine if compared to the mere 7 times more hits for Amazon&#8217;s AWS, the offering that&#8217;s probably the most similar to Azure and one that dates back to <a href="http://aws.amazon.com/about-aws/whats-new/2004/" target="_blank">2004</a>(!).</p>
<p>My opinion? Don&#8217;t expect Azure to play a big role next year or the year after. But then, don&#8217;t expect it to play <em>no </em>role in 10 years.</p>
<p><span style="color:#008000;">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f11%2f16%2fabout-azure%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f11%2f16%2fabout-azure%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />Posted in .NET, .NET Framework, Azure, Software Architecture, Software Developers, Software Development  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/180/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=180&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/11/16/about-azure/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/11/ray-ozzie-pdc-keynote-thumb.jpg" medium="image">
			<media:title type="html">Ray Ozzie, Keynote PDC 2008</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/11/azure-services-platform-thumb.gif" medium="image">
			<media:title type="html">Azure Services Platform</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/11/life-mesh-thumb.gif" medium="image">
			<media:title type="html">Life Mesh &#34;ZEN&#34;</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f11%2f16%2fabout-azure%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>LINQ 2 SQL &#8212; Less is More (More or Less)</title>
		<link>http://ajdotnet.wordpress.com/2008/07/26/linq-2-sql-less-is-more-more-or-less/</link>
		<comments>http://ajdotnet.wordpress.com/2008/07/26/linq-2-sql-less-is-more-more-or-less/#comments</comments>
		<pubDate>Sat, 26 Jul 2008 12:21:55 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=167</guid>
		<description><![CDATA[Some time ago I promised some additional thoughts about how LINQ 2 SQL affects (web) application architectures. Well, here we go&#8230; There are two defining characteristics of LINQ 2 SQL that may affect the architecture of a web application: The DataContext class, being &#8220;the main entry point for the LINQ to SQL framework.&#8221; (as the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=167&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Some time ago I <a href="http://ajdotnet.wordpress.com/2008/04/20/linq-to-sql-reality-check/">promised</a> some additional thoughts about how LINQ 2 SQL affects (web) application architectures. Well, here we go&#8230;</p>
<p>There are two defining characteristics of LINQ 2 SQL that may affect the architecture of a web application:</p>
<ol>
<li>The <em>DataContext </em>class, being &#8220;the main entry point for the LINQ to SQL framework.&#8221; (as the documentation <a href="http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.aspx" target="_blank">states</a>.)</li>
<li>The way code generation works.</li>
</ol>
<p>While the first point affects what features of LINQ 2 SQL we are able to use in web applications, the second one affects the application architecture.</p>
<p>Note: if you need to catch up with LINQ 2 SQL have a look at the <a href="http://ajdotnet.wordpress.com/2008/04/20/linq-to-sql-reality-check/">my earlier post</a>.</p>
<p><strong>DataContext Effects </strong></p>
<p>In this post I&#8217;ll focus on the <em>DataContext </em>class generated by LINQ 2 SQL.</p>
<p>The <em>DataContext </em>class is not only an anchor to access the tables, views, and stored procedures. It also offers more interesting features like change tracking, maintaining object identities, optimistic concurrency, and deferred loading. Consequently this is what most people I talked to attributed to LINQ 2 SQL: The possibility of reading some data, manipulating it, and call <em>SubmitChanges</em>, while LINQ 2 SQL handles all the gory details of mapping the data, efficiently talking to the database (including load on demand), dealing with concurrent changes, and so on.</p>
<p>This read/manipulate/submit approach is what the documentation <a href="http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.aspx" target="_blank">describes </a>as being &#8220;designed to last for one &#8216;unit of work&#8217;.&#8221; And in case the consequence escaped you: This this implies a statefull programming model. The very <em>DataContext </em>instance that was used to read the data has to be available until every potential change or deferred access has been settled.</p>
<p>This does generally not agree with web applications, as read/manipulate/submit regularly spans several requests: The data is read, presented to the user, and then the request dies, and in a stateless scenario the <em>DataContext </em>as well. The next request comes in, say an update request, but there is no <em>DataContext </em>available, carrying information about the data that was read before. In order to work with the laid out programming model, one would have to create a new <em>DataContext</em>, reread the data, and then apply the changes and submit them. With optimistic locking being the first victim, because for that the information from the previous request is mandatory. And delayed loading degenerates to &#8220;optional loading&#8221;, because either you need the data (no benefit in delaying then) or you don&#8217;t.</p>
<p>How about maintaining the <em>DataContext </em>instance across requests? No way either; since it is not serializable, you can&#8217;t put it into the session. (And that&#8217;s just a technical reason, whether one should do that even if it were possible is a different matter altogether.)</p>
<p>To make a long story short, let me rephrase and emphasize the first sentence:<br />
<span style="text-decoration:underline;"><em><strong>For web applications</strong> the generated </em>DataContext </span><em><span style="text-decoration:underline;">class is <strong>only </strong>an anchor to access the tables, views, and stored procedures.</span> </em></p>
<p>BTW: Services are frequently bound to be stateless, too. Thus the same reasoning applies to them as well. Additionally they face another problem: They hand out the entities and get fresh ones from the outside world via serialization. Thereby they are removed from the DataContext, which is kind of <a href="http://www.west-wind.com/weblog/posts/162336.aspx" target="_blank">unforgiving</a>.</p>
<p><strong>Less is More</strong></p>
<p>Now we have concluded that the statefull approach doesn&#8217;t work. Reverting to a stateless employment of LINQ 2 SQL however leaves out a lot and raises the question whether there is something left at all. Well, there certainly is. We still have code generation for entity classes (based on tables and views) and for stored procedures and functions.</p>
<p>May web applications are really quite simple in that they are mainly &#8220;browsers over a (one) data store&#8221;. The complexity of those kind of applications lies more in sophisticated presentation rather than coding the business logic. In this scenario, and to really benefit from the productiveness of LINQ 2 SQL, I have had good experience using LINQ 2 SQL with just two simple tweaks:</p>
<ul>
<li><strong>Limited number of result set types (i.e. the set of columns):<br />
</strong>Rather than having my SELECTs (e.g. in stored procedures) produce different projections (i.e. tailored to the particular stored procedures task), I let them produce the same set of columns if they work on the same table. This way I will get a <em>Customer </em>entity and respective instances rather than a <em>CustomerWithAddress</em>, <em>CustomerWithRating</em>, <em>CustomerWithName</em>, <em>CustomerWithAllInfo</em>, &#8230; . And if I get that customer, I can always be sure it&#8217;s not some half filled entity.</li>
<li><strong>Explicit result set types: </strong><br />
It&#8217;s quite common to work on JOINed data. LINQ 2 SQL handles this quite well and will figure out the entity type even for stored procedures as &#8220;auto-generated type&#8221;. In order to make this type explicit in the database I would define a view containing the JOIN and have the stored procedure work against this view. And of course I use the view to generate a respective entity with LINQ 2 SQL. </li>
<li>I also refrain from having stored procedures return more than one result set or varying result set types depending on some condition. (I don&#8217;t consider this to be a tweak, because I would do that anyway.)</li>
</ul>
<blockquote><p>Of course the database may need some tuning, as some of these tweaks may hurt the performance. But <a href="http://ajdotnet.wordpress.com/2006/10/10/optimize-it/">optimization when optimization is due</a>&#8230; . And while I like the stored procedure approach, those tweaks will also work with free statements in code.</p></blockquote>
<p>These tweaks are not meant as rules but as guidelines. Feel free to break them at leisure <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  , their intention is merrily to support the LINQ 2 SQL code generation. <em>However&#8230; </em>I experienced that the define-your-entities-and-the-operations-on-top approach caused more OO-like thinking than the traditional define-your-operations-and-let-them-return-the-result-at-hand approach.</p>
<p>So, after dragging and dropping the tables, views, and stored procedures LINQ 2 SQL will happily generated the respective classes and methods. Getting type safe data and DB access was never easier.</p>
<p>If you are in the &#8220;use CRUD statements to access the database&#8221; camp, the usual round trip for an update would be: read the data that is to be changed, change it, submit changes. Like this:</p>
<blockquote><p><span style="color:#0000ff;">using</span> (MyDataContext dc = <span style="color:#0000ff;">new</span> MyDataContext())<br />
{<br />
    <span style="color:#0000ff;">var </span>customer = (<span style="color:#0000ff;">from</span> c <span style="color:#0000ff;">in</span> dc.Customer <span style="color:#0000ff;">where</span> c.ID == id <span style="color:#0000ff;">select</span> c).First();<br />
    customer.Name = <span style="color:#800000;">&#8220;new name&#8221;</span>;<br />
    dc.SubmitChanges();<br />
}</p></blockquote>
<p>Compared to ADO.NET this still eases db access a lot.</p>
<p>If you follow the &#8220;use stored procedures to access the database&#8221; approach it gets even simpler:</p>
<blockquote><p><span style="color:#0000ff;">using</span> (MyDataContext dc = <span style="color:#0000ff;">new</span> MyDataContext())<br />
{<br />
    dc.ChangeCustomerName(id, name);<br />
}</p></blockquote>
<p>This is kind of &#8220;anti-sophisticated&#8221; but quite efficient. And it allows to do concurrency in stored procedures if you maintain the version field on the client and provide it during the update call. I found this to be much more concise and better suited to the way web applications work.</p>
<p>One word of warning (or rather a disclaimer if you like): This works for <em>me</em>. And it works for a certain kind of web applications. And it only works because I&#8217;m willing to trade some academic architectural demands for the <a href="http://en.wikipedia.org/wiki/KISS_principle" target="_blank">KISS</a> principle, productivity, and maintainability. So please don&#8217;t follow this advice blindly.</p>
<p>Oh, by the way: I used this approach in a project using an Oracle database as well. Writing a simple code generator that read the system tables and generated wrappers around stored procedures was no rocket science, the only caveat was dealing with REF CURSORs.</p>
<p>The next post will take a closer look at LINQ 2 SQL code generation and how it affects the architecture.</p>
<p><span style="color:#008000;">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f07%2f26%2flinq-2-sql-less-is-more-more-or-less%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f07%2f26%2flinq-2-sql-less-is-more-more-or-less%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/167/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/167/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/167/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/167/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/167/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=167&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/07/26/linq-2-sql-less-is-more-more-or-less/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f07%2f26%2flinq-2-sql-less-is-more-more-or-less%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Working for SDX (a.k.a. My latest project&#8230;)</title>
		<link>http://ajdotnet.wordpress.com/2008/07/13/working-for-sdx-aka-my-latest-project/</link>
		<comments>http://ajdotnet.wordpress.com/2008/07/13/working-for-sdx-aka-my-latest-project/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 14:04:59 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[SDX]]></category>
		<category><![CDATA[Software Developers]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=164</guid>
		<description><![CDATA[Advertisement warning! I&#8217;ve said it in an earlier post: I like working for SDX. In fact my work has become even more challenging due to a changed job description (with the unfortunate side effect that I have less time to spend on this blog). Anyway, we are looking for people (don&#8217;t look at the date [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=164&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>Advertisement warning!</em></p>
<p><em><a href="http://www.sdx-ag.de/" target="_blank"><img style="margin:0 0 5px 5px;" src="http://ajdotnet.files.wordpress.com/2007/01/sdxlogo.gif?w=92&amp;h=28" alt="" align="right" /></a> </em></p>
<p>I&#8217;ve said it in an <a href="http://ajdotnet.wordpress.com/2006/08/11/why-i-like-working-for-sdx/">earlier post</a>: I like working for SDX. In fact my work has become even more challenging due to a changed job description (with the unfortunate side effect that I have less time to spend on this blog). Anyway, we are looking for people (don&#8217;t look at the date of the post; if you are reading this in a year the statement will still be true). Well, here&#8217;s a short description of my latest project to give you an idea on some of the work we do for our customers&#8230;</p>
<blockquote><p>I just completed a pilot study for one of our major customers, running about 3/4 of a year. Starting point was a system consisting of a non-trivial database and of two VB6/ActiveX/DHTML applications. Initially created a decade ago as replacement for a simple MS Access application, it had grown organically into a multi-purpose-application and a very vital, central data pool for &#8220;quite a few&#8221; stakeholders.</p>
<p>Since Microsoft has decommissioned VB6, the customer decided to do a VB6-to-.NET migration. My job as responsible architect was designing the target architecture, and coming up with a migration path that supported parallel operations of old and new world during the anticipated two years time the migration would take.</p>
<p>Of course in a decade the world has changed, so has the business and the way software has to be built to honor that. Globalization, European Union, changed customer&#8217;s perceptions, constantly changing demands, the way software is built, maintained, and operated.<br />
So the job quickly grew to include a new domain model, adjusted business processes, better business alignment. So far the demands.</p>
<p>The agreed on strategy we came up with is an ecosystem of applications. One core application implements the main parts of a new domain data model, ensures consistency and &#8212; essential in any distributed system and surprisingly difficult to achieve at times &#8212; provides stable identifiers. Circled around this core application is a number of other mutually independent applications. (The possibility to do this of course relies on the business requirements being mutually independent.)</p>
<p>This approach is driven by</p>
<ul>
<li>the separation of the monolith in as many as possible disparate applications (pardon the exaggeration, but it <em>is </em>a fair number),</li>
<li>defined ways of interaction between these applications (including off-the-shelf-software),</li>
<li>and providing a sound basis to support building the custom-made family members.</li>
</ul>
<p>This strategy provides the flexibility to build each application according to demand of specific stakeholders, even allowing for contradicting business demands of different departments. The set of applications can change in the future to address changed needs. Future technology changes can be applied in small steps (lessening the chance that will build the next Moloch). Maintenance should get better, because each application is less complex (simpler architecture, less business functions). <em>And </em>it conforms with <a href="http://www.objectwatch.com/white_papers.htm#SIP" target="_blank">Roger Sessions</a> works on complexity of software systems.</p>
<p>Of course, a small but rigid set of rules and governance has to be implemented to ensure peaceful coexistence and avoid &#8220;chaotic growth&#8221; of our application family in the future. Especially the growth of interdependencies between the applications has to be watched carefully.</p>
<p>Next steps will be applying for the budget at the top management and then hopefully building that system. Of course with my and SDX participation <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  .</p></blockquote>
<p>Now, if that sounds like a challenging and interesting project; if you happen to be willing to work in the Rhein/Main area, Germany; if you could envision yourself working for the same company as I do <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  &#8230; (not necessarily in that project!). Well then pay a look at <a title="http://www.sdx-ag.de/jobs.aspx" href="http://www.sdx-ag.de/jobs.aspx">http://www.sdx-ag.de/jobs.aspx</a> (German language skills mandatory!).</p>
<p><span style="color:#008000;">That&#8217;s all for now folks,<br />
<strong>AJ.SDX</strong></span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/164/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/164/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/164/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=164&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/07/13/working-for-sdx-aka-my-latest-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/01/sdxlogo.gif?w=92&#38;h=28" medium="image" />
	</item>
		<item>
		<title>Rants and rails</title>
		<link>http://ajdotnet.wordpress.com/2008/07/06/rants-and-rails/</link>
		<comments>http://ajdotnet.wordpress.com/2008/07/06/rants-and-rails/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 16:12:38 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=163</guid>
		<description><![CDATA[Something is going on out there&#8230; While I still work on LINQ 2 SQL some people started an open discussion, rant, or rail (depending on one&#8217;s view and taken offense) about the upcoming Entity Framework. In all frankness, an &#8220;ADO .NET Entity Framework Vote of No Confidence&#8221; (VoNC from now on, see here) is certainly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=163&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Something is going on out there&#8230;</p>
<p>While I still work on LINQ 2 SQL some people started an open discussion, rant, or rail (depending on one&#8217;s view and taken offense) about the upcoming Entity Framework.</p>
<p>In all frankness, an &#8220;ADO .NET Entity Framework <em>Vote of No Confidence</em>&#8221; (<em>VoNC </em>from now on, see <a href="http://efvote.wufoo.com/forms/ado-net-entity-framework-vote-of-no-confidence/" target="_blank">here</a>) is certainly capable to triggering off some very strong reactions.</p>
<blockquote><p>What I disagree with is the way in which it&#8217;s presented. The language of &#8220;Vote of No Confidence&#8221; is intended to start a fight and is long hand for &#8220;You suck&#8221;. [...]</p>
<p>I&#8217;m not upset that people are giving feedback. I want them to give feedback. But here&#8217;s the deal &#8211; do it in a grown up way. My way or the highway doesn&#8217;t sit well with anyone on the receiving end. There&#8217;s a WIDE path between being constructively critical and downright offensive.</p>
<p>(Josh Holmes, <a href="http://www.joshholmes.com/2008/06/26/RantingAndRavingOrGettingResults.aspx" target="_blank">Ranting and Raving or Getting Results?</a>)</p></blockquote>
<p>Also quite funny: While the VoNC has probably been popularized by <a href="http://blogs.zdnet.com/microsoft/?p=1457" target="_blank">Mary-Jo Foley</a>, she instantly got her &#8230; <em>feedback </em>&#8230;. from one of the VoNC&#8217;s authors:</p>
<blockquote><p>The signatories list represents leading developers, architects, and practice leads within the Microsoft community. The representation of the signatories as testers is misleading and inaccurate.</p>
<p>We would appreciate an immediate retraction and correction of this misrepresentation.</p>
<p>(Scott Bellware, MVP, see <a href="http://talkback.zdnet.com/5208-12558-0.html?forumID=1&amp;threadID=49048&amp;messageID=917057&amp;start=-9986" target="_blank">here</a>)</p></blockquote>
<p>Seems people got a little testy. Anyway, Scott also points out &#8220;the history of the feedback and relationship between the community of experts and the Entity Framework team going back to April of 2007&#8243;, which raises the question why they still had to publish the VoNC in the first place, <em>despite </em>that relationship.</p>
<p>Given all that, Microsoft&#8217;s <a href="http://blogs.msdn.com/timmall/archive/2008/06/24/vote-of-no-confidence.aspx" target="_blank">response</a> was a fine example of &#8220;cooling things down&#8221; and trying to focus in the facts. Well, essentially Tim more or less tells us that all the VoNC asked for will be kind of there in EF v2.</p>
<p>But already the VoNC is experiencing string headwind. Most is aimed at the, well, call it <em>appearance</em>, of the VoNC and a nice listing can be found <a href="http://oakleafblog.blogspot.com/2008/06/current-commentary-about-adonet-entity.html" target="_blank">here</a>. There is even an &#8220;An Open Letter to the ALT.NET Community&#8221; (see <a href="http://www.codethinked.com/post/2008/06/An-Open-Letter-to-the-ALTNET-Community.aspx" target="_blank">here</a>).</p>
<p><strong>My opinion?</strong></p>
<p>Thought I would spare you? Silly you <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>What instantly caught my attention, if just because it was the first point made in the VoNC, was the statement that &#8220;entities are more significantly behavioral objects from the perspective of entity-oriented applications&#8221; and the claim that this is a &#8220;key architectural enabler and distinction&#8221;.</p>
<p>Having some experience with EJB those statements vividly reminded me of entity beans. I have expressed my opinion on the notion of &#8220;intelligent data objects&#8221; (for lack of a better term) more than half a decade ago:</p>
<blockquote><p>My opinion is that the support of <strong>statefull </strong><strong>components</strong> (i.e. entity beans) in J2EE is one of its biggest weaknesses. Not because it&#8217;s technically bad but it leads to wrong architectural <strong>design</strong> decisions [...]<br />
(microsoft.public.dotnet.general, 4/9/2001, see <a href="http://groups.google.de/group/microsoft.public.dotnet.general/browse_thread/thread/ed870968ecee090b/2e8ed39189742006?hl=de&amp;lnk=gst&amp;q=OO+design+with+statefull+data+components+alexander#2e8ed39189742006" target="_blank">here</a>)</p></blockquote>
<p>The reasons for this opinion in 2001 (scalability, reliability, etc.) are still valid. Additionally there are a bunch of other reasons: Trends to lightweight architectures have prospered in Java and even affected .NET (back then, <em>DataSets</em> were the means of choice, today entity classes are very common). The Service notion put emphasis on data shape and operations <em>on </em>that data. Business process engines move data from system to system, shaping and reshaping it along the way. In the distributed, sometimes disconnected world that our enterprise environments have become I could build cases against behavioral objects around security, maintenance, outsourcing scenarios, versioning, testing (which is ironically so favored in the VoNC), software complexity, future safety, and so on.</p>
<p>The VoNC seems to imply that if you don&#8217;t have &#8220;behavioral objects from the perspective of entity-oriented applications&#8221;, then you are stuck with &#8220;data objects from the perspective of data storage and data storage technologies&#8221; (as I read it more or less simple mappings from database tables to objects). Well, correct me if I&#8217;m wrong, but <em>data can be reshaped without putting behavior in it</em>. That&#8217;s exactly what I expect from an ORM tool like EF.</p>
<p>I&#8217;ll stop before I get carried away. Much to my own relief, I&#8217;m not the only one having these reservations, though: <a href="http://codebetter.com/blogs/ian_cooper/archive/2008/06/26/the-criticism-of-the-entity-framework-is-not-just-around-domain-driven-design.aspx" target="_blank">Ian</a> noted the similarity with EJB as well and got deeper in this topic. <a href="http://neverindoubtnet.blogspot.com/2008/06/rejoinder-1-to-of-no-confidence-in.html" target="_blank">Ward</a> makes a good point on the issues of &#8220;Persistence Ignorance&#8221; which I share and thus won&#8217;t reiterate here.</p>
<p><strong>Where are we?</strong></p>
<p>As I see it, the ongoing discussions are circling around the issue on whether entities should follow the data centric pattern of <a href="http://en.wikipedia.org/wiki/Value_object" target="_blank">value objects</a>, or whether they should be complemented with behavior to become <a href="http://en.wikipedia.org/wiki/Business_object_%28computer_science%29" target="_blank">business objects</a>. That is largely a matter of taste.</p>
<p>On the other hand, the discussion is somewhat misleading. The topic has got nothing to do with <a href="http://en.wikipedia.org/wiki/Domain_model" target="_blank">domain models</a>, which in itself is agnostic of those two approaches. And the VoNC&#8217;s reference to the <a href="http://en.wikipedia.org/wiki/Anemic_Domain_Model" target="_blank">anemic domain model</a> (i.e. a domain model based on value objects) only muddies the water. The very verdict that this is an anti-pattern, and a horrific one at that, is due to a <a href="http://www.martinfowler.com/bliki/AnemicDomainModel.html" target="_blank">judgment by Martin Fowler</a> and only justified by the fact that it violates OO principles (which is obvious) and people think (yes, they do, according to Martin) that value objects are real objects. No wonder the VoNC calls this a &#8220;degraded architecture&#8221;.</p>
<p>So, two opposing forces, standing in muddied water, and Microsoft caught between them. The PDC is going to be interesting&#8230; <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
<p>BTW: Please note that I never said, Microsoft should not do what the VoNC asks for. There are bright people among the signatories and they should not be ignored. Microsoft as tool vendor should provide a tool than can be used in <em>any </em>architecture.</p>
<p><span style="color:#008000;">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/163/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/163/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/163/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/163/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/163/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=163&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/07/06/rants-and-rails/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>I can&#8217;t help but notice&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2008/04/27/i-cant-help-but-notice/</link>
		<comments>http://ajdotnet.wordpress.com/2008/04/27/i-cant-help-but-notice/#comments</comments>
		<pubDate>Sun, 27 Apr 2008 14:28:36 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=162</guid>
		<description><![CDATA[&#8230; that functional programming might be the next big shift in general purpose development paradigms. The other day I realized a trend that may be decisive for the evolution of our development environment in general: Functional Programming! It is not that I did not see the symptoms. It is just that it took that long [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=162&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8230; that <strong>functional programming </strong>might be the next big shift in general purpose development paradigms.</p>
<p>The other day I realized a trend that may be decisive for the evolution of our development environment in general: Functional Programming! It is not that I did not see the symptoms. It is just that it took that long to realize the breadth of it. (I&#8217;m in <a href="http://blogs.msdn.com/somasegar/archive/2007/10/17/f-a-functional-programming-language.aspx" target="_blank">good company</a>, though.)</p>
<p><strong>Yesterday&#8230;</strong></p>
<p>&#8230; it started quite unobtrusive. </p>
<p>We got <strong>generics </strong>and with them (hardly mentioned as more than syntactic sugar) <strong>type inference</strong>. </p>
<blockquote><p>In retrospect it even seems misleading that generics were discussed as something akin to C++ templates. The <a href="http://msdn2.microsoft.com/en-us/library/sbh15dya(VS.80).aspx" target="_blank">technical differences</a> may seem superfluous at first, yet some advanced techniques with templates, orthogonal libraries such as STL (only recently available as <a href="http://blogs.msdn.com/nikolad/archive/2006/06/16/STLCLR-Intro.aspx" target="_blank">STL/CLR</a> for managed code) and <a href="http://en.wikipedia.org/wiki/Template_metaprogramming" target="_blank">template meta-programming</a> have never been broadly considered for generics. Rather type inference plays a major role with generics, effectively pushing the burden of type safety from developer to compiler.</p>
</blockquote>
<p>We got <a href="http://msdn2.microsoft.com/en-us/library/0yw3tz5k(VS.80).aspx" target="_blank"><strong>anonymous methods</strong></a>, which was at that time hardly worth the effort and not at all a justified language change &#8212; if looked at in isolation.</p>
<p>We got <a href="http://msdn2.microsoft.com/en-us/library/dscyy5s0.aspx" target="_blank"><strong>iterators</strong></a>, which was again a feature no one had missed, much less asked for.</p>
<p>Several features, seemingly unrelated, some rather tiny unmotivated additions to the language.</p>
<p><strong>Today (the obvious)&#8230;</strong></p>
<p>&#8230; we have LINQ. </p>
<p>LINQ has been <a href="http://blogs.msdn.com/danielfe/archive/2005/09/13/464904.aspx" target="_blank">introduced at the PDC 05</a> by Anders Hejlsberg et al. as <a href="http://msdn2.microsoft.com/en-us/library/bb308959.aspx" target="_blank">kind of</a> &#8220;complied SQL statements&#8221;, &#8220;type safe SQL&#8221;, and &#8220;unified query language&#8221;, thus the name of course. </p>
<blockquote><p>The language features that make up LINQ rely on the above language features. And with LINQ those pieces suddenly fall into shape. Type inference for anonymous types and together with generics as general foundation, anonymous methods for lambdas, iterators for deferred execution. A concise system.</p>
</blockquote>
<p>And this is how LINQ is seen by many people: <em>Type safe queries</em>. Something to replace ugly ADO.NET code over SQL strings with beautiful and compiler checked C# statements. Who can blame them, that&#8217;s how it got introduced.</p>
<p>What those people miss is the less obvious force behind LINQ. It&#8217;s functional programming, as Anders itself <a href="http://blogs.msdn.com/charlie/archive/2007/01/26/anders-hejlsberg-on-linq-and-functional-programming.aspx" target="_blank">explains</a> &#8212; not the other way round, as presented in <a href="http://msdn.microsoft.com/msdnmag/issues/07/06/CSharp30/" target="_blank">&#8220;The Evolution Of LINQ And Its Impact On The Design Of C#&#8221;</a>.</p>
<blockquote><p>It&#8217;s not that the trend to functional programming is kept secretly. Matter of fact, the term is mentioned quite frequently in relation to LINQ. And there&#8217;s other evidence, like the new .NET language <a href="http://research.microsoft.com/fsharp/" target="_blank">F#</a>, incidentally written by <a href="http://research.microsoft.com/~dsyme/" target="_blank">Don Syme</a>, the man who built generics for .NET. And there&#8217;s enough <a href="http://blogs.msdn.com/search/SearchResults.aspx?q=functional+programming&amp;o=Relevance" target="_blank">bloggers out there</a>, talking about the topic. <br />It&#8217;s more that the average corporate developer, the kind that has more than enough to do getting his job done, is not directly exposed to this information. Therefore he picks up only occasional hints at best, not connected, not nearly enough to identify a larger trend. Many of them may not even be aware about the degree to which they have already exposed to functional programming bits and pieces.</p>
</blockquote>
<p><strong>Today (the not so obvious)&#8230;</strong></p>
<p>&#8230; there is a lot of talk around functional programming going on in the blog sphere. Some examples:</p>
<p>Regarding lambdas have a look at <a href="http://blogs.msdn.com/wesdyer/archive/tags/Functional+Programming/default.aspx" target="_blank">Wes&#8217; blog</a> to learn about currying, continuations, monads. Other bloggers have written about other language features (e.g. <a href="http://ajdotnet.wordpress.com/2008/03/21/using-extension-methods-for-fluent-interfaces/">extension methods</a>). Luca tries to <a href="http://blogs.msdn.com/lucabol/archive/2008/04/01/a-c-library-to-write-functional-code-part-i-background.aspx" target="_blank">bring F# features to C#</a>.</p>
<p>Also there has been a lot of noise around one of the tenets of functional programming: immutable data types. Just as we got new collection classes with generics, we may get immutable ones sometime in the future.</p>
<blockquote><p>If you like to read up on immutable data types, Roy has compiled a list of <a href="http://weblogs.asp.net/bleroy/archive/2008/01/16/immutability-in-c.aspx" target="_blank">related blog posts</a>; I found Erics <a href="http://blogs.msdn.com/ericlippert/archive/2007/11/13/immutability-in-c-part-one-kinds-of-immutability.aspx" target="_blank">series</a> to be the best, as he addresses not only the purpose but also the feasibility (consider the insolence, a list that does not change, how can that be feasible?). And he addresses null values (not exactly part of the functional universe) better than the others. </p>
</blockquote>
<p>Another interesting application is <a href="http://www.clariusconsulting.net/blogs/kzu/archive/category/1062.aspx" target="_blank">MoQ</a> (if not by itself, then as an example for the functional approach), a LINQ based mock framework. It may serve as indication that even stuff that is not directly related to functional programming may come in a functional shape.</p>
<p><strong>Tomorrow&#8230;</strong></p>
<p>&#8230; &#8212; and this is strictly a personal guess &#8212; the trend will continue. If anything it will diverge in different areas. Functional programming in general and F# idioms in particular may contribute to our languages, the patterns we use, and the libraries. F# may not only be the first functional language to decisively <a href="http://msdn2.microsoft.com/en-us/magazine/cc164244.aspx" target="_blank">enter the .NET environment</a>, it may be the very first functional language with at least the potential to become a <a href="http://www.amazon.com/Expert-F-Experts-Voice-Net/dp/1590598504/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1209298946&amp;sr=8-1" target="_blank">mainstream language</a>.&nbsp; </p>
<p>The driving force behind this is something that Anders hinted at it in his interview above, and that Pat Helland <a href="http://blogs.msdn.com/pathelland/archive/2008/01/11/pdf-version-of-the-slides-for-the-irresistible-forces-meet-the-movable-objects.aspx" target="_blank">pointed out</a> quite clearly at the TechEd: <em>The future is parallel</em>. And functional programming is so much more suited to parallel processing than imperative programming. Matter of fact, <a href="http://msdn2.microsoft.com/en-us/magazine/cc163329.aspx" target="_blank">Parallel LINQ (PLINQ)</a> is already working in that direction. </p>
<p><strong>Right now&#8230;</strong></p>
<p>&#8230; that&#8217;s enough gazing in the crystal ball. What&#8217;s the consequence (provided you share my view)? Today probably nothing. None of <em>my </em>daily work is affected, beyond using LINQ as a nice tool. Tomorrow perhaps still nothing, as I may be totally wrong. All I can recommend is this: Try to see the bigger picture behind LINQ and keep watching for the trend. For if it&#8217;s the other way round, you may be tomorrows next VB guy, like the one in the next cubicle that never mastered inheritance and exceptions.</p>
<blockquote><p>As an afterthought: I&#8217;m not aware that this functional programming trend happened somewhere outside the Microsoft space. This is contrary to the dynamic languages trend. And I&#8217;m honestly not sure what the implication is.</p>
</blockquote>
<p><font color="#008000">That&#8217;s all for now folks,<br /><strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f04%2f27%2fi-cant-help-but-notice%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f04%2f27%2fi-cant-help-but-notice%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/162/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/162/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/162/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=162&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/04/27/i-cant-help-but-notice/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f04%2f27%2fi-cant-help-but-notice%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>LINQ to SQL Reality Check</title>
		<link>http://ajdotnet.wordpress.com/2008/04/20/linq-to-sql-reality-check/</link>
		<comments>http://ajdotnet.wordpress.com/2008/04/20/linq-to-sql-reality-check/#comments</comments>
		<pubDate>Sun, 20 Apr 2008 12:37:58 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=157</guid>
		<description><![CDATA[After the introduction and checking LINQ to Objects, this is the second part of the Reality Check story. Employment of LINQ to SQL OK, off with the gloves and hard core LINQ But first some background: LINQ to SQL manifests itself as a .dbml file supported in VS2008 by a respective designer. Via server explorer [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=157&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After the <a href="http://ajdotnet.wordpress.com/2008/04/13/linq-to-objects-reality-check/">introduction and checking LINQ to Objects</a>, this is the second part of the Reality Check story.</p>
<p><strong><span style="text-decoration:underline;">Employment of LINQ to SQL</span></strong></p>
<p>OK, off with the gloves and hard core LINQ <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><a href="http://ajdotnet.files.wordpress.com/2008/04/image1.png" target="_blank"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;margin:0 0 5px 5px;" src="http://ajdotnet.files.wordpress.com/2008/04/image-thumb1.png?w=244&#038;h=145" border="0" alt="image" width="244" height="145" align="right" /></a> <strong>But first some background: </strong>LINQ to SQL manifests itself as a <em>.dbml </em>file supported in VS2008 by a respective <a href="http://msdn2.microsoft.com/en-us/library/bb384511.aspx" target="_blank">designer</a>. Via server explorer one can add tables, stored procedures, and other DB objects to the designer. <a href="http://msdn2.microsoft.com/en-us/library/bb386987.aspx" target="_blank">SQLMetal</a>, the code generation tool behind the scenes of LINQ to SQL, is used to generate code for the <a href="http://msdn2.microsoft.com/en-us/library/system.data.linq.datacontext.aspx" target="_blank">data context class</a> with static methods for stored procedures. Tables are mapped to entity classes, columns to properties, in a trivial fashion but non-trivial way. E.g. the ID column:</p>
<blockquote><p>[Column(Storage="_CustomerID", DbType="UniqueIdentifier NOT NULL")]<br />
public System.Guid CustomerID<br />
{<br />
     get<br />
     {<br />
         return this._CustomerID;<br />
     }<br />
     set<br />
     {<br />
        if ((this._CustomerID != value))<br />
        {<br />
            if (this._Customer.HasLoadedOrAssignedValue)<br />
            {<br />
                throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();<br />
            }<br />
             this.OnCustomerIDChanging(value);<br />
             this.SendPropertyChanging();<br />
             this._CustomerID = value;<br />
             this.SendPropertyChanged(&#8220;CustomerID&#8221;);<br />
             this.OnCustomerIDChanged();<br />
         }<br />
     }<br />
}</p></blockquote>
<p>As you can see, the set method goes at length to announce the change of the value. The generated entity properties support various &#8220;events&#8221; by means of <a href="http://ajdotnet.wordpress.com/2007/09/04/partial-methods-for-partial-developers/">partial methods</a>, and the entity classes implement respective interfaces (<a href="http://msdn2.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanging.aspx" target="_blank">INotifyPropertyChanging</a> and <a href="http://msdn2.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx" target="_blank">INotifyPropertyChanged</a>).<br />
In addition to properties for columns, the entity classes provide properties for relationships (supporting lazy loading) if they have been modeled accordingly.</p>
<p>All generated classes are realized as partial classes and can be adorned with custom code without problems. All classes are created in one big source file, one can however influence the class names, namespaces and some other parameters that affect code generation.</p>
<p><strong>Now back to the prototype application&#8230;</strong></p>
<p>The prototype application uses &#8220;poor man&#8217;s O/R mapping&#8221;, i.e. data readers to access the DB and manual mapping to <a href="http://de.wikipedia.org/wiki/POJO" target="_blank">POCO</a>s. It even doesn&#8217;t use reflection (dude, it&#8217;s a <em>prototype </em>application), thus it is by no means representative.</p>
<p>Anyway, I&#8217;ll just present old and new code as before, again, relevant parts in bold. </p>
<p><strong>3. Example: </strong>Reading a customer (single object) from the database.</p>
<blockquote><p>const string SELECT_CUSTOMER_BY_ACCOUNT = &#8220;select * from customer where MainAccount=@MainAccount&#8221;;</p>
<p>Customer FindCustomer(int mainAccount)<br />
{<br />
     Customer c;<br />
     using (SqlConnection con = OpenConnection())<br />
     {<br />
         using (SqlCommand command = new SqlCommand(SELECT_CUSTOMER_BY_ACCOUNT, con))<br />
         {<br />
             AddParameter(command, &#8220;MainAccount&#8221;, mainAccount);</p>
<p>             using (SqlDataReader reader = command.ExecuteReader())<br />
             {<br />
                 while (reader.Read())<br />
                 {<br />
                     c = FillCustomer(reader);<br />
                     return c;<br />
                 }<br />
             }<br />
         }<br />
     }<br />
     return null;<br />
}</p>
<p>private static Customer FillCustomer(SqlDataReader reader)<br />
{<br />
     Customer c = new Customer();<br />
     string name;<br />
     for (int i = 0; i &lt; reader.FieldCount; ++i)<br />
     {<br />
         name = reader.GetName(i).ToLower();<br />
         switch (name)<br />
         {<br />
             case &#8220;id&#8221;: c.Id = reader.GetGuid(i); break;<br />
             case &#8220;mainaccount&#8221;: c.MainAccount = reader.GetInt32(i); break;<br />
             case &#8220;name&#8221;: c.Name = reader.GetString(i); break;<br />
         }<br />
     }<br />
     return c;<br />
}</p></blockquote>
<p>Nothing but boilerplate code. And the rewrite using LINQ to SQL:</p>
<blockquote><p>CustomerLinq FindCustomerLinq(int mainAccount)<br />
{<br />
     DataClassesDataContext dc = new DataClassesDataContext();<br />
     var customerList = from cc in dc.CustomerLinqs where cc.MainAccount == mainAccount select cc;<br />
     return customerList.FirstOrDefault();<br />
}</p></blockquote>
<p>About 35 LOC (still 20 LOC if the mapping is left out) vs. 6 LOC. No need to comment on that I guess&#8230;</p>
<p>To provide a complete picture (and because I didn&#8217;t want to change the whole application to new entity classes) I also tried the &#8220;separate entity assembly&#8221; approach. This code also maps the generated entities to layer independent entities:</p>
<blockquote><p>Customer FindCustomerLinq2(int mainAccount)<br />
{<br />
     DataClassesDataContext dc = new DataClassesDataContext();<br />
     var customerList = from cc in dc.CustomerLinqs where cc.MainAccount == mainAccount select cc;<br />
     var cl= customerList.FirstOrDefault();<br />
<strong>     if (cl!=null)<br />
         return new Customer() { Id= cl.ID, MainAccount= cl.MainAccount, Name= cl.Name, TotalBalance= cl.TotalBalance };<br />
</strong>     return null;<br />
}</p></blockquote>
<p>As there was no appropriate constructor, object initializers kicked in nicely. Of course this would be the next mapping method, but not to complicated and, contrary to the data reader mapping above, it would be fully type safe (unless you employed reflection, of course).</p>
<p><strong>4. Example: </strong>Read all accounts (i.e. a list) for a customer.</p>
<blockquote><p>const string SELECT_ACCOUNTS_BY_CUSTOMER= &#8220;select * from vAccount where CustomerID=@CustomerID order by SubAccount&#8221;;</p>
<p>IList&lt;Account&gt; IAccountTable.GetAccounts(Guid customerId)<br />
{<br />
        IList&lt;Account&gt; list = new List&lt;Account&gt;();<br />
        Account a;<br />
        using (SqlConnection con = OpenConnection())<br />
        {<br />
                using (SqlCommand command = new SqlCommand(SELECT_ACCOUNTS_BY_CUSTOMER, con))<br />
                {<br />
                        AddParameter(command, &#8220;CustomerID&#8221;, customerId);</p>
<p>                        using (SqlDataReader reader = command.ExecuteReader())<br />
                        {<br />
                                while (reader.Read())<br />
                                {<br />
                                        a = FillAccount(reader);<br />
                                        list.Add(a);<br />
                                }<br />
                        }<br />
                }<br />
        }<br />
        return list;<br />
}</p>
<p>private static Account FillAccount(SqlDataReader reader)<br />
{<br />
        Account a = new Account();<br />
        string name;<br />
        for (int i = 0; i &lt; reader.FieldCount; ++i)<br />
        {<br />
                name = reader.GetName(i).ToLower();<br />
                switch (name)<br />
                {<br />
                        case &#8220;id&#8221;: a.Id = reader.GetGuid(i); break;<br />
                        case &#8220;mainaccount&#8221;: a.MainAccount = reader.GetInt32(i); break;<br />
                        case &#8220;subaccount&#8221;: a.SubAccount = reader.GetInt32(i); break;<br />
                        case &#8220;balance&#8221;: a.Balance = reader.GetDecimal(i); break;<br />
                }<br />
        }<br />
        return a;<br />
}</p></blockquote>
<p>With LINQ:</p>
<blockquote><p>IList&lt;AccountLinq&gt; GetAccountsLinq(Guid customerId)<br />
{<br />
     DataClassesDataContext dc = new DataClassesDataContext();<br />
     var accountsList = from aa in dc.AccountLinqs where aa.CustomerID == customerId orderby aa.SubAccount select aa;<br />
     return accountsList.ToList();<br />
}</p></blockquote>
<p>The same LOC relation as above. Mapping the generated entities may be a little more effort, but still far less than in the classical version. And since I called <em>ToList()</em> I didn&#8217;t even have to change my interfaces. With separate entities one would have to traverse the list and translate each entry. But again, no big deal and less work than without LINQ.</p>
<p><strong>Conclusion:</strong></p>
<p>The rate of code reduction with LINQ to SQL is even higher than with LINQ to Objects. This is something that&#8217;s very hard to ignore.</p>
<p>On the other hand, there is the architectural issue to be solved. In my opinion the biggest obstacle with LINQ to SQL is the fact that all code, entities and data context, are created in one big source file, thus I cannot separate them. I cannot put the entities in an entity assembly as mandated by the <a href="http://ajdotnet.wordpress.com/2007/04/29/infactoring-the-architecture/">architecture</a> without also putting the data context class into that assembly as well, exposing the database to anyone unduly interested. The alternative would be to have a second set of entities, one for the data access and one to flow across the layers. And respective mapping code. Doable as I checked, but not a nice prospect.</p>
<p>BTW, this time I used nearly every aspect of LINQ: The code contained Query Syntax, Extension Methods, Lambdas, Object Initializers, and Type Inference. And with <em>System.Data.Linq</em> a library is used that heavily relies on Expression Trees. Anonymous Types is the only missing part.</p>
<p><strong>Final judgement:</strong></p>
<p>All in all, LINQ proved to be such a useful addition to the developers toolbox that it cannot be ignored, even if it has its own problems. And while it is often seen as &#8220;better SQL&#8221;, this is already shortsighted. My <a href="http://ajdotnet.wordpress.com/category/linq/">earlier posts</a> as well as all the fuss about functional programming in general should be indication enough that this is just where it begins.</p>
<p><span style="color:#008000;">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f04%2f20%2flinq-to-sql-reality-check%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f04%2f20%2flinq-to-sql-reality-check%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/157/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/157/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/157/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/157/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/157/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/157/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/157/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/157/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/157/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/157/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=157&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/04/20/linq-to-sql-reality-check/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/04/image-thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f04%2f20%2flinq-to-sql-reality-check%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>LINQ to Objects Reality Check</title>
		<link>http://ajdotnet.wordpress.com/2008/04/13/linq-to-objects-reality-check/</link>
		<comments>http://ajdotnet.wordpress.com/2008/04/13/linq-to-objects-reality-check/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 12:38:47 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=156</guid>
		<description><![CDATA[The following post is actually a translation of a post I wrote last year for our internal company blog. It&#8217;s already gained some moss, so to speak (LINQ is released; isn&#8217;t there some new technology to blog about? ), but it may still serve as motivation for those who have successfully avoided the LINQ hype [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=156&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>The following post is actually a translation of a post I wrote last year for our internal company blog. It&#8217;s already gained some moss, so to speak (LINQ is released; isn&#8217;t there some new technology to blog about? <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ), but it may still serve as motivation for those who have successfully avoided the LINQ hype so far. And I kind of need it as introduction to some other posts I have in mind.</em></p>
<p><em>Here we go&#8230;</em></p>
<p>To me, LINQ seemed to be quite interesting, but until recently it was exactly that: a semblance &#8212; and one that has to be proved. I didn&#8217;t want another bunch of test code showing the exact problems that LINQ was built to solve and LINQ (surprise!) solving those problems. I wanted to see how LINQ fared in a real world scenario, i.e. based on existing code <em>not </em>built with LINQ in mind.</p>
<p>I have a little prototype application at my disposal. Not exactly a productive application, but near enough for my purpose. It&#8217;s a simple 3tier web application, as outlined in an <a href="http://ajdotnet.wordpress.com/2007/04/29/infactoring-the-architecture/">earlier post</a>.</p>
<p>My experiment took three steps:</p>
<ol>
<li>Migration to VS2008 und .NET 3.5</li>
<li>Employment of LINQ to Objects</li>
<li>Employment of LINQ to SQL</li>
</ol>
<p>Here are my experiences &#8212; the LINQ to Objects part in this post, the LINQ to SQL part in the next one. Valuations are purely subjective <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  &#8230;</p>
<p>The migration ran smoothly enough, unit test assemblies had to migrated manually and code analysis spit out a lot of new warnings (which may be an issue in bigger projects and if you like &#8220;warnings as errors&#8221;). Otherwise the application ran without problem.</p>
<p><strong><span style="text-decoration:underline;">Employment of LINQ to Objects</span></strong></p>
<p>LINQ to Objects is only a using statement away. All you have to do is adding the following line (and the respective assembly reference, if not done already):</p>
<blockquote><p>using System.Linq;</p></blockquote>
<p>Afterwards I scanned the existing code for rewrite candidates. You don&#8217;t need to understand the gory details of the following samples, the important thing is the relation between the non-LINQ and the LINQ versions. The relevant parts of the samples are in bold.</p>
<p><strong>1. Example: </strong>A code fragment that reads all accounts of a customer and calculates the balance.</p>
<blockquote><p>Customer c= &#8230;.<br />
IList&lt;Account&gt; al = AccountTable.GetAccounts(c.Id);</p>
<p><strong>c.TotalBalance = 0;<br />
foreach (Account a in al)<br />
     c.TotalBalance += a.Balance;</strong></p></blockquote>
<p>The rewrite with LINQ:</p>
<blockquote><p>Customer c= &#8230;<br />
IList&lt;Account&gt; al = AccountTable.GetAccounts(c.Id);</p>
<p><strong>c.TotalBalance = al.Sum(a =&gt; a.Balance);</strong></p></blockquote>
<p>Effect: Calculating the sum is down from 3 lines of code to one line of code &#8212; and quite a bit more readable as well.</p>
<p><strong>2. Example: </strong>Find a sub account in a sub account list.</p>
<blockquote><p>IList&lt;Account&gt; list1 = AccountTable.GetAccounts(c.Id);</p>
<p><strong>Account a= null;<br />
foreach (Account a1 in list1)<br />
{<br />
     if (a1.SubAccount == subAccount)<br />
     {<br />
         a = a1;<br />
         break;<br />
     }<br />
}</strong></p></blockquote>
<p>Another &#8220;classical&#8221; version could have been provided via an anonymous delegate, though only available with the class <em>List&lt;&gt;</em>, not the interface <em>IList&lt;&gt;</em>:</p>
<blockquote><p>IList&lt;Account&gt; list1 = AccountTable.GetAccounts(c.Id);</p>
<p><strong>List&lt;Account&gt; list2 = list1 as List&lt;Account&gt;;<br />
a = list2.Find(<br />
     delegate(Account test)<br />
     {<br />
         return (test.SubAccount == subAccount);<br />
     });</strong></p></blockquote>
<p>And the LINQ version:</p>
<blockquote><p>IList&lt;Account&gt; list1 = AccountTable.GetAccounts(c.Id);</p>
<p><strong>Account a = list1.First(test =&gt; (test.SubAccount == subAccount));</strong></p></blockquote>
<p>The effect: LOC down from 9 (6 with delegate) to 1. And more readable. And applicable on the interface (rather than the <em>List&lt;&gt; </em>class).</p>
<p><strong>Conclusion: </strong></p>
<p>In the cases shown above, LINQ to Object provides way more efficient code, less code, better readable code. The cases were all related to list operations. And this is by no means tied in any way to database operations, i.e. <em>any </em>code may profit from this. On the other hand, I didn&#8217;t find any other use cases beside list operations in the existing code.</p>
<p>At a closer look only a subset of the LINQ features were involved: Extension methods, lambdas, and the <em>System.Linq </em>library. This is not an issue, just stating a fact. It&#8217;s not that the query syntax and other features aren&#8217;t available without database, it&#8217;s just that I didn&#8217;t need them.</p>
<p>End of part 1, the short and easy on, actually. But very convincing so far. The next post will look into LINQ to SQL.</p>
<p><span style="color:#008000;">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f04%2f13%2flinq-to-objects-reality-check%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f04%2f13%2flinq-to-objects-reality-check%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/156/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/156/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/156/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=156&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/04/13/linq-to-objects-reality-check/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f04%2f13%2flinq-to-objects-reality-check%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Extension Methods for Fluent Interfaces</title>
		<link>http://ajdotnet.wordpress.com/2008/03/21/using-extension-methods-for-fluent-interfaces/</link>
		<comments>http://ajdotnet.wordpress.com/2008/03/21/using-extension-methods-for-fluent-interfaces/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 14:53:31 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2008/03/21/using-extension-methods-for-fluent-interfaces/</guid>
		<description><![CDATA[The last post was a bit dry; this time let&#8217;s do some coding first and add the justification afterwards. I now and than have to create XML within code. Just to have an example to work on, take this configuration file fragment: &#60;?xml version=&#8220;1.0&#8243; encoding=&#8220;utf-8&#8243; ?&#62; &#60;configuration&#62;     &#60;appSettings&#62;         &#60;add key=&#8220;email&#8221; value=&#8220;nospam@mysite.com&#8221;/&#62;         &#60;add [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=155&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://ajdotnet.wordpress.com/2008/03/16/using-extension-methods-for-decomposition/">last post</a> was a bit dry; this time let&#8217;s do some coding first and add the justification afterwards.</p>
<p>I now and than have to create XML within code. Just to have an example to work on, take this configuration file fragment:</p>
<blockquote><p><font color="#0000ff">&lt;?</font><font color="#800000">xml</font> <font color="#ff0000">version</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;1.0&#8243;</font> <font color="#ff0000">encoding</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;utf-8&#8243;</font> <font color="#0000ff">?&gt;</font><br />
<font color="#0000ff">&lt;</font><font color="#800000">configuration</font><font color="#0000ff">&gt;</font><br />
    <font color="#0000ff">&lt;</font><font color="#800000">appSettings</font><font color="#0000ff">&gt;<br />
        </font><font color="#0000ff">&lt;</font><font color="#800000">add</font> <font color="#ff0000">key</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;email&#8221;</font> <font color="#ff0000">value</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;nospam@mysite.com&#8221;</font><font color="#0000ff">/&gt;</font><br />
        <font color="#0000ff">&lt;</font><font color="#800000">add</font> <font color="#ff0000">key</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;email2&#8243;</font> <font color="#ff0000">value</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;nospam@othersite.com&#8221;</font><font color="#0000ff">/&gt;</font><br />
    <font color="#0000ff">&lt;/</font><font color="#800000">appSettings</font><font color="#0000ff">&gt;</font><br />
<font color="#0000ff">&lt;/</font><font color="#800000">configuration</font><font color="#0000ff">&gt;</font></p>
<p><font color="#0000ff"></font></p></blockquote>
<p>To create this little XML on the fly, using plain .NET BCL means, the code would look like this:</p>
<blockquote><p><font color="#0000ff">private</font> <font color="#0000ff">static</font> <font color="#008080">XmlDocument</font> CreateAppConfig_Manual()<br />
{<br />
    <font color="#008080">XmlDocument</font> doc = <font color="#0000ff">new</font> <font color="#008080">XmlDocument</font>();<br />
    doc.AppendChild(doc.CreateXmlDeclaration(<font color="#800000">&#8220;1.0&#8243;</font>, <font color="#008080">Encoding</font>.UTF8.BodyName, <font color="#800000">&#8220;yes&#8221;</font>));<br />
   <br />
    <font color="#008080">XmlElement</font> eConf = doc.CreateElement(<font color="#800000">&#8220;configuration&#8221;</font>);<br />
    doc.AppendChild(eConf);<br />
    <font color="#008080">XmlElement</font> eSettings = doc.CreateElement(<font color="#800000">&#8220;appSettings&#8221;</font>);<br />
    eConf.AppendChild(eSettings);<br />
   <br />
    <font color="#008080">XmlElement</font> eAdd = doc.CreateElement(<font color="#800000">&#8220;add&#8221;</font>);<br />
    eSettings.AppendChild(eAdd);<br />
    eAdd.SetAttribute(<font color="#800000">&#8220;key&#8221;</font>, <font color="#800000">&#8220;email&#8221;</font>);<br />
    eAdd.SetAttribute(<font color="#800000">&#8220;value&#8221;</font>, <font color="#800000">&#8220;nospam@mysite.com&#8221;</font>);<br />
   <br />
    eAdd = doc.CreateElement(<font color="#800000">&#8220;add&#8221;</font>);<br />
    eSettings.AppendChild(eAdd);<br />
    eAdd.SetAttribute(<font color="#800000">&#8220;key&#8221;</font>, <font color="#800000">&#8220;email2&#8243;</font>);<br />
    eAdd.SetAttribute(<font color="#800000">&#8220;value&#8221;</font>, <font color="#800000">&#8220;nospam@othersite.com&#8221;</font>);<br />
   <br />
    <font color="#0000ff">return</font> doc;<br />
}</p></blockquote>
<p>It&#8217;s quite obvious that this C# method creates the XML above, is it not? Well, it does, as long as I did not forget to append that element over there after creating it. And appended it to the correct parent node. Which had to be created and appended to&#8230; which node?</p>
<p><strong>Improving the code with helper methods</strong></p>
<p>This is exactly the situation in which I usually come up with a little helper class:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">class</font> XmlHelper<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#008080">XmlDocument</font> CreateXmlDocument(<font color="#008080">Encoding</font> enc)<br />
    {<br />
        <font color="#008080">XmlDocument </font>doc = <font color="#0000ff">new</font> <font color="#008080">XmlDocument</font>();<br />
        doc.AppendChild(doc.CreateXmlDeclaration(<font color="#800000">&#8220;1.0&#8243;</font>, enc.BodyName, <font color="#800000">&#8220;yes&#8221;</font>));<br />
        <font color="#0000ff">return</font> doc;<br />
    }<br />
   <br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#008080">XmlElement</font> CreateElement(<font color="#008080">XmlDocument</font> parent, <font color="#0000ff">string</font> name)<br />
    {<br />
        <font color="#008080">XmlElement</font> e = parent.CreateElement(name);<br />
        parent.AppendChild(e);<br />
        <font color="#0000ff">return</font> e;<br />
    }<br />
   <br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#008080">XmlElement</font> CreateElement(<font color="#008080">XmlElement</font> parent, <font color="#0000ff">string</font> name)<br />
    {<br />
        <font color="#008080">XmlElement</font> e = parent.OwnerDocument.CreateElement(name);<br />
        parent.AppendChild(e);<br />
        <font color="#0000ff">return</font> e;<br />
    }<br />
}</p></blockquote>
<p>Tiny little methods, not doing very much, thus not worth very much? On the contrary. (In reality I would add some parameter checks, but this is not my point right now.) Have a look at the polished up code:</p>
<blockquote><p><font color="#0000ff">private</font> <font color="#0000ff">static</font> <font color="#008080">XmlDocument</font> CreateAppConfig_Helper()<br />
{<br />
    <font color="#008080">XmlDocument</font> doc = <font color="#008080">XmlHelper</font>.CreateXmlDocument(<font color="#008080">Encoding</font>.UTF8);<br />
    <font color="#008080">XmlElement</font> eConf = <font color="#008080">XmlHelper</font>.CreateElement(doc, <font color="#800000">&#8220;configuration&#8221;</font>);<br />
    <font color="#008080">XmlElement</font> eSettings = <font color="#008080">XmlHelper</font>.CreateElement(eConf, <font color="#800000">&#8220;appSettings&#8221;</font>);<br />
   <br />
    <font color="#008080">XmlElement</font> eAdd = <font color="#008080">XmlHelper</font>.CreateElement(eSettings, <font color="#800000">&#8220;add&#8221;</font>);<br />
    eAdd.SetAttribute(<font color="#800000">&#8220;key&#8221;</font>, <font color="#800000">&#8220;email&#8221;</font>);<br />
    eAdd.SetAttribute(<font color="#800000">&#8220;value&#8221;</font>, <font color="#800000">&#8220;nospam@mysite.com&#8221;</font>);<br />
   <br />
    eAdd = <font color="#008080">XmlHelper</font>.CreateElement(eSettings, <font color="#800000">&#8220;add&#8221;</font>);<br />
    eAdd.SetAttribute(<font color="#800000">&#8220;key&#8221;</font>, <font color="#800000">&#8220;email2&#8243;</font>);<br />
    eAdd.SetAttribute(<font color="#800000">&#8220;value&#8221;</font>, <font color="#800000">&#8220;nospam@othersite.com&#8221;</font>);<br />
   <br />
    <font color="#0000ff">return</font> doc;<br />
}</p></blockquote>
<p>To me this looks way better. It&#8217;s shorter, better readable, and the code contains what I <u>want to do</u>, not <u>how to do</u> it.</p>
<p><strong>Improving the code with extension methods</strong></p>
<p>OK, plain helper methods were yesterday, today we have extension methods. But carefully, or you&#8217;ll step into the same trap as I did!</p>
<p>I started doing it naively by adding the &#8220;this&#8221; keyword to all first parameters and changing the calls accordingly. It compiled smoothly, ran smoothly&#8230; and produced an empty document. Why? Because the <em>CreateElement(this XmlDocument) </em>collides with the existing method <em>XmlDocument.CreateElement()</em>. And neither intellisense, nor the compiler, nor the runtime bothered to tell me.</p>
<p>Lesson learned: Be careful with extension method names!</p>
<p>Anyway, all this would change would be two calls to <em>CreateElement()</em> which is not worth the effort. Actually the thing that bothers me the most with the above code is all those temporary variables. But the reason I need them is (only) that I need to apply several calls on them. Enter Fluent Interfaces!</p>
<p><strong>Improving the code with fluent interfaces</strong></p>
<p>The very idea of fluent interfaces is that one method that would otherwise be declared as void, returns a reference that can instantly be used for the next call. So, what do you think about this little beauty:</p>
<blockquote><p><font color="#0000ff">private</font> <font color="#0000ff">static</font> <font color="#008080">XmlDocument</font> CreateAppConfig_Fluent()<br />
{<br />
    <font color="#0000ff">return</font> <font color="#008080">XmlHelper</font>.CreateXmlDocument(Encoding.UTF8)<br />
        .NewElement(<font color="#800000">&#8220;configuration&#8221;</font>)<br />
            .NewElement(<font color="#800000">&#8220;appSettings&#8221;</font>)<br />
                .NewElement(<font color="#800000">&#8220;add&#8221;</font>)<br />
                    .SetAttrib(<font color="#800000">&#8220;key&#8221;</font>, <font color="#800000">&#8220;email&#8221;</font>)           <font color="#008000"><i>// name collsion</i></font><br />
                    .SetAttrib(<font color="#800000">&#8220;value&#8221;</font>, <font color="#800000">&#8220;nospam@mysite.com&#8221;</font>)<br />
                    .Parent()                                    <font color="#008000"><i>// type safe version of ParentNode</i></font><br />
                .NewElement(<font color="#800000">&#8220;add&#8221;</font>)<br />
                    .SetAttrib(<font color="#800000">&#8220;key&#8221;</font>, <font color="#800000">&#8220;email2&#8243;</font>)<br />
                    .SetAttrib(<font color="#800000">&#8220;value&#8221;</font>, <font color="#800000">&#8220;nospam@othersite.com&#8221;</font>)<br />
                    .OwnerDocument;<br />
}</p></blockquote>
<p>No more unnecessary temporaries, and way more readable as the code indentation even reflects the XML structure.</p>
<p>Of course I had to provide respective extension methods to allow this method to be written:</p>
<ul>
<li>I changed the <em>CreateElement() </em>extension methods to <em>NewElement() </em>to avoid the name collision. I had another name clash with the <em>SetAttribute()</em> method, which I needed to provide because&#8230; </li>
<li>every method had to return a value (to pass the reference along).</li>
<li>In order not to &#8220;break the chain&#8221; I had to add methods to &#8220;navigate&#8221; in cases were the returned value was not the one to work on afterwards, e.g. I had to provide the <em>Parent() </em>method.</li>
<li>And finally I needed the correct return type, i.e. the most derived type, in order to apply the specific extension methods. This was why I could not use <em>XmlNode.ParentNode</em> for &#8220;navigation&#8221;. It has the wrong type of <em>XmlNode </em>rather than the required <em>XmlElement</em>.</li>
</ul>
<p>Here&#8217;s the respective extension class:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">class</font> <font color="#008080">XmlHelper</font><br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#008080">XmlElement</font> NewElement(<font color="#0000ff">this</font> <font color="#008080">XmlDocument</font> parent, <font color="#0000ff">string</font> name)<br />
    {<br />
        <font color="#008080">XmlElement</font> e = parent.CreateElement(name);<br />
        parent.AppendChild(e);<br />
        <font color="#0000ff">return</font> e;<br />
    }<br />
   <br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#008080">XmlElement</font> NewElement(<font color="#0000ff">this</font> <font color="#008080">XmlElement</font> parent, <font color="#0000ff">string</font> name)<br />
    {<br />
        <font color="#008080">XmlElement</font> e = parent.OwnerDocument.CreateElement(name);<br />
        parent.AppendChild(e);<br />
        <font color="#0000ff">return</font> e;<br />
    }<br />
   <br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#008080">XmlElement</font> SetAttrib(<font color="#0000ff">this</font> <font color="#008080">XmlElement</font> element, <font color="#0000ff">string</font> name, <font color="#0000ff">string</font> <font color="#0000ff">value</font>)<br />
    {<br />
        element.SetAttribute(name, <font color="#0000ff">value</font>);<br />
        <font color="#0000ff">return</font> element;<br />
    }<br />
   <br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#008080">XmlElement</font> Parent(<font color="#0000ff">this</font> <font color="#008080">XmlElement</font> element)<br />
    {<br />
        <font color="#0000ff">return</font> (<font color="#008080">XmlElement</font>)element.ParentNode;<br />
    }<br />
}</p></blockquote>
<p>See how every method but one on one hand extends <em>XmlElement</em> and at the same time returns an <em>XmlElement</em>? This could probably be extended to <em>XmlAttribute </em>and other related classes. As long as I can build a chain of returned type used as subsequently extended type the fluent interface idea should work.</p>
<p><strong>But I never liked fluent interfaces&#8230;</strong></p>
<p>Fluent interfaces have been coined by Marin Fowler <a target="_blank" href="http://martinfowler.com/bliki/FluentInterface.html">in his blog</a>, december 2005, more information on the term may be found at <a target="_blank" href="http://en.wikipedia.org/wiki/Fluent_interface">wikipedia</a>. He did however no exactly invent the idea, he merely was taking an C++ idiom a little further. I remember having returned <em>*this </em>in C++ in the 90s, and <em>I </em>certainly did <em>not </em>invent it then.</p>
<p>However, I also grew very wary of this idiom, and with C# I became an advocate against &#8220;call chains&#8221; (where every return value is instantly used to call the next method) in general, and fluent interfaces in particular. For just one simple reason: <em>NullReferenceException</em>. If one appeared, who could tell which particular call was the culprit, and why. With single calls, each in its own source line, you do know from the call stack and debug information which call failed. And running in a debugger you instantly had the temporary variables to tell you the current state of affairs.</p>
<p>Thus I concluded that fluent interfaces lack robustness. Then came LINQ.</p>
<p>This example is <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/bb308959.aspx">taken from an early introduction</a> by none other than Don Box and Anders Hejlsberg:</p>
<blockquote><p>IEnumerable&lt;string&gt; query = from s in names where s.Length == 5 orderby s select s.ToUpper();</p>
<p>translates to:</p>
<p>IEnumerable&lt;string&gt; query = names.Where(s =&gt; s.Length == 5).OrderBy(s =&gt; s).Select(s =&gt; s.ToUpper());</p></blockquote>
<p>If that is not what I call a &#8220;call chain&#8221;, I don&#8217;t know what is. And it certainly is a very nice application of fluent interfaces. Thus it should be subject to the concerns I had. It is not. And not just because I wouldn&#8217;t dare to contradict Don or Anders (oh boy, I would have a field day if I could do <em>that</em>).</p>
<p>The reason I have no problem with LINQ is that it does not only employ fluent interface programming style, it is also backed up by <a target="_blank" href="http://en.wikipedia.org/wiki/Functional_programming">functional programming</a> concepts. And functional programming demands that methods do not return <em>NULL</em> values, but <a target="_blank" href="http://en.wikipedia.org/wiki/Null_Object_pattern">null objects</a>. (Ironically we had that back in the old C++ days, as C++ references are not supposed to be null in the first place, contrary to pointers.)</p>
<p>Apart from this theoretical justification, extension methods are static methods that can check the &#8220;this&#8221; reference and throw <em>ArgumentException</em>s that tell exactly what call was wrong. Something that is not possible with instance methods.</p>
<p>So, if you spice fluent interfaces up with some functional pepper, they become a very digestible meal.</p>
<p><strong>Wrap up</strong></p>
<p>Fluent interfaces provide a compelling concept that has been used in isolated spots, such as with <em><a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.text.stringbuilder.aspx">StringBuilder</a></em>. With LINQ it is also backed up with functional programming concepts and in turn becomes a more broadly usable concept. While LINQ itself is a great example of the employment of fluent interfaces, extension methods can be used to implement fluent interfaces in more general cases.</p>
<blockquote><p>Does that mean I need extension methods to implement fluent interfaces? It does not! When I had already written much of this post I stumbled over &#8220;<a target="_blank" href="http://www.improve.dk/blog/2007/10/20/xmldocument-fluent-interface">XmlDocument fluent interface</a>&#8220;. Marks approach was a little different. Rather than extending the existing <em>XmlElement </em>class, he returned his own tool class. This way he could avoid the naming collisions and restrict the callable methods to just the fluent interface and nothing else. And he does <em>not </em>use extension methods.</p></blockquote>
<p>My example shouldn&#8217;t be taken too literally, as it was only meant to highlight the concept, not to provide a robust implementation. It should at least have shown that fluent interfaces are a feasibly thing to do with extension methods. In many cases, all it takes is &#8220;return x;&#8221; Without extension methods, this would not have been possible.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f03%2f21%2fusing-extension-methods-for-fluent-interfaces%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f03%2f21%2fusing-extension-methods-for-fluent-interfaces%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/155/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/155/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/155/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=155&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/03/21/using-extension-methods-for-fluent-interfaces/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f03%2f21%2fusing-extension-methods-for-fluent-interfaces%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Using extension methods for decomposition</title>
		<link>http://ajdotnet.wordpress.com/2008/03/16/using-extension-methods-for-decomposition/</link>
		<comments>http://ajdotnet.wordpress.com/2008/03/16/using-extension-methods-for-decomposition/#comments</comments>
		<pubDate>Sun, 16 Mar 2008 10:18:32 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=154</guid>
		<description><![CDATA[My last post dug into some technical details of extension methods. Now I&#8217;ll have a look at what extension methods can do for me; more to the point, whether extension methods may support new patterns or idioms. Occasional hints in other blogs and articles as well as my own findings revealed two general patterns: Using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=154&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My <a href="http://ajdotnet.wordpress.com/2008/02/10/extensively-using-extension-methods/">last post</a> dug into some technical details of extension methods. Now I&#8217;ll have a look at what extension methods can do for me; more to the point, whether extension methods may support new patterns or idioms. Occasional hints in other blogs and articles as well as my own findings revealed two general patterns:</p>
<ul>
<li>Using extension methods for decomposition or separation</li>
<li>Using extension methods to support fluent interfaces</li>
</ul>
<p>I&#8217;ll start with the first one because I think it may address a variety of issues and ideas. Fluent interfaces will be covered in another post.</p>
<p>Let&#8217;s go through some use cases.</p>
<p><strong>Interface based coding</strong></p>
<p>Did you ever sort a collection? What method did you use? <em>Array.Sort()</em>? <em>List.Sort()</em>? Why not <em>IList.Sort()</em>? Because there is no <em>IList.Sort()</em>!</p>
<p>One may argue that Microsoft simply forgot to put <em>Sort() </em>into the <em>IList</em> interface or to provide an <em>ISortedList </em>interface. But what about <em>Project()</em>, <em>RemoveInvalidValues(), Normalize()</em>? Matter of fact, it is simply not possible to foresee every demand and not feasibly to put it into general purpose interfaces.</p>
<p>The price to pay is that implementing sorting in the list classes sacrifices interface based abstraction and binds the calling code unnecessarily to implementation classes. But what other options did we have anyway?</p>
<p>The sorting algorithm could easily be implemented <u>working on</u> <em>IList</em>, independent of the implementation class. Yet the method would have to be put somewhere, usually in some helper class (like <em>ListHelper.Sort(IList)</em>). Microsoft did not do that because it violates ease of use principles outlined in &#8220;<a target="_blank" href="http://www.amazon.com/Framework-Design-Guidelines-Conventions-Development/dp/0321246756/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1204467845&amp;sr=8-1">Framework Design Guidelines</a>&#8221; (indeed a very valid reason).</p>
<p>However, since .NET 3.5 we can easily solve that problem by declaring our static <em>Sort </em>method as extension method, making it appear as if it is a method of the interface:</p>
<blockquote><p><font color="#0000ff">void</font> ListHelper.Sort(<font color="#0000ff">this</font> IList) {&#8230;}</p></blockquote>
<p>OK, one step back! Doesn&#8217;t that violate OO principles? Shouldn&#8217;t the the list be able to sort itself? Just like a deck of cards? Well, last time I played cards <em>I </em>had to sort &#8230; I mean <em>shuffle </em>them. Sorting and shuffling are algorithms <u>working on</u><em> </em>lists, not intrinsic features of said lists.</p>
<p>Thus we have a possible idiom:</p>
<ol>
<li>Provide interfaces that describe core characteristics of data structures (such as <em>IEnumerable</em>, <em>IList</em>, <em>ISerializable</em>, &#8230;).</li>
<li>Put methods that implement algorithms <u>working on</u> core characteristics in extension classes for the respective interface.</li>
</ol>
<p>This helps keeping interfaces straight, and it improves reuse of algorithms.</p>
<p><strong>Segregate context specific service methods</strong></p>
<p>Take an entity class, say <em>Address</em>. There are certain things one could do with an address, e.g. provide a formatted string for printing, checking if it is a valid address, and so on. I said &#8220;do with&#8221; not &#8220;do to&#8221;; again I&#8217;m talking about algorithms <u>working on</u><em> </em>the address, rather than manipulating it. And they don&#8217;t need access to the inner workings of the object.</p>
<p>Still we could implement the methods within the address class; the motivation for the previous pattern was reuse of the algorithm, but how many addresses are we going to have?</p>
<p>So let&#8217;s put the <em>Validate() </em>method (used by the business logic) into the entity, the <em>FormatForPrinting() </em>Method (used by the UI), the <em>GenerateUniqueId() </em>Method (used by the data access layer), &#8230; damn, that format method produced HTML but this client needs XAML&#8230; . And is this <em>IsReadOnly()</em> method for the UI or the data access layer?<br />
Got the idea? There <em>is </em>reason <u>not</u><em> </em>to put those methods into the entity class: they do not only depend on the entity but also belong to their specific context, in this case a certain layer.</p>
<p>Putting those methods into a helper class could have been done before, but again, how many helper classes shall we have to remember? Extension methods can solve that particular problem.</p>
<p>So, I have another idiom:</p>
<ol>
<li>Keep context dependent methods out of classes which are used in different contexts.</li>
<li>Put those context specific methods into context specific extension classes.</li>
</ol>
<p>Doing this, the entity class stays clean and pure, no undue features, no pesky helper methods, only nice little properties.</p>
<p><strong>Separation of core implementation and service methods</strong></p>
<p>Take one of my favorite classes, a <a href="http://ajdotnet.wordpress.com/2007/04/21/building-the-factory/">factory class</a>. It probably provides a <em>CreateObject(&#8230;)</em> method taking certain parameters that does the main job of creating objects. Of course it would take the maximum of available parameters, and of course it would have certain overloads to make things easier to use:</p>
<blockquote><p><font color="#0000ff">object</font> CreateObject(Type type, <font color="#0000ff">params</font> <font color="#0000ff">object</font>[] args);<br />
<font color="#008000">// Service methods:</font><br />
T CreateObject&lt;T&gt;(<font color="#0000ff">params</font> <font color="#0000ff">object</font>[] args);<br />
<font color="#0000ff">object</font> CreateObject(Type type);<br />
T CreateObject&lt;T&gt;();<br />
<font color="#0000ff">object</font> CreateObject(<font color="#0000ff">string</font> typeName, <font color="#0000ff">params</font> <font color="#0000ff">object</font>[] args);<br />
<font color="#0000ff">object</font> CreateObject(<font color="#0000ff">string</font> typeName);<br />
&#8230;</p></blockquote>
<p>I wouldn&#8217;t have problems to further add type safe overloads. What&#8217;s the result? While there is just one relevant method, a bunch of additional method complicates the class, broadens its surface, needs to be tested, may do things a little differently&#8230; and at the end the overload I just needed would still be missing.</p>
<p>Extension methods solve this problem in two aspects: First they allow moving the convenience methods out of the factory class without sacrificing the usability from the callers point of view. Secondly, I can add my special incarnation of a <em>CreateObject </em>method in my private extension class and it would seamlessly appear beside (or even replace) all the other methods.</p>
<p>So, I have another idiom:</p>
<ol>
<li>Keep the implementation of classes to the core functionality.</li>
<li>Put additional convenience methods into extension classes.</li>
</ol>
<p><strong>Mixin classes</strong></p>
<p>The idea of using extension methods for mixins was introduced with <a target="_blank" href="http://msdn2.microsoft.com/en-us/vcsharp/bb625996.aspx">Create Mixins with Interfaces and Extension Methods</a>. This article uses extension methods working on a special interface, the combination of them forming the mixin. A class that needs some orthogonal functionality would simply implement that interface and benefit from the provided implementation.</p>
<p>The idiom described looks like:</p>
<p>If you have an algorithm or feature you want to apply in an egalitarian way to different classes&#8230;</p>
<ol>
<li>use an interface to provide uniform access to the classes&#8230;</li>
<li>and provide the algorithm as extension method to that interface.</li>
</ol>
<p>I may have seen those two points before&#8230;?!</p>
<blockquote><p>As a side note: Wikipedia defines mixins as follows:</p>
<p>&#8220;[...] a <b>mixin</b> is a <a target="_blank" href="http://en.wikipedia.org/wiki/Class_%28computer_science%29">class</a> that provides a certain functionality to be <a target="_blank" href="http://en.wikipedia.org/wiki/Inheritance_%28computer_science%29">inherited</a> by a subclass, but is not meant to stand alone. Inheriting from a mixin is not a form of specialization but is rather a means to collect functionality.&#8221; <a href="http://en.wikipedia.org/wiki/Mixin" title="http://en.wikipedia.org/wiki/Mixin">http://en.wikipedia.org/wiki/Mixin</a></p>
<p>Seen from a C++ point of view, the mixin approach relies on several tenets: Based on inheritance of functionality, the mixin class is a fully fledged class that provides actual code (as opposed to interfaces). This quite often included code placed in constructors and the destructor, thus implicitly adding behavior. At the same time, the reuse by inheritance approach does not interfere with the regular inheritance hierarchy, as C++ supports multiple inheritance. And it also does not interfere with the interface of the class (i.e. it can be realized that way in case it is undesired), as C++ allows protected and private inheritance.</p>
<p>Of course this is not possible with .NET, as multiple inheritance is restricted to interfaces and always public. Thus I am inclined to call the mentioned approach a very poor realization of mixins. It falls short of covering any aspect I used mixins for with C++: I don&#8217;t inherit functionality, say by providing default implementations. I don&#8217;t add behavior, as no logic is changed until I explicitly call the extension method. And I cannot even dream of making this an implementation detail of the class, as it solely relies on changing the public interface of that class.</p></blockquote>
<p><strong>Putting things together&#8230;</strong></p>
<p>These usage scenarios may have provided different motivations, but in essence they have followed the same ideas and led to similar idioms. In a more generalized form:</p>
<ol>
<li>Keep methods out of your class or interface &#8230;
<ul>
<li>if they implement algorithms <u>working on</u> the class rather than <u>features of</u><em> </em>the class</li>
<li>if they depend not only on the class/interface, but also on the context</li>
<li>if they merely add convenience overloads</li>
<li>if they would not have been available in the first place</li>
</ul>
</li>
<li>Provide extension classes &#8230;
<ul>
<li>that capture algorithms working on objects and especially implementations working on interfaces</li>
<li>that cluster context specific features</li>
<li>that add shortcuts, convenience methods, and helper methods.</li>
</ul>
</li>
</ol>
<p>Now, all this could have been done before with static helper classes. And having extension methods at our disposal doesn&#8217;t change the work on the providers side at all. The big difference however is at the users side. While the classes he works with remain simpler and more concise at first glance, just by adding a using statement he can dynamically enhance those classes with exactly the bunch of features he just needs. This is almost like dynamically extending class definitions in dynamic languages.</p>
<p>Putting it together, this has (or rather may have) several effects:</p>
<ul>
<li>It supports the information hiding principle for <a target="_blank" href="http://en.wikipedia.org/wiki/Abstract_data_type">abstract data types</a> as only the absolutely necessary methods get access to the inner workings.</li>
<li>It elevates <a target="_blank" href="http://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a> as classes and algorithms are separated.</li>
<li>It improves <a target="_blank" href="http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29">cohesion</a> as context dependent features are moved to their respective context.</li>
<li>Reusability should improve if the extension methods can be implemented to work against interfaces and thus become more applicable.</li>
<li>Testing those algorithms should improve as those interfaces may also be implemented by <a target="_blank" href="http://en.wikipedia.org/wiki/Mock_object">mock objects</a>.</li>
<li>Testing the classes will be easier due to the smaller and more concise surface to test.</li>
<li>And finally classes and interfaces that have a smaller surface are less complex and easier to keep consistent.</li>
</ul>
<p>If you ask me, I didn&#8217;t expect such a compelling list of benefits when I started locking into this topic. Whether they may be realized remains to be seen, but after having worked on this post, I am willing to give it a try.</p>
<p>That is, as long as nobody points out any flaws I overlooked. (OK guys, that&#8217;s a challenge!)</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f03%2f16%2fusing-extension-methods-for-decomposition%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f03%2f16%2fusing-extension-methods-for-decomposition%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/154/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/154/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/154/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=154&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/03/16/using-extension-methods-for-decomposition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f03%2f16%2fusing-extension-methods-for-decomposition%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Extensively using extension methods</title>
		<link>http://ajdotnet.wordpress.com/2008/02/10/extensively-using-extension-methods/</link>
		<comments>http://ajdotnet.wordpress.com/2008/02/10/extensively-using-extension-methods/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 13:00:39 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=153</guid>
		<description><![CDATA[What was meant as a single post now seems to become another little series: I have started looking at the new C# language features (introduced with/for LINQ) in isolation, trying to assess whether they can live up to being features in their own right. I have covered partial methods (strictly speaking not a LINQ related [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=153&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>What was meant as a <a href="http://ajdotnet.wordpress.com/2007/09/04/partial-methods-for-partial-developers/">single post</a> now seems to become another little series: I have started looking at the new C# language features (introduced with/for LINQ) in isolation, trying to assess whether they can live up to being features in their own right.</p>
<p>I have covered <a href="http://ajdotnet.wordpress.com/2007/09/04/partial-methods-for-partial-developers/">partial methods</a> (strictly speaking not a LINQ related feature). <a target="_blank" href="http://anastasiosyal.com">Anastasios</a> has written a blog post about <a target="_blank" href="http://www.anastasiosyal.com/archive/2007/11/27/C-3.0-Anonymous-type-support-is-incomplete.aspx">anonymous types</a>, so I&#8217;ll cover that aspect simply by referral.</p>
<p><strong>Now for extension methods&#8230;</strong></p>
<p>If you need a recap on extension methods, those links might suit you:</p>
<ul>
<li>Scott Guthrie&#8217;s <a target="_blank" href="http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx">introduction</a> focuses on extension methods in the context of LINQ</li>
<li><a target="_blank" href="http://blogs.msdn.com/sreekarc/archive/2007/04/25/extension-methods.aspx">Extension methods in C#</a> is a blog post from the very guy that built extension methods into the compiler. He looks at them on a very low level.</li>
<li>Always the reference: The <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms364047(vs.80).aspx#cs3spec_topic3">C# language specification</a>.</li>
</ul>
<p>Now let&#8217;s look at a few characteristics and consequences; nothing special, most of it should be obvious anyway.</p>
<p><strong>Basic usage</strong></p>
<p>Example: Check if an array is empty&#8230;</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">class</font> ArrayExtensions<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">bool</font> IsEmpty(<font color="#0000ff">this</font> Array array)<br />
    {<br />
        <font color="#0000ff">return</font> (array==<font color="#0000ff">null</font>) || (array.Length==0);<br />
    }<br />
}</p></blockquote>
<p>Now look at this code using the extension method:</p>
<blockquote><p><font color="#0000ff">int</font>[] ia = <font color="#0000ff">new</font> <font color="#0000ff">int</font>[] { 1, 2, 3 };<br />
<font color="#0000ff">if</font> (ia.IsEmpty())<br />
    Console.WriteLine(<font color="#800000">&#8220;ia is empty&#8221;</font>);</p></blockquote>
<p>The thing to note is that a property <em>IsEmpty</em> would be so much nicer. Alas, extension methods &#8212; at least in the current implementation &#8212; are limited to plain instance methods.</p>
<p>Let&#8217;s stress that:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">class</font> ArrayExtensions<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">int</font>[] CreateNumbers(<font color="#0000ff">this</font> Array array, <font color="#0000ff">int</font> start, <font color="#0000ff">int</font> end)<br />
    {<br />
        <font color="#0000ff">return</font> <font color="#0000ff">new</font> <font color="#0000ff">int</font>[] { start, end }; <font color="#008000"><i>// if you find that peculiar, you&#8217;re right <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </i></font><br />
    }<br />
}</p></blockquote>
<p>This is a factory method, a method that <em>creates </em>an instance. It would be so nice to call it on the type, e.g.</p>
<blockquote><p><font color="#0000ff">int</font>[] ib = (<font color="#0000ff">int</font>[]).CreateNumbers(1, 5);</p></blockquote>
<p>And yet, this would require static extension methods. Something that has been discussed in a <a target="_blank" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2046738&amp;SiteID=1">forum thread</a>, well, <em>rebuffed</em> would be a better description&#8230; <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  .<em> I also could find uses for &#8220;extension const values&#8221; but there&#8217;s no sense in starting </em>that <em>discussion. </em></p>
<p>Another piece of code calling into extension methods:</p>
<blockquote><p><font color="#0000ff">int</font>[] ic = <font color="#0000ff">null</font>;<br />
<font color="#0000ff">if</font> (ic.IsEmpty())<br />
    Console.WriteLine(<font color="#800000">&#8220;ic is empty&#8221;</font>);<br />
<font color="#0000ff">if</font> (ArrayExtensions.IsEmpty(ic))<br />
    Console.WriteLine(<font color="#800000">&#8220;ic is empty&#8221;</font>);</p></blockquote>
<p>There are a few things to point out:</p>
<ul>
<li>Look at the second line in the above code. This code runs nicely, no <em>NullReferenceException</em>! Despite the fact that extension methods are called via instances, the &#8220;this&#8221; argument may still be <em>null </em>and the extension method should make sure it can handle that (thus the <em>array==null </em>check above).</li>
<li>Look again at the second line. Partly a consequence of the previous point, there is no way to know whether <em>IsEmpty()</em> is a call to an ordinary instance method (which would certainly throw an exception) or to an extension method (which would not). Thus you also cannot decide whether this is an erroneous code fragment or not.</li>
<li>Now look at the second &#8220;if&#8221; statement. It still is possible to call extension methods like you would with ordinary static helper methods.</li>
</ul>
<p>What I make out of these findings is that instance methods and extension methods may look the same at the calling code fragment, yet there is a semantic difference (i.e. different behavior at runtime) one should be be aware of. And the fact that this difference is not apparent in the calling code somewhat blurs the code if you look at it from a reviewers point of view.</p>
<p><strong>Ambiguity</strong></p>
<p>Let&#8217;s count some numbers:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">class</font> ArrayExtensions<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">int</font> GetSafeCount(<font color="#0000ff">this</font> Array array)<br />
    {<br />
        <font color="#008000"><i>// allways check null value!</i></font><br />
        <font color="#0000ff">return</font> (array == <font color="#0000ff">null</font>) ? 0 : array.Length;<br />
    }<br />
}</p>
<p><font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">class</font> CollectionExtensions<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">int</font> GetSafeCount&lt;T&gt;(<font color="#0000ff">this</font> ICollection&lt;T&gt; col)<br />
    {<br />
        <font color="#008000"><i>// allways check null value!</i></font><br />
        <font color="#0000ff">return</font> (col == <font color="#0000ff">null</font>) ? 0 : col.Count;<br />
    }<br />
}</p></blockquote>
<p>Suppose you import the first class, then you write the following code:</p>
<blockquote><p><font color="#0000ff">if</font> (ia.GetSafeCount() == 0)<br />
    Console.WriteLine(<font color="#800000">&#8220;ia is empty&#8221;</font>);</p></blockquote>
<p>After you import the second class, the compiler will greet you with the following message:</p>
<blockquote><p>D:\&#8230;\BasicTests.cs(68,17): error CS0121: The call is ambiguous between the following methods or properties: &#8216;Extensions.ArrayExtensions.GetSafeCount(System.Array)&#8217; and &#8216;Extensions.CollectionExtensions.GetSafeCount&lt;int&gt;(System.Collections.Generic.ICollection&lt;int&gt;)&#8217;</p></blockquote>
<p>The bad message is: Just by importing another namespace you add an ambiguity. This is nothing new, if you happened to code against <em>Control </em>with <em>using System.Web.UI;</em> and you added <em>using System.Windows.Forms;</em> you would run into the same problem. With two notable differences: One, this ambiguity is on class level, not on method level. Two, you could circumvent it with a <em>using WebControl = System.Web.UI.Control; </em>directive. This is not possible with extension methods.</p>
<p>The good part is that the compiler will whine until you made your intentions clear. Or does it? Look at this:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> Test1<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">void</font> Foo()<br />
    {<br />
        <font color="#0000ff">this</font>.Test();<br />
    }<br />
}</p>
<p><font color="#0000ff">public</font> <font color="#0000ff">class</font> Test2 : Test1<br />
{<br />
}</p>
<p><font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">class</font> TestExtensions<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">void</font> Test(<font color="#0000ff">this</font> Test1 test)<br />
    {<br />
        Console.WriteLine(<font color="#800000">&#8220;Test 1 called!&#8221;</font>);<br />
    }<br />
}</p></blockquote>
<p>One class derived from another, an extension method for the base class. This is valid code and of course it calls the extension method:</p>
<blockquote><p><font color="#0000ff">Test2</font> t2 = <font color="#0000ff">null</font>;<br />
t2.Test();</p></blockquote>
<p>Now import another extension method:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">void</font> Test(<font color="#0000ff">this</font> Test2 test)<br />
{<br />
    Console.WriteLine(<font color="#800000">&#8220;Test 2 called!&#8221;</font>);<br />
}</p></blockquote>
<p>Guess what? For the call to <em>Test()</em> in the above example intellisense will show both methods &#8212; without any way to distinguish them. And the compiler will <u>not</u> complain, yet at runtime the new extension method will be called, because the type matches better. Thus, by simply adding a using directive you have changed the semantics of your code radically, calling different methods and perhaps not even noticing it.</p>
<p>BTW: In case you wonder what the <em>Foo()</em> method in <em>Test1</em> is for: I just wanted to stress the fact that a class can call extension methods aimed at itself. All it needs to do is invoke them via the <em>this</em> pointer.</p>
<p><strong>Importing extension methods</strong></p>
<p>I already talked a little about importing extension methods. But there&#8217;s something that should be made very clear:</p>
<p>You don&#8217;t import <em>some </em>extension methods. You don&#8217;t import <em>some </em>classes holding extension methods. You import <em>all </em>extensions methods in <em>all </em>classes in a particular namespace.</p>
<p>Lemma 1: It is not possible to import single extension methods.<br />
Lemma 2: It is not possible to import a single class carrying extension methods. In other words, the following using directive does <em>not </em>import the extension methods in that particular class:</p>
<blockquote><p><font color="#008000"><i>// introducing only one particular class&#8217;s extensions won&#8217;t work</i></font><br />
<font color="#0000ff">using</font> ImportExtensions = Extensions.ArrayExtensions;<br />
<font color="#008000"><i>// we have to introduce all extension methods in all classes in that namespace</i></font><br />
<font color="#0000ff">using</font> Extensions;</p></blockquote>
<p>Lemma 3: It is not possible to import a namespace without importing the extension methods as well.</p>
<p>As a consequence it may be wise to keep extension classes in separate namespaces. More to the point, don&#8217;t put extension methods for common classes (such as <em>Object</em>, <em>String</em>, or <em>Control</em>) in commonly used namespaces. It may even be a good idea &#8212; considering that the class containing the extension methods is of less meaning than usually &#8212; to put extension methods for certain purposes in distinct namespaces, i.e. use the last namespace part in a way you would normally use a class.</p>
<p><strong>Reflection</strong></p>
<p>The obvious part regarding reflection is that the class being extended does no know anything about the extension methods. Calling <em>typeof(MyClass).GetMethods()</em> will always return the same result, always excluding the extension methods. So it serves one to think about extension methods as a pure compiler feature that never makes it to IL.</p>
<p>This is however only partly true and only part of the truth&#8230;</p>
<p>First the truth: The calling IL code is identical for extension method calls and simple static method calls:</p>
<blockquote><p>L_<font color="#000000">006b: </font><font color="#000000">call</font><font color="#000000"> bool Extensions.ArrayExtensions::IsEmpty(class [mscorlib]System.Array) </font></p>
<p><font color="#000000">L_0085: </font><font color="#000000">call</font><font color="#000000"> bool Extensions.ArrayExtensions::IsEmptyNonExt(class [mscorlib]System.Array)</font></p></blockquote>
<p>Now the untrue part: There actually is some difference, otherwise <a target="_blank" href="http://www.aisto.com/roeder/dotnet/">Reflector</a> would not be able to decompile the following fragment:</p>
<blockquote><p><font color="#0000ff">if</font> (ic.IsEmpty())<br />
    Console.WriteLine(<font color="#800000">&#8220;ic is empty&#8221;</font>);<br />
<font color="#0000ff">if</font> (ic.IsEmpty())<br />
    Console.WriteLine(<font color="#800000">&#8220;ic is empty&#8221;</font>);<br />
<font color="#0000ff">if</font> (ArrayExtensions.IsEmptyNonExt(ic))<br />
    Console.WriteLine(<font color="#800000">&#8220;ic is empty&#8221;</font>);</p></blockquote>
<p>So there has to be some information about extension methods in the IL code; however not at the calling side, for otherwise Reflector would have presented the second call correctly as the plan static call that was in the original code.</p>
<p>The answer lies in the missing part: The extension method itself is marked as such, using an attribute. This is the IL (as Reflector shows it):</p>
<blockquote>
<pre>.method public hidebysig static bool <b>IsEmpty</b>(class [mscorlib]System.Array array) cil managed
{
    .custom instance void [System.Core]System.Runtime.CompilerServices.ExtensionAttribute::.ctor()
    .custom instance void [mscorlib]System.Diagnostics.DebuggerStepThroughAttribute::.ctor()
    .maxstack 2</pre>
</blockquote>
<p>I put the <em>DebuggerStepThroughAttribute </em>in for a reason. The same method presented by Reflector as C# code looks like this:</p>
<blockquote>
<pre>[DebuggerStepThrough]
public static bool <b>IsEmpty</b>(this Array array)</pre>
</blockquote>
<pre></pre>
<p>As you can see, Reflector silently replaces the <em>ExtensionAttribute </em>with the <em>this </em>keyword.</p>
<p>There is another interesting thing about the attribute. If you look it up in the documentation it states the usual &#8220;This API supports the .NET Framework infrastructure and is not intended&#8230;&#8221;, but it also tells us that it targets not only methods, but classes and assemblies likewise. Consequently my test class contains the attribute (again, only visible in IL view in Reflector):</p>
<blockquote>
<pre>.class public abstract auto ansi sealed beforefieldinit <b>ArrayExtensions</b>
    extends [mscorlib]System.Object
{
    .custom instance void [System.Core]System.Runtime.CompilerServices.ExtensionAttribute::.ctor()</pre>
</blockquote>
<p>As well as the assembly (and hey! this time in C# view):</p>
<blockquote>
<pre>// Assembly <b>ConsoleApplication1</b>, Version 1.0.0.0    

[assembly: Extension]</pre>
</blockquote>
<p>Best guess is that this is for faster lookup of extension methods (or rather ruling their presence out).</p>
<p><strong>LINQ</strong></p>
<p>I guess I cannot avoid to talking about the relationship between LINQ and extension methods. Have a look at that code:</p>
<blockquote><p><font color="#0000ff">int</font>[] ia = <font color="#0000ff">new</font> <font color="#0000ff">int</font>[] { 1, 2, 3 };<br />
<font color="#0000ff">var </font>result = <font color="#0000ff">from</font> num <font color="#0000ff">in</font> ia <font color="#0000ff">where</font> num &lt; 2 <font color="#0000ff">select</font> num;</p></blockquote>
<p>In a sense LINQ is all about translating <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/bb310804.aspx">query keywords</a> into &#8220;lower level&#8221; language features. Reflector presents the relevant part of this code as follows:</p>
<blockquote><p>CS$&lt;&gt;9__<font color="#000000">CachedAnonymousMethodDelegate1 = delegate (int num) { return </font><font color="#000000">num</font><font color="#000000"> &lt; 2; };<br />
IEnumerable&lt;int&gt; <b>result</b> = </font><font color="#000000">ia</font><font color="#000000">.Where&lt;int&gt;(CS$&lt;&gt;9__CachedAnonymousMethodDelegate1);</font></p></blockquote>
<p>As you can see, the <em>where</em> keyword is translated to a call to the extension method <em>Where</em> (declared in <em>System.Linq.Enumerable</em>).<br />
(<em>Note: If you look at that method in Reflector it appears to be empty, just like all extension methods in that class. I&#8217;ll leave that riddle to someone else&#8230;) </em></p>
<p><strong>Verdict</strong></p>
<p>Extension methods are no doubt an interesting new language feature. They have their pitfalls, but which feature does not. My main concern is that the IDE doesn&#8217;t tell me which extension method I&#8217;m calling. Tooltips as well as Intellisense tell me a method <em>is</em> an extension method, but not <em>in which namespace/class</em> it resides.</p>
<p>On the other hand it&#8217;s quite obvious that extension methods are not there as a feature in its own right but as a means to support LINQ. It actually does support LINQ very well &#8212; but it does not go beyond. Had it been otherwise, there would be means to at least some of those areas in which class extension methods currently fall short:</p>
<ul>
<li>Extension properties</li>
<li>Static extension methods</li>
<li>Better ways for controlling the import of extension methods (e.g. import classes rather than namespaces)</li>
</ul>
<p>OK, that&#8217;s it. Seems I&#8217;m not capable of writing short posts&#8230;</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f02%2f10%2fextensively-using-extension-methods%2f"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f02%2f10%2fextensively-using-extension-methods%2f" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/153/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/153/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/153/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=153&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/02/10/extensively-using-extension-methods/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f02%2f10%2fextensively-using-extension-methods%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Get your hands on the .NET source code&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2008/02/08/get-your-hands-on-the-net-source-code/</link>
		<comments>http://ajdotnet.wordpress.com/2008/02/08/get-your-hands-on-the-net-source-code/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 07:16:13 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/?p=152</guid>
		<description><![CDATA[Now this is worth mentioning: John Robbins (a.k.a. Mr. Debugger ) has provided what Microsoft only promised, but did not yet deliver: A standalone full download of the .NET Framework source code: Download All the .NET Reference Source Code at Once with Net Mass Downloader .NET Mass Downloader 1.1 Released And he even described how [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=152&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Now this is worth mentioning:</p>
<p>John Robbins (a.k.a. Mr. Debugger <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ) has provided what Microsoft only <a target="_blank" href="http://weblogs.asp.net/scottgu/archive/2007/10/03/releasing-the-source-code-for-the-net-framework-libraries.aspx">promised</a>, but <a target="_blank" href="http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now-available.aspx">did not yet deliver</a>: A standalone full download of the .NET Framework source code:</p>
<ul>
<li>
<div><a target="_blank" href="http://www.wintellect.com/cs/blogs/jrobbins/archive/2008/02/06/download-all-the-net-reference-source-code-at-once-with-net-mass-downloader.aspx">Download All the .NET Reference Source Code at Once with Net Mass Downloader</a></div>
</li>
<li>
<div><a target="_blank" href="http://www.wintellect.com/cs/blogs/jrobbins/archive/2008/02/07/net-mass-downloader-1-1-released.aspx">.NET Mass Downloader 1.1 Released</a></div>
</li>
</ul>
<p>And he even described how to use that source code with <strong>Visual Studio <em>2005</em></strong>!</p>
<p>A word of warning though: My first attempt do download John&#8217;s tool resulted in &#8220;Server is too busy&#8221;. So hurry up, there&#8217;s other people already lined up and the downloads may run out of stock <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/152/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/152/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/152/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=152&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/02/08/get-your-hands-on-the-net-source-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Command line tool vs. PowerShell Cmdlet</title>
		<link>http://ajdotnet.wordpress.com/2008/01/19/command-line-tool-vs-powershell-cmdlet/</link>
		<comments>http://ajdotnet.wordpress.com/2008/01/19/command-line-tool-vs-powershell-cmdlet/#comments</comments>
		<pubDate>Sat, 19 Jan 2008 20:03:19 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2008/01/19/command-line-tool-vs-powershell-cmdlet/</guid>
		<description><![CDATA[I&#8217;ve blogged before about the fact that I like command line tools. No quick and dirty no-options hacks, but seriously taken applications. Must be due to the fact that I started in the DOS era. Console applications are powerful, expressive, and above all they can be used to automate tasks. And yet, things have changed. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=151&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve blogged <a href="http://ajdotnet.wordpress.com/2006/08/31/long-live-console-applications/">before</a> about the fact that I like command line tools. No quick and dirty no-options hacks, but seriously taken applications. Must be due to the fact that I started in the DOS era. Console applications are powerful, expressive, and above all they can be used to automate tasks. And yet, things have changed. Batches lack a good deal of features, more powerful shells known from UNIX environments never caught on in the Microsoft world, neither did <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/9bbdkx3k.aspx">Microsoft Script Host</a> (MSH).<br />
Nevertheless there <em>are </em>tools that stepped into the breach, if only for me. <a target="_blank" href="http://en.wikipedia.org/wiki/Apache_Ant">ANT</a>, being intended as successor to <a target="_blank" href="http://en.wikipedia.org/wiki/Make_%28software%29">MAKE</a>, and <a target="_blank" href="http://en.wikipedia.org/wiki/Nant">NANT</a>, today about to be succeeded(?) by <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/wea2sca5.aspx">MSBuild</a> provided the scripting features I looked for. Those tools however lack universal availability and support and had to fall back on command line utilities for special tasks. But now we have <a target="_blank" href="http://en.wikipedia.org/wiki/Powershell">PowerShell</a> that attempts to bring unprecedented scripting support not only to windows, but also (by Microsoft&#8217;s commitment) to be the one shell that shall be universally supported by server software for the automation of administrative tasks.</p>
<blockquote></blockquote>
<blockquote><p>As Bob Muglia (Microsofts Senior Vice President, Windows Server) said <a target="_blank" href="http://www.microsoft.com/presspass/exec/bobmuglia/09-15PDC2005.mspx">on the last PDC</a>: “<em>We are going to undergo a project over the next few years to get a full set of Monad [PowerShell] commands across all of Windows Server, and across all of our server applications. […]</em>“.</p></blockquote>
<p>So it lingered in my mind to check the differences between command line tools development and PowerShell Cmdlets until an MSDN Magazine article (&#8220;<a target="_blank" href="http://msdn.microsoft.com/msdnmag/issues/07/12/PowerShell/default.aspx">Extend Windows PowerShell With Custom Commands</a>&#8220;) gave the final push. My little command line framework was aimed at making 80% of the demands easy and effortless. Would PowerShell complicate matters? Would it provide additional features I missed so far? Would it be feasible to provide both implementations at once? All that was needed was a real world-test scenario&#8230;.</p>
<p>I change the screen resolution of my laptop quite often, depending on whether it&#8217;s balanced on my knees or placed on the desk. I never found a command line tool to do this, so I always had to go through Display Settings. With Vista this became a nuisance (more clicks, another window to close, &#8230;).<br />
So this became my test scenario: A tool to query and change the screen resolution.</p>
<p><strong>Preparation</strong></p>
<p>Since I intended to use the logic in different contexts, I separated it into a respective core assembly right from the start. <a target="_blank" href="http://www.pinvoke.net">www.pinvoke.net</a> told me the details about changing the screen resolution with .NET, MSDN provided the <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms533260.aspx">background</a>. Thus I had the .NET representatives for <em>DEVMODE</em>, <em>ChangeDisplaySettings</em>, and <em>EnumDisplaySettings</em>, as well as a little helper class for standard tasks (like error handling and getting all display settings as a list).</p>
<p>Since I am familiar with it and it defined the reference, I started with the command line version. I&#8217;ll point out the important points and provide code snippets only if necessary. For a quick peek in the console framework usage see my <a href="http://ajdotnet.wordpress.com/2006/08/31/long-live-console-applications/">older post</a>, the full source code is available for download at the end.</p>
<p><strong>Command Line Tool</strong></p>
<p>The following screen shot shows the calls to the command line (CL) tool:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2008/01/displaysettings-cl.jpg"><img border="0" width="680" src="http://ajdotnet.files.wordpress.com/2008/01/displaysettings-cl-thumb.jpg?w=680&#038;h=559" alt="displaysettings_cl" height="559" style="border-width:0;" /></a></p>
<p>Using my framework the implementation was a snap. (It ought to, that&#8217;s what I wrote it for):</p>
<ul>
<li>Provide an application class derived from <em>ConsoleApp</em>.</li>
<li>Override <em>ApplyArguments</em> to get the values for setting the resolution.</li>
<li>Override <em>ApplySwitch</em> to handle /query and /queryall.</li>
<li>Override <em>Process</em> to do the work, i.e. switch on the actual job to do and call the respective helper methods in the core implementation.</li>
<li>Provide methods to output the current screen resolution and the list.</li>
<li>Provide a resource file with logo and help information.</li>
</ul>
<p>Quick and easy, it does the job, and it satisfies my &#8220;quality demands&#8221;.</p>
<p><strong>PowerShell</strong></p>
<p>PowerShell (PS) differs in its philosophy insofar as it demands a separate cmdlet per command, in my case one for setting the resolution, another for querying it. Below is the screen shot for loading the snapin and querying the current resolution:</p>
<p><a href="http://ajdotnet.files.wordpress.com/2008/01/displaysettings-ps.jpg"><img border="0" width="681" src="http://ajdotnet.files.wordpress.com/2008/01/displaysettings-ps-thumb.jpg?w=681&#038;h=560" alt="displaysettings_ps" height="560" style="border-width:0;" /></a></p>
<p>Here is what I had to do to implement the functionality for PS:</p>
<ul>
<li>Provide two different cmdlets, derived from <em>PSCmdlet</em> to declare the parameters and to implement the commands. <em>Quite easy for the </em>get<em>, a bit more to do for </em>set<em>.</em></li>
<li>Provide a format file for the output. <em>Reasonable work and quite flexible.</em></li>
<li>Provide a help file. <em>Ugly work.</em></li>
<li>Provide a snapin class derived from <em>PSSnapIn</em> to satisfy the PS infrastructure and run <em>installutil</em> to announce the snapin. <em>No big deal at all.</em></li>
</ul>
<p>Apart form being installed, one needs to load the snapin into the shell before using it, as denoted in the above screen shot. Here my assessments on the single tasks:</p>
<p><strong><em>get </em>Cmdlet and Format File</strong></p>
<p>This is the sweet spot with one small caveat. Rather than printing information like the command line tool, my cmdlet should follow the PS philosophy and produce objects that will then be printed (but might also be piped to the next cmdlet within a script). The <em>DEVMODE </em>struct did not fit too well with that demand, but a simple wrapper class with just the properties needed did the trick.</p>
<p>After that it only needed one simple class containing a property (the only pitfall being it&#8217;s data type <em>SwitchParameter</em>) to switch between current and all resolutions, plus a <em>ProcessRecord </em>method that cannot be more simple:</p>
<blockquote><p>[Cmdlet(VerbsCommon.Get, <font color="#800000">"DisplaySettings"</font>)]<br />
<font color="#0000ff">public</font> <font color="#0000ff">class</font> GetDisplaySettingsCommand : PSCmdlet<br />
{<br />
    <font color="#0000ff">bool</font> _all;<br />
   <br />
    [Parameter(HelpMessage =<br />
        <font color="#800000">"provide this parameter to show a complete list of available screen settings; "</font> +<br />
        <font color="#800000">"otherwise only the current screen setting is reported."</font>)]<br />
    <font color="#0000ff">public</font> SwitchParameter All<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> _all; }<br />
        <font color="#0000ff">set</font> { _all = (<font color="#0000ff">bool</font>)<font color="#0000ff">value</font>; }<br />
    }<br />
   <br />
    <font color="#0000ff">protected</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> ProcessRecord()<br />
    {<br />
        <font color="#0000ff">if</font> (_all)<br />
        {<br />
            IList&lt;DisplayData&gt; list = Display.GetDisplaySettings();<br />
            <font color="#0000ff">foreach</font> (DisplayData data <font color="#0000ff">in</font> list)<br />
                WriteObject(data);<br />
        }<br />
        <font color="#0000ff">else</font><br />
        {<br />
            DisplayData current = Display.GetCurrentDisplaySettings();<br />
            WriteObject(current);<br />
        }<br />
    }<br />
}</p></blockquote>
<p>While this would have already been enough (note that I didn&#8217;t have to do anything to print the data), adding a format file allowed customization of the output format even using script blocks. Very flexible.</p>
<p>Writing this cmdlet was even more straight forward than writing the CL tool. The later one focuses on keeping similar tasks (like parsing and processing) in one place while the cmdlet keeps related parts together and does a lot more in a declarative fashion.</p>
<p><strong><em>set </em>Cmdlet</strong></p>
<p>Compared to the <em>get </em>cmdlet, the <em>set </em>cmdlet adds some demands for processing. Providing the input parameters is again done using properties adorned with attributes. Validation beyond the provided attributes would require supporting this infrastructure (more effort than what I can do with the CL tool) or plain code in <em>BeginProcessing, </em>which<em> </em>splits the validation. This is especially the case with interdependent property values.</p>
<p>Now for the processing part: While my command line tool simply set the screen resolution, PowerShell <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/cc136129(VS.85).aspx">Cmdlet Development Guidelines</a> demand that system changing operations follow certain rules: They should support the <em>WhatIf</em>, <em>Confirm</em>, and <em>Force </em>properties. This includes calling <em>ShouldProcess </em>and <em>ShouldContinue </em>within <em>ProcessRecord</em>.</p>
<blockquote><p><font color="#0000ff">protected</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> ProcessRecord()<br />
{<br />
    DisplayData data = &#8230; <font color="#ff0000"><em>omitted for brevity, invalid parameters might cause exceptions</em></font><br />
   <br />
    <font color="#008000"><i>// check the -whatif parameter, just return</i></font><br />
    <font color="#0000ff">string</font> msg = <font color="#800000">&#8220;Display settings &#8220;</font> + data.GetDisplayText();<br />
    <font color="#0000ff">if</font> (!ShouldProcess(msg))<br />
        <font color="#0000ff">return</font>;<br />
   <br />
    <font color="#008000"><i>// check the users intention</i></font><br />
    <font color="#0000ff">if</font> (!_force)<br />
    {<br />
        msg = <font color="#800000">&#8220;Set display settings to &#8220;</font> + data.GetDisplayText() + <font color="#800000">&#8220;?&#8221;</font>;<br />
        <font color="#0000ff">if</font> (!ShouldContinue(msg, <font color="#800000">&#8220;Warning!&#8221;</font>))<br />
            <font color="#0000ff">return</font>;<br />
    }<br />
   <br />
    <font color="#008000"><i>// and finally go</i></font><br />
    <font color="#0000ff">string</font> err;<br />
    Display.ChangeSettings(data, <font color="#0000ff">out</font> err);<br />
    <font color="#0000ff">if</font> (err != <font color="#0000ff">null</font>)<br />
    {<br />
        WriteWarning(<font color="#800000">&#8220;Error setting values: &#8220;</font> + err);<br />
    }<br />
    <font color="#0000ff">else</font><br />
    {<br />
        msg = <font color="#800000">&#8220;Display settings set to &#8220;</font> + data.GetDisplayText();<br />
        WriteVerbose(msg);<br />
    }<br />
}</p></blockquote>
<p>While this adds additional &#8220;burden&#8221; on the cmdlet developer, it also ensures a consistent user interface for cmdlets. Not a bad thing as long as cmdlet developers consistently follow these guidelines.</p>
<p><strong>Help Support</strong></p>
<p>The help file (XML of course) has been the area of the biggest hurdles. It&#8217;s complex, highly redundant (with some parts not even used, according to the <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/cc136158(VS.85).aspx">documentation</a>), with an intransparent mixture of leveraged schemas, attributes without expected default values&#8230; . Writing consistent help files is IMO not feasibly doable in all but the most simple examples; rather help files scream for tool support (hear me, anybody?).</p>
<p>In this case I craved for the simplicity of my command line tool. I also have to say that the this complexity is IMO not justified for just having a help command printing out some information. And the documentation also does not explain the motivation for what I can only see as over-engineering. Only if you think of generating help files similar to the MSDN documentation this would be a reason I could understand. But again, I could imagine a help browser with GUI interface, but it has not been mentioned anywhere, much less implemented or announced (AFAIK).</p>
<p><strong>Snapin and Registration</strong></p>
<p>The snapin is simple enough and registering the cmdlets with PS prior to using them is a reasonable demand.</p>
<p><strong>Final Verdict</strong></p>
<p>So, final verdict. Hmm, let&#8217;s see&#8230; CL tool vs. PS cmdlet:</p>
<ul>
<li><strong>Code organization: </strong>The CL tool addresses multiple commands and keeps similar functionality (command line parsing, processing, etc.) together. PS uses one cmdlet per command and keeps the command related stuff together. Different approaches but no technical advantages in general for either; it&#8217;s just a matter of taste.<strong> 0:0</strong></li>
<li><strong>Command line parsing: </strong>Cmdlets follow a purely declarative approach that goes further than what I&#8217;ve shown here (i.e. parameter sets), the CL tool uses an imperative approach. For simple cases the cmdlet would need less coding, but I&#8217;ll still give this point to the command line tool. It&#8217;s more flexible and consistent if it comes to parameter validation. With cmdlets, at some point the declarative approach will fail, e.g. if it comes to parameter interdependencies. <strong>1:0</strong></li>
<li><strong>Processing: </strong>It <em>was </em>more work to implement the cmdlet logic in the case of the <em>set </em>cmdlet. But this also brought about additional features and compliance with certain patterns. More work but not a bad thing. <strong>1:1</strong> </li>
<li><strong>Pipeline support: </strong>No question, here the cmdlets play top league. Just for the price of a clean pipeline object (which is neglectable) I get flexible output formatting, object oriented pipelining, etc.. The CL tool cannot compete here, as I have to code the output and still only get &#8220;simple output&#8221;. <strong>0:2</strong></li>
<li><strong>Help support: </strong>While the CL help is no doubt quite simple, it is sufficient for my needs. Cmdlet help on the other hand aims to answer more complex needs &#8212; by becoming complex^2, addressing unclear demands, and being highly redundant. Thus cmdlets loose by comparison as well as by simple inspection. <strong>2:0</strong></li>
</ul>
<p>If this were a shootout, it would be close to an even score. But it was not; it was about whether PowerShell cmdlets are a viable alternative to command line tools, and whether dual implementations are a feasible option. Both is the case and since this has been accomplished by plain PowerShell features whereas the command line tool needed a framework, PowerShell actually did very well.</p>
<p>All in all, I&#8217;m content. My console framework did well <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  and even if PowerShell will become the future, there is a clean migration path. I&#8217;m ready for the future <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Download the <a href="http://www.alexander-jung.net/download/AJ.NET_Console.zip">console framework</a> and the <a href="http://www.alexander-jung.net/download/AJ.NET_CL_vs_PS.zip">display settings</a> application.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f01%2f19%2fcommand-line-tool-vs-powershell-cmdlet%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f01%2f19%2fcommand-line-tool-vs-powershell-cmdlet%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/151/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/151/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/151/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=151&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2008/01/19/command-line-tool-vs-powershell-cmdlet/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/01/displaysettings-cl-thumb.jpg" medium="image">
			<media:title type="html">displaysettings_cl</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2008/01/displaysettings-ps-thumb.jpg" medium="image">
			<media:title type="html">displaysettings_ps</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2008%2f01%2f19%2fcommand-line-tool-vs-powershell-cmdlet%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Workflow Series Recap</title>
		<link>http://ajdotnet.wordpress.com/2007/12/14/workflow-series-recap/</link>
		<comments>http://ajdotnet.wordpress.com/2007/12/14/workflow-series-recap/#comments</comments>
		<pubDate>Fri, 14 Dec 2007 16:57:12 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[WF]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/12/14/workflow-series-recap/</guid>
		<description><![CDATA[This post concludes my little workflow series&#8230; 1. Talking WF (introduction) 2. Workflow Instance State Management 3. Workflow Communication and Workflow Communication Clarification 4. Hosting WF 5. Talking to the Windows Service 6. Robust Operations 7. Error handling is Error Management Remember where we started? WF. And what did I mostly talk about? Asynchronous data [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=146&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post concludes my little workflow series&#8230;</p>
<blockquote><p>1. <a href="http://ajdotnet.wordpress.com/2007/09/22/talking-wf/">Talking WF</a> (introduction)<br />
2. <a href="http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/">Workflow Instance State Management</a><br />
3. <a href="http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/">Workflow Communication</a> and <a href="http://ajdotnet.wordpress.com/2007/10/06/workflow-communication-clarification/">Workflow Communication Clarification</a><br />
4. <a href="http://ajdotnet.wordpress.com/2007/10/14/hosting-wf/">Hosting WF</a><br />
5. <a href="http://ajdotnet.wordpress.com/2007/10/19/talking-to-the-windows-service/">Talking to the Windows Service</a><br />
6. <a href="http://ajdotnet.wordpress.com/2007/11/04/robust-operations/">Robust Operations</a><br />
7. <a href="http://ajdotnet.wordpress.com/2007/11/11/error-handling-is-error-management/">Error handling is Error Management</a></p></blockquote>
<p>Remember where we started? WF. And what did I mostly talk about? Asynchronous data updates. Threading issues. Robust Windows Service implementation. Asynchronous error handling. Patterns. Practices. Guidelines.</p>
<p>And what did I rarely talk about? Shapes. Activities. Workflow specifics.</p>
<p>Remember what I wrote in the intro post: „And also very similar in the demand for knowledge of things that are not WF specific but are far from common knowledge for the average developer&#8230;“</p>
<p>Why are these things “far from common knowledge”, especially if they are not WF specific?</p>
<p>In my opinion this is because WF did not only introduce workflows. It also introduced asynchronous behavior and reliability demands far more forcibly than any other technology before.</p>
<ul>
<li>We had threading before – but only the odd developer actually embraced it.</li>
<li>We had Windows Services before – but only rarely were they employed.</li>
<li>We had human workflow and state before – but it was largely hand grown and synchronous state machines.</li>
<li>We had demanding applications that could not live with these simplistic notions – but these called for specialized server software like BizTalk anyway.</li>
</ul>
<p>With WF <em>any </em>developer might have to face all these new demands at once. It&#8217;s not WF in itself that is complex, in fact I can hardly imagine a workflow engine more easy to use than WF. It is the architectural consequences, the need for until then somewhat exotic concepts, the complicated asynchronous processing patterns. And the need to master all these demands at once.</p>
<p><strong>Truth to be told&#8230;. ? </strong></p>
<p>I once worked in a project that had quite amazing characteristics: 6 mio frontend transactions, processed to eventually enter the balance sheet, being subject to GAAP and quite a set of other legal compliance demands. Of course the software was built using BizTalk, not WF. We did then much of what I told you here. We had no choice and we had the budget.</p>
<p><em>Vacations@SDX </em>does not even handle 1 vacation requests per day on the average. Does <em>Vacations@SDX </em>adhere to all the guidelines? Of course it does <em>not</em>. No one would have paid for <em>that </em>amount of fault tolerance <em>just for one single workflow</em>. We had to stay on budget and to meet a deadline; and making it foolproof simply was not feasible. (And the hosting part was a learning experience anyway.)</p>
<p>The reality is: What I presented here is in certain parts the 120% solution. (I am a friend of delivering 80% and waiting which of the missing 20% parts cause the most trouble. And 120% is simply 20% waste in any case.) But since this project was meant to have reference character we <em>designed </em>for the 120%. And with changing demands, new versions, or other applications built on the same principles, we may evolve the framework and the patterns. Gradually and where it hurts most. And in one respect we <em>have </em>accomplished more than with a simple &#8220;coding&#8221; experience: We <em>have </em>the architectural patterns (even if not fleshed out in toto) and we <em>have </em>the Windows Service Framework implementation.</p>
<p>The pragmatic point of view for you is: Decide for yourself which parts <em>do </em>hurt you. If you leave out certain aspects, do it knowingly. And I hope I could present some patterns that will help you addressing the aspects you can&#8217;t leave out.</p>
<p>Anyway, this concludes that little series. It&#8217;s been a number of posts, but believe me, this is only where it begins. On the missing list are testing of workflows, workflow design (including choosing between sequence and state driven workflows), and versioning, among others. Anyway, I wanted to talk about those areas that I came to realize caused the most problems for the people involved in the projects. I hope to have provided some useful hints, even if I got carried away sometimes <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  .</p>
<p>PS: I know, I promised another post about the replay pattern. But given my current workload and other topics in my blog queue, I decided I should close this series <em>this </em>year. I haven&#8217;t forgotten it and if want to prioritize it, drop a respective comment.</p>
<p>I wish you a peaceful Christmas and a happy new year.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/146/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/146/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/146/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=146&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/12/14/workflow-series-recap/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Error Handling is Error Management</title>
		<link>http://ajdotnet.wordpress.com/2007/11/11/error-handling-is-error-management/</link>
		<comments>http://ajdotnet.wordpress.com/2007/11/11/error-handling-is-error-management/#comments</comments>
		<pubDate>Sun, 11 Nov 2007 10:21:25 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WF]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/11/11/error-handling-is-error-management/</guid>
		<description><![CDATA[An error occurred, oh my! Try/catch, anything more to say? You bet! Note: This is part of a series: 1. Talking WF (introduction) 2. Workflow Instance State Management 3. Workflow Communication and Workflow Communication Clarification 4. Hosting WF 5. Talking to the Windows Service 6. Robust Operations more to come&#8230; The last post talked about [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=145&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>An error occurred, oh my! Try/catch, anything more to say? You bet!</p>
<blockquote><p>Note: This is part of a series:<br />
1. <a href="http://ajdotnet.wordpress.com/2007/09/22/talking-wf/">Talking WF</a> (introduction)<br />
2. <a href="http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/">Workflow Instance State Management</a><br />
3. <a href="http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/">Workflow Communication</a> and <a href="http://ajdotnet.wordpress.com/2007/10/06/workflow-communication-clarification/">Workflow Communication Clarification</a><br />
4. <a href="http://ajdotnet.wordpress.com/2007/10/14/hosting-wf/">Hosting WF</a><br />
5. <a href="http://ajdotnet.wordpress.com/2007/10/19/talking-to-the-windows-service/">Talking to the Windows Service</a><br />
6. <a href="http://ajdotnet.wordpress.com/2007/11/04/robust-operations/">Robust Operations</a><br />
more to come&#8230;</p></blockquote>
<p>The last post talked about preventing errors, but no matter how hard we try, there <em>will </em>be errors. Thus we need to think about <em>Error Management</em>. This is more than simple exception handling, since our workflow system shall support long running robust operations, and we cannot afford any loss of data. Remember, this is about <em>MY </em>VACATION, please make sure this particular workflow does not get lost. All in all, error management includes:</p>
<ul>
<li>Ordinary error handling, i.e. handling of exceptions</li>
<li>Restart after mending the bug</li>
<li>Provide error feedback</li>
</ul>
<p><strong>Ordinary Error Handling</strong></p>
<p>OK, let&#8217;s start with the try/catch area. Errors are inevitable. No matter how many test code you write, this will only prove you didn&#8217;t find the cause for the next exception yet. Therefore rather than preventing every exception it is far more important to handle exceptions properly. The magical word here is „last chance exception handler“ (LCEH). If everything else failed, the LCEH ensures that the exception gets caught. In a web application you&#8217;ll write your LCEH code in <em>Application.OnError</em>, a Windows Service should do this in the main loop of the worker thread, the workflow engine provides a respective event (<a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.workflow.runtime.workflowruntime.workflowterminated.aspx">WorkflowRuntime.WorkflowTerminated</a>) for workflow instances.</p>
<p>It is <em>not </em>the LCEH&#8217;s responsibility to prevent data loss or to keep the business data consistent. That&#8217;s what transactions are for. The job of the LCEH is to</p>
<ul>
<li>prevent vanishing workflow instances</li>
<li>prevent inconsistent WF instance state</li>
<li>prevent unnoticed errors</li>
</ul>
<p>To accomplish this it should</p>
<ul>
<li>ensure the exception is properly logged (e.g. within the windows event log)</li>
<li>ensure the workflow instance is in a defined state (e.g. set the state to „What the heck?“)</li>
<li>ensure the exception is properly announced, e.g. write some additional error information to the <a href="http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/">workflow instance state table</a>.</li>
</ul>
<p>Again, this is not about preventing errors; it&#8217;s about making them apparent.</p>
<p><strong>Restart After Fixing the Bug</strong></p>
<p>OK, it happened. The child jumped headlong into the wishing well, it screams and nobody can pretend not to have noticed. Now what?</p>
<p>If you do nothing, the child will scream its head off, but that&#8217;s it. Talking about software, this is what usually happens. Talking about children and data this is not enough. Of course you should get the child out, clean it, comfort it, and make sure it cannot fall in again. Or you could leave it where it is and start a new one to fill the gap. With children you&#8217;ll probably (&#8230; no? &#8230; <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ) opt for the first choice, with software the second one is usually simpler to implement.</p>
<p>So what do you do if you are the admin and you have a workflow instance in an error state? The cause is diagnosed, the bug is fixed. Actually you could simply go on and continue at the location just before the error happened. Unfortunately it is not quite that easy to do that (time shift wasn&#8217;t included in the wishing well example). So we have four options, but none is actually pleasant:</p>
<ol>
<li><strong>Ignoring the situation.</strong> This may actually serve you quite well, as long as errors can be diagnosed and mended by someone manually. But if this is too error prone, if it happens too often, or if you have to adhere to some compliance rules (GAAP, legal issues, etc.) you&#8217;ll have to think about a better solution.</li>
<li><strong>Announce the problem. </strong>Do nothing about the workflow instance but sent an email to all people involved, telling them what happened and asking them to start all over again. And kill the child, it&#8217;s not needed anymore and it&#8217;s become an annoyance.</li>
<li><strong>Continue the workflow instance. </strong>This is what your customer will probably ask you to do. And it is by far the most complicated and error prone option. You&#8217;ll have to anticipate any error and provide loopbacks to any regular shape within the workflow.</li>
<li><strong>Start all over. </strong>The current workflow instance is flawed, dump it. <em>And </em>start a fresh workflow instance automatically (more or less).</li>
</ol>
<p>Lets ignore option 1 from now on, we got here because it&#8217;s not sufficient, anyway. It goes without saying that any other option would need some kind of UI, showing the admin the invalid workflow instances and offering respective means to mend the issue accordingly.</p>
<p>Option 2 (telling about the failure) is by far the most simple one and takes the least effort. Go for it if you can. Once the audience of you application becomes bigger and/or errors more regular, option 2 will no longer be sufficient. Forget about option 3 (continuing the workflow instance). It is not feasible for any non-trivial workflow. Period. Rather option 4 (re-running the workflow) should be your choice. I&#8217;ll dedicate a separate post to this pattern.</p>
<p>You may run into a situation where even option 4 does not fulfill the demand, e.g. if it cannot rely on &#8220;stale&#8221; data gathered before. This may call for a dedicated correction workflow. Try to avoid this situation by falling back option 2. Some errors simply cannot be mended automatically.</p>
<p><strong>Error Feedback </strong></p>
<p>If your web application fails, it’ll show an error page &#8212; more precisely if your web application fails synchronously. But what about failures that happen asynchronously. Failures that happen during timeout handling (exactly 2:13 AM). Of course our LCEH makes sure all the gory details are in the event log or any other log file, ready to be collected by the administrator and analyzed by the next available developer. But what about the end user? What is the substitute for the error page in this case?</p>
<p>The end user certainly needs no error page that pops up when he starts the web application and tells him that (any) one workflow instance {144215AE-28EB-4c36-81F6-7A0F9EC69F76} failed last night. What he needs… well, what <em>I</em> expect if one of my vacation requests failed, is:</p>
<ul>
<li>Some way of identifying the vacation request. In the long list of my vacation requests in the web application it should stand out, e.g. it could be in a certain error state marked red.</li>
<li>Some way of understanding what’s going on and what I am supposed to do. E.g. there could be an “info” column in the list of vacation requests, saying something like “There was an error writing the vacation to the payroll system. The administrator has been notified. Since he is on vacation and won’t be back in time you may just forget about your vacation.”</li>
<li>Some way of being notified of the problem, why else would I look into the web application in the first place. Read “email”, and it could tell me exactly the same, the web application does. (No reason to omit either!)</li>
</ul>
<p>Easier said than done? Well, yes. The challenge here is that I expect a lot to happen under error conditions. What if the error occurred during sending an email? Send another one to tell me that emails cannot be sent?</p>
<p>The reality is that it does not exactly make sense to put that much effort in code that should by all means never run. The realistic approach would be:</p>
<ul>
<li>Make vacation requests (i.e. any data that is subject to asynchronous processing) in temporary and error states clearly distinguishable in the web application. This might mean introducing yet another group of states, the “I’m going to do something and the user should never see the intermediate state because it’s overwritten after I have done my job properly”-states.</li>
<li>Make sure <em>somebody</em> gets notified. If there is a danger of losing data or producing inconsistent data, at least try to send an email to the administrator. Or shut down and make him look for the cause.</li>
</ul>
<p>To summarize this post in broader terms: It is futile to try to mend every error condition. Rather than trying to join <a target="_blank" href="http://en.wikipedia.org/wiki/Sisyphus">Sisyphus</a>, try to make errors apparent. Entering an error state is far better than insufficiently trying to handle (and effectively obscuring) it.</p>
<p>I didn&#8217;t plan that but I think it makes sense to spend the next post on the replay pattern&#8230;</p>
<p>PS: Finally a <a target="_blank" href="http://www.codethinked.com/post/2007/11/You-too-can-fail-fast-(or-at-least-really-quickly).aspx">recommended post</a>, quote &#8220;Programmers often have a misconception that their software should always work.&#8221;</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2007%2f11%2f11%2ferror-handling-is-error-management%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2007%2f11%2f11%2ferror-handling-is-error-management%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/145/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/145/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/145/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=145&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/11/11/error-handling-is-error-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2007%2f11%2f11%2ferror-handling-is-error-management%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Robust Operations</title>
		<link>http://ajdotnet.wordpress.com/2007/11/04/robust-operations/</link>
		<comments>http://ajdotnet.wordpress.com/2007/11/04/robust-operations/#comments</comments>
		<pubDate>Sun, 04 Nov 2007 14:26:25 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WF]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/11/04/robust-operations/</guid>
		<description><![CDATA[I guess you don&#8217;t want to know about my latest &#8220;Vista vs. Windows XP on one machine&#8221; experience. Suffice it to say that DOS and FDSIK saved my day. And that it reminded me that the next post should be about robustness&#8230; Note: This is part of a series: 1. Talking WF (introduction) 2. Workflow Instance State Management [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=144&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I guess you don&#8217;t want to know about my latest &#8220;Vista vs. Windows XP on <em>one</em> machine&#8221; experience. Suffice it to say that DOS and FDSIK saved my day. And that it reminded me that the next post should be about <em>robustness</em>&#8230;</p>
<blockquote><p>Note: This is part of a series:<br />
1. <a href="http://ajdotnet.wordpress.com/2007/09/22/talking-wf/">Talking WF</a> (introduction)<br />
2. <a href="http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/">Workflow Instance State Management</a><br />
3. <a href="http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/">Workflow Communication</a> and <a href="http://ajdotnet.wordpress.com/2007/10/06/workflow-communication-clarification/">Workflow Communication Clarification</a><br />
4. <a href="http://ajdotnet.wordpress.com/2007/10/14/hosting-wf/">Hosting WF</a><br />
5. <a href="http://ajdotnet.wordpress.com/2007/10/19/talking-to-the-windows-service/">Talking to the Windows Service</a><br />
more to come (error treatment).</p></blockquote>
<p>Last week at the coffee machine&#8230;</p>
<blockquote><p><em>David Developer:</em> „Hey Mrs. Accounting. That vacation of mine wasn‘t properly included in my salary!“</p></blockquote>
<blockquote><p><em>Alica Accounting: </em>„I know of no vacation. And I really don‘t have time for this. I have to track down Carl Consultant. He went on a vacation that actually was rejected!“</p></blockquote>
<blockquote><p><em>Peter Production (munching a donut): </em>„Oh, fat muft all haff happened laft monf &#8230; (gulp) &#8230; excuse me, when I had to reboot a few servers. Probably <em>Vacations@SDX </em>tried to access the payroll system when it was down. I told you, didn&#8217;t I?&#8221;</p></blockquote>
<blockquote><p><em><em>Alica Accounting: </em>„Yes?“ (like in „What the heck is this guy talking about?“)</em></p></blockquote>
<blockquote><p><em>Peter Production: </em>„Well, the application should have sent an email about that failure, but Exchange was also down. (slowly walking out) But since Paul Projectmanager agreed, the vacation was listed as granted. (<em>From the corridor</em>) And Carl Consultants vacation request somehow vanished. (<em>Gone</em>)“</p></blockquote>
<blockquote><p><em>Alica Accounting: </em>„Who built such a mess?“</p></blockquote>
<blockquote><p><em>David Developer: </em>„Oh, I &#8230; *<strong>aham</strong>* &#8230; I really don‘t know&#8230;“</p></blockquote>
<p>People pissed off, money involved, considerable cleanup work required. Do you want to be David Developer in this case? Do you need more motivation to think about robust processing and error handling?</p>
<p>Robust processing (i.e. preventing errors) and error handling are actually two sides of the same coin. What’s needed to alleviate the issues implied in the above conversation is as follows:</p>
<p>Preventing Errors:</p>
<ul>
<li>Calling another application <em>semantically </em>synchronously – and dealing with unavailability (the payroll system, as synchronous acknowledge is crucial for the workflow)</li>
<li>Calling another application <em>semantically</em> asynchronously (the email system, as email is inherently asynchronous)</li>
<li>Doing several things <em>semantically</em> in a transactional fashion – and breaking transaction contexts if expedient.</li>
</ul>
<p>The reason I stressed the word <em>semantically</em> should become clear in a minute. Please note that we cannot prevent the erroneous behaviour (e.g. unavailability); but we can prevent it to become a showstopper for our application. Only should that effort fail we&#8217;ll have to deal with the error (which I&#8217;ll defer until the next post).</p>
<p><strong>Calling Another Application Synchronously </strong></p>
<p>Many things are done synchronously because it‘s the natural way to do – and because it‘s so easy. Some things on the other hand have to be done synchronously despite the fact that it‘s far from easy. Talking to another application usually falls in the second category&#8230; .<br />
When talking to another application you‘ll have to make sure the call actually get‘s through. If it does not, retry! (And with this your simple call becomes a loop). If there is no chance, fail. But don‘t fail like „throw Exception and wreck the workflow instance“, fail like „execute this branch of the workflow that puts the workflow in a defined error state, to be mended by some operator and even clearly visible within <em>Vacations@SDX </em>(nothing fancy, a small neon light and a bell will do)“. If you actually manage to get a call through, be sure it was processed correctly. And correctly does not only mean „no exception thrown“. It also includes „sent back the correct reply.“ If you get some unexpected return value, one that you haven‘t been told about when you asked for the contract (and thus you cannot know whether it is safe to go on), again fail!</p>
<p><strong>The crux is: </strong>Failing to call some other system, a system that may be offline, is no technical issue. It‘s something to be expected and is has to be handled accordingly. Also applications evolve (and nobody will bother to tell you, just because you happen to call that WebService) and again, this is to be expected!</p>
<p><a href="http://ajdotnet.wordpress.com/2006/10/22/webservice-what-do-you-mean-webservice/">Internal WebServices</a> may not need this kind of caution but I would apply this rule to any external application, WebService, whatever API.</p>
<p><strong>Calling Another Application Asynchronously </strong></p>
<p>Sending an email is an inherently asynchronous operation. If all goes well you talk to the mail gateway and that‘s that. No way to know whether and when the mail is received. So why even bother if the gateway accepted the mail? As long as it will <em>eventually </em>accept it?</p>
<p>Suppose you just put the email in a certain database table and go on as if you did everything you had to do. No special error handling, no external dependency. Nice and easy.<br />
Suppose there is a Mail Service (e.g. a Windows Service that you just wrote) that regularly picks up mails from said table and tries to send them, one at a time. If the mail gateway was not available it would retry. If there was an error it would notify the admin.</p>
<blockquote><p>„But how does my application know whether the Mail Service actually did sent the email? Don‘t I need some kind of feedback?“</p></blockquote>
<p>What for? Email is unsafe, even if the gateway accepted it it might still not reach the recipient. So why bother if something bad happened at the initial step?</p>
<blockquote><p>Side note: This Mail Service would be „the last mail access to write“, and it would add substantial robustness to sending emails. Advantages include:</p>
<ul>
<li>asynchronous processing and load levelling (even in the case of mass emails)</li>
<li>application independence (if you happen to have more than one application in need of sending emails)</li>
<li>just one mail gateway account, infrastructure hassle just once.</li>
<li>the option of adding additional features (routing incoming reply emails to the respective application, regularly resending unanswered emails, escalation emails, &#8230;)</li>
</ul>
</blockquote>
<p><strong>The crux here is: </strong>If something allready is asynchronous, don&#8217;t bother making the call to the system foolproof. Factor it out and let some dedicated service handle the gory details about seting up the connection, retry scenarios, escalation, etc.. This pattern also holds for other use cases: a file drop to some network drive, sending an SMS, accessing a printer.</p>
<p><strong>Doing Several Things in a Transactional Fashion </strong></p>
<p><a href="http://ajdotnet.files.wordpress.com/2007/11/transactionscopeactivity.jpg"><img border="0" align="right" width="240" src="http://ajdotnet.files.wordpress.com/2007/11/transactionscopeactivity-thumb.jpg?w=240&#038;h=119" alt="transactionscopeactivity" height="119" style="border-width:0;margin:0 0 5px 5px;" /></a>Transactions are nothing new. In code you use some kind of <em>begin transaction/end transaction </em>logic, in WF there is a respective shape to span a transaction boundary (<a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.workflow.componentmodel.transactionscopeactivity.aspx">TransactionScopeActivity</a>). Use it! A transaction scope activity not only spans the contained logic, it also adds a persistent point (see <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/aa663362.aspx">Introduction to Hosting Windows Workflow Foundation</a>).</p>
<p>Enter „informal“ transactions&#8230;</p>
<p>Suppose neither the payroll system nor the email gateway support transactions. The textbook answer for non-transactional systems would be „compensation“. But if the payroll system needs special permission or treatment to undo an entry? And how do you fetch back an email?</p>
<blockquote><p><em>In my experience compensation at this technical level is largely a myth. If anything, compensation is a complicated business process that takes its own workflow to handle.</em></p></blockquote>
<p>Obviously the transaction boundaries we assumed do not quite work in these cases. But rather than trying endlessly to make it work, we might take a step back and rethink the state model. Do we have to go directly from „waiting for approval“ to „finished“? „Waiting“ and „finished“ are business states, states that describe interaction with or feedback for some end user. But nobody does deny us the option to introduce intermediary states like „granting vacation (processing payroll update)“ and „granting vacation (sending notification emails)“. This would effectively cut the the former transactional scope in pieces, thus eliminate the immediate need for ACID transactions or compensation.</p>
<p>What do we gain from this? Should anything happen along the way, the state would remain in one of the intermediate states. It would <em>not</em> enter the „vacation granted“ state and effectively lie to us. And what‘s more, the state would actually tell us what part of the process failed, the payroll system or the email. And it would be obvious, clearly calling out in the list of open vacation requests.</p>
<p><strong>The crux here is: </strong>Don‘t try to mirror business transactions to technical transaction boundaries. Don‘t do several fragile things in one step, separate them.</p>
<p>Feeling better? More confident? Sorry to disappoint you, but no matter how hard you try, eventually there <em>will </em>be errors. And how to address them will be covered in the next post.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2007%2f11%2f04%2frobust-operations%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2007%2f11%2f04%2frobust-operations%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/144/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/144/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/144/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=144&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/11/04/robust-operations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/11/transactionscopeactivity-thumb.jpg" medium="image">
			<media:title type="html">transactionscopeactivity</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2007%2f11%2f04%2frobust-operations%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Talking to the Windows Service</title>
		<link>http://ajdotnet.wordpress.com/2007/10/19/talking-to-the-windows-service/</link>
		<comments>http://ajdotnet.wordpress.com/2007/10/19/talking-to-the-windows-service/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 19:15:17 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/10/19/talking-to-the-windows-service/</guid>
		<description><![CDATA[Note: This is part of a series: 1. Talking WF (introduction) 2. Workflow Instance State Management 3. Workflow Communication and Workflow Communication Clarification 4. Hosting WF more to come (error management). The last post left us with the web application residing in IIS and WF hosted in a Windows Service. Separated like a divorced couple. Now we need to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=141&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is part of a series:<br />
1. <a href="http://ajdotnet.wordpress.com/2007/09/22/talking-wf/">Talking WF</a> (introduction)<br />
2. <a href="http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/">Workflow Instance State Management</a><br />
3. <a href="http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/">Workflow Communication</a> and <a href="http://ajdotnet.wordpress.com/2007/10/06/workflow-communication-clarification/">Workflow Communication Clarification</a><br />
4. <a href="http://ajdotnet.wordpress.com/2007/10/14/hosting-wf/">Hosting WF</a><br />
more to come (error management).</p></blockquote>
<p>The <a href="http://ajdotnet.wordpress.com/2007/10/14/hosting-wf/">last post</a> left us with the web application residing in IIS and WF hosted in a Windows Service. Separated like a divorced couple. Now we need to setup some communication between them. The means of choice? WCF of course. (There is a choice?)</p>
<p>I’m not going into too much details about WCF here as this series is devoted to WF and the documentation for WCF is considerably broader than the WF related information. For hosting of WCF in a Windows Service have a look at <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms733069.aspx">How to: Host a WCF Service in a Managed Windows Service</a>. For a more elaborate example including WF <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/bb266709.aspx">Integrating Windows Workflow Foundation and Windows Communication Foundation</a> will show you how to host the WF engine as service extension (gee, the <a href="http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/">service pattern</a> again).</p>
<p><strong>&#8216;S&#8217;ervice or &#8216;s&#8217;ervice?</strong></p>
<p>Let’s have a look at the architecture: What will become of our Windows Service if I attach a WCF interface to it? Will it become a Service in the SOA sense (capital &#8216;S&#8217;!)? Do we therefore need to set up HTTP bindings, WS-Security (my vacation is certainly important enough to be protected!)? Are we going to advertise the Service so that a customer can plug into it? Probably not. None of it. From a logical point of view the WF part is still part of the business logic of our application as the reason to separate it was purely technical. It will therefore become an <em>internal</em> service (see <a href="http://ajdotnet.wordpress.com/2006/10/22/webservice-what-do-you-mean-webservice/">WebService? What do you mean, „WebService“?</a>), lowercase &#8216;s&#8217;!.</p>
<blockquote><p>WCF actually supports internal services quite well with the named pipe binding. It&#8217;s is a binary, efficient binding and it is restricted to one machine (the binding, not named pipes in general of course). This might rule out distributing the two parts on different machines, but seriously, we don‘t have that many employees (yet).<br />
Windows actually also „supports“ that choice by making it very hard to choose HTTP instead. (The “very” stems from the fact that it’s hard to diagnose the reason for the problem. There is <a target="_blank" href="http://msdn.microsoft.com/msdnmag/issues/06/11/SecurityBriefs/default.aspx">solution</a>, though not a pretty one, all in the name of security.)</p></blockquote>
<p>The fact that we factored the WF engine out of our web application was not intended to change the <em>logical</em> architecture more than necessary, i.e. the workflow is still part of our business logic:</p>
<p align="center"><img border="0" width="360" src="http://ajdotnet.files.wordpress.com/2007/10/arch-logical.jpg?w=360&#038;h=412" alt="arch_logical" height="412" style="border-width:0;" /></p>
<p>However the <em>physical</em> architecture is somewhat different:</p>
<p align="center"><img border="0" width="644" src="http://ajdotnet.files.wordpress.com/2007/10/arch-physical.jpg?w=644&#038;h=395" alt="arch_physical" height="395" style="border-width:0;" /></p>
<p>The danger here lies in misinterpreting the physical architecture as logical architecture. (It&#8217;s actually debateable whether the call to the Windows Service originates from the DAL or the BL. Don&#8217;t sweat it, it&#8217;s of no consequence.)</p>
<p><strong>&#8216;S&#8217;ervice?</strong></p>
<p>The demand of our application is fulfilled, but let‘s think a bit more about the Service notion. What if I actually wanted a Service in the SOA sense, one that is publicly available?</p>
<p>In this case <em>I </em>would still propose the very same approach for the Windows Service and an accompanying web application. The web application would consist of a publicly available Service (WCF hosted in IIS, e.g. a Web Service), part of the presentation layer, that handled the communication with the caller (validation, security, versioning, &#8230;.). It would implement the service interface that was developed during the contracting phase. Internally it would talk, again using WCF, to the Windows Service, just like above. For a prototype SOA ecosystem based on this idea (and being a little more fleshed out) have a look at <a target="_blank" href="http://ajdotnet.wordpress.com/2007/02/23/security-analysis-on-wcf-for-the-german-gouvernment/">Security analysis on WCF for the German Gouvernment</a>.</p>
<p>For a series about WF this post was kind of a diversion. Yet I think it is part of the architecture <em>implied</em> by the employment of WF, therefore I kept it in. The next post will look into robust processing, as promised in a previous post.</p>
<p><em>Quick! How many different notions of the word &#8216;Service&#8217; did you count in this post? <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </em></p>
<p><font color="#008000">That’s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2007%2f10%2f19%2ftalking-to-the-windows-service%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2007%2f10%2f19%2ftalking-to-the-windows-service%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/141/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/141/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=141&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/10/19/talking-to-the-windows-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/10/arch-logical.jpg" medium="image">
			<media:title type="html">arch_logical</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/10/arch-physical.jpg" medium="image">
			<media:title type="html">arch_physical</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2007%2f10%2f19%2ftalking-to-the-windows-service%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Hosting WF</title>
		<link>http://ajdotnet.wordpress.com/2007/10/14/hosting-wf/</link>
		<comments>http://ajdotnet.wordpress.com/2007/10/14/hosting-wf/#comments</comments>
		<pubDate>Sun, 14 Oct 2007 12:37:49 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WF]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/10/14/hosting-wf/</guid>
		<description><![CDATA[Note: This is part of a series: 1. Talking WF (introduction) 2. Workflow Instance State Management 3. Workflow Communication and Workflow Communication Clarification more to come (error management). Hosting WF is easy. Real Easy. You can host it anywhere you want. Console applications, ASP.NET applications, windows services, shopping bags, closets, &#8230; . Well. It turns out that most available [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=138&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is part of a series:<br />
1. <a href="http://ajdotnet.wordpress.com/2007/09/22/talking-wf/">Talking WF</a> (introduction)<br />
2. <a href="http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/">Workflow Instance State Management</a><br />
3. <a href="http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/">Workflow Communication</a> and <a href="http://ajdotnet.wordpress.com/2007/10/06/workflow-communication-clarification/">Workflow Communication Clarification</a><br />
more to come (error management).</p></blockquote>
<p>Hosting WF is easy. Real Easy. You can host it anywhere you want. Console applications, ASP.NET applications, windows services, shopping bags, closets, &#8230; . Well. It turns out that most available samples are too simplistic for my taste. Hosting for the sake of it may be easy, hosting in real world scenarios has its pitfalls.</p>
<p><strong>Hosting in IIS</strong></p>
<p>Given that our example application is a web application, the first attempt of hosting WF might be somewhere within the web application itself. Actually this is quite simple and covers all but one demand. Due to the IIS architecture it is even a very robust solution, one that can easily be adorned with an IIS hosted WCF service interface, again backed by IIS, namely the security features. Just great. Apart from the „but one demand“: IIS hosted code relies on a request! Not a &#8220;current&#8221; request, just any request that keeps the appdomain running. Should the appdomain shut down and go to sleep for the rest of the night, there is no running WF engine. What if a workflow is supposed to timeout somewhen during the night? What if it is supposed to regularly poll a directory or database table? Nothing of this happens until the next request comes in, wakes the appdomain and eventually starts the WF engine. If you can live with the time lag, go for IIS. If not, IIS is out of question.</p>
<p>And of course our example application <em>cannot</em> live with that time lag. There regularly won‘t be a vacation request for days, sometimes weeks. No timeouts and reminder mails? No way!</p>
<p><strong>Hosting in a Windows Service</strong></p>
<p>I‘ve seen various developers at this point thinking of alternatives: Regularly trigger the web application to revive the appdomain&#8230; Hosting the WF in a console application&#8230; A winforms application&#8230; . Eventually I realized that quite a few developers just try to avoid the obvious solution: Windows Services (as in NT <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms681921.aspx">Service</a>).</p>
<p>Why avoid them? Because Windows Services are weird. And demanding. They have to be installed and started via the service controll manager (SCM). You have to deal with <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms686005.aspx">service accounts</a> and permissions. Windows Services are supposed to be multithreaded. They have no decent UI other than some logs. They have to be robust—and if you think your current application is robust, a Windows Service has to be robust^3. For example:</p>
<ul>
<li><a target="_blank" href="http://en.wikipedia.org/wiki/Zombie" title="Zombie"><img align="right" src="http://upload.wikimedia.org/wikipedia/commons/thumb/a/ad/Zombie_haiti_ill_artlibre_jnl.png/200px-Zombie_haiti_ill_artlibre_jnl.png" style="margin:0 0 5px 5px;" /></a>A Windows Service may start at boot time and shut down 3 years later.</li>
<li>A Windows Service may have to talk to a database (or other resource) that occasionally goes off line for maintenance reasons.</li>
<li>A Windows Service may become what I call a <a target="_blank" href="http://en.wikipedia.org/wiki/Zombie">zombie</a> if the worker thread terminates but the service keeps running.</li>
</ul>
<p>Cheer up, with .NET everything gets better. The .NET Framework devotes a whole namespace to Windows Services: <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.serviceprocess.aspx">System.ServiceProcess</a>. The most important class is <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.serviceprocess.servicebase.aspx">ServiceBase</a> which acts as base class for your own Windows Service implementation; actually it’s a thin layer over the <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms685149.aspx">Service Control Handler Function</a>. There are also classes for installation or controlling other services. So there already is some very welcome support available.</p>
<p>Additionally there are quite a few examples available on how to use these classes to host WF, usually in conjunction with WCF (if the WF is not hosted in your web application you need some means to talk to it, we&#8217;ll get to that, too). The most simplistic implementation would start and stop the WF engine in the respective SCM commands (i.e. <em>ServiceBase.OnStart </em>and <em>ServiceBase.OnStop </em>respectively). It really doesn‘t need more to implement a valid windows service hosting WF. Well, for the sake of it that may be true. But real world demands? Are these examples actually production ready? Do they fulfill the demands regarding operations, robustness, etc.? Not in my opinion.</p>
<p><strong>Better Hosting in a Windows Service</strong></p>
<p><em>ServiceBase</em> has no special support for worker threads. No support for any runtime diagnosis (such as a ping or heartbeat). <em>ServiceBase</em> is actually prone to become a zombie, because an exception during any SCM command (such as pause) will be written to the event log but it will _<em>not</em>_ stop the service. However this cannot be called „robustness“ (if it were defined that way) because an exception in another thread will turn down the whole process, including all services contained in the same EXE and registered with the SCM.<br />
Actually these are all fairly generic issues for any Windows Service and not dependant on the work the service actually does. Therefore its quite easy to come up with a reusable Windows Service framework on top of <em>ServiceBase</em>.</p>
<p>And here is <u>the pattern</u> to be implemented by such a framework (based on two real world projects):</p>
<ul>
<li>Restrict your EXE to one Windows Service. We want the service to go down if something bad happens; and dragging innocent services into death just because they happen to run in the same process won&#8217;t do.</li>
<li>Don‘t do your work in <em>ServiceBase.OnStart</em>. Use it to start a separate thread, acting as watchdog. Notify that thread about pause, continue, stop, and the other SCM commands. If an exception is raised during an SCM command, again, kill the service (you can allways do that by starting another thread that raises an exception).</li>
<li>The watchdog thread should start the engine and afterwards enter a loop. It should leave the loop if it receives the stop request, stopping the engine before it finishes.</li>
<li>Within the loop the watchdog thread should regularly check whether the engine is still operating (hence the term &#8220;watchdog&#8221;). If the engine fails for some reason the watchdog thread may try to compensate (restart the WF engine). E.g. if the engine failed because the databases went off line, it may be an option to wait for a certain amount of time. If the database server was just rebooted the databases may come online in a few minutes. Anyway, if that is not possible, kill the service.</li>
<li>The watchdog should also maintain a heartbeat, say trigger a performance counter that tells the operator the Windows Service is healthy &#8212; even if the system doesn‘t do anything worthwhile right now.</li>
</ul>
<p>The reason for killing the service is simple: A Windows Service that stopped working is more obvious and will be noted far earlier than one that just wrote an event log entry and kept lingering around. Also a stopped service usually can be tracked by operations software such as <a target="_blank" href="http://en.wikipedia.org/wiki/IBM_Tivoli_NetView">NetView</a>.</p>
<p>Now we have a service that fullfills basic demands of robustness. There <em>is </em>more to say about robustness, but before that we need a means to talk to the workflow, now that we cut it out of the web application. Next post.</p>
<p><font color="#008000">That’s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fajdotnet.wordpress.com%2f2007%2f10%2f14%2fhosting-wf%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2007%2f10%2f14%2fhosting-wf%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/138/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/138/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=138&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/10/14/hosting-wf/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/commons/thumb/a/ad/Zombie_haiti_ill_artlibre_jnl.png/200px-Zombie_haiti_ill_artlibre_jnl.png" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fajdotnet.wordpress.com%2f2007%2f10%2f14%2fhosting-wf%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Workflow Communication Clarification</title>
		<link>http://ajdotnet.wordpress.com/2007/10/06/workflow-communication-clarification/</link>
		<comments>http://ajdotnet.wordpress.com/2007/10/06/workflow-communication-clarification/#comments</comments>
		<pubDate>Sat, 06 Oct 2007 12:47:04 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WF]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/10/06/workflow-communication-clarification/</guid>
		<description><![CDATA[My last post may need a clarification&#8230; Tim raised the question whether it is such a good idea to synchronize the communication between web application and workflow instance. To make it short: Generally it isn&#8217;t! Period. It hurts scalability and it may block the web request being processed. Therfore from a technical perspective it usually is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=137&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My <a href="http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/">last post</a> may need a clarification&#8230;</p>
<p><a href="http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/#comments">Tim</a> raised the question whether it is such a good idea to synchronize the communication between web application and workflow instance. To make it short: Generally it isn&#8217;t! Period. It hurts scalability and it may block the web request being processed. Therfore from a technical perspective it usually is preferable to avoid it. Ways around this include:</p>
<ul>
<li>Redirect the user to a different page telling him that his request has been placed and that it may take a while until it is processed.</li>
<li>Ignore the fact that the current page may show an outdated workflow state, hope for the best and take means that another superfluous request won&#8217;t cause any problems.</li>
<li>&#8230;.</li>
</ul>
<p>However sometimes you cannot avoid having to support a use case like the one I presented. But even then &#8212; if the circumstances demand it &#8211; it might be possible to avoid blocking on the workflow communication. E.g. <em>the web application </em>could write a &#8220;processing requested&#8230;&#8221; state into the worflow instance state table (contrary to what I wrote in an <a href="http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/">earlier post</a>, but that was <em>just one </em>pattern, not a rule either). The actual call could be made asynchronously, even be delayed somehow.</p>
<p>If you still think about following the pattern I layed out, make sure the processing within the workflow instance is fast enough to be feasibly made synchronously. E.g.:</p>
<p align="center"><img border="0" width="440" src="http://ajdotnet.files.wordpress.com/2007/10/sequence-1.jpg?w=440&#038;h=408" alt="sequence_1" height="408" style="border:0;" /></p>
<p align="left">As you can see, synchronization encapsulates the whole processing.</p>
<p>What if the processing takes longer? Well, the pattern still holds if you introduce an &#8220;I&#8217;m currently processing&#8230;&#8221; state. The callback won&#8217;t tell you the work has been done any longer, but it will still tell you that the demand has been placed and accepted by the workflow instance.</p>
<p align="center"><img border="0" width="444" src="http://ajdotnet.files.wordpress.com/2007/10/sequence-2.jpg?w=444&#038;h=502" alt="sequence_2" height="502" style="border:0;" /></p>
<p>In this case synchronization encapsulates only the demand being accepted, not the processing itself. However it still serves the original purpose, which was telling the user that his request has been placed.</p>
<p>What if you need to synchronize with the end of a longer running task? In that case this pattern is <em>not </em>the way to go. The user clicking on a button and the http post not returning for a minute? This definitely calls for another pattern.</p>
<p>I hope this has made things clearer.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/137/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/137/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/137/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=137&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/10/06/workflow-communication-clarification/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/10/sequence-1.jpg" medium="image">
			<media:title type="html">sequence_1</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/10/sequence-2.jpg" medium="image">
			<media:title type="html">sequence_2</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Workflow Communication</title>
		<link>http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/</link>
		<comments>http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/#comments</comments>
		<pubDate>Tue, 02 Oct 2007 18:36:09 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WF]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/</guid>
		<description><![CDATA[Note: This is part of a series: 1. Talking WF (introduction) 2. Workflow Instance State Management more to come (hosting, error management). The last post brought up the following topic: &#8220;I clicked a button and somehow the workflow took over and did something. As you know, this happens asynchronously, nevertheless I saw the correct state after the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=133&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is part of a series:<br />
1. <a href="http://ajdotnet.wordpress.com/2007/09/22/talking-wf/">Talking WF</a> (introduction)<br />
2. <a href="http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/">Workflow Instance State Management</a><br />
more to come (hosting, error management).</p></blockquote>
<p>The last post brought up the following topic:</p>
<blockquote><p>&#8220;I clicked a button and somehow the workflow took over and did something. As you know, this happens asynchronously, nevertheless I saw the correct state after the processing instantly. To make that work, the web application has to have a means to know when the state has changed. <em>Workflow communication.&#8221;</em></p></blockquote>
<p>So, how do you talk to a workflow instance? How do you know it processed your request? How does it talk back?</p>
<p><em>Please note: Talking to a workflow is a topic that is actually well documented. Yet it still has its pitfalls and it takes a little getting used to. Therefore I’ll recap the pattern, trying to explain it along the line. And I will assume a certain use case (the synchronization issue) because it showed up regularly in our use cases. </em></p>
<p>If you are new to WF you&#8217;ll have to master two or three things to talk to a workflow: The service pattern, a silly interface pattern, and some threading issues.</p>
<p><strong>The service pattern</strong></p>
<p>If you read an article about WF, the service pattern is most likely <em>not </em>introduced properly; most articles simply say &#8220;do this, and you&#8217;ll accomplish that&#8221;. The service pattern has been widely used for visual studio design time support but that&#8217;s the only usage I am aware of. Until WinFx came around, that is. Firstly WF uses the service pattern for runtime services such as persistence. In this case the developer only has to announce existing service implementations. Secondly it also employes services for data exchange &#8212; in which case the developer has to deal with the service pattern in all its beauty.</p>
<blockquote><p>For the record: The service pattern usually defines a service as an interface. It decouples the consumer of a service and the provider. A certain service may be optional (such as the tracking service) or mandatory (such as the scheduler service). If the consumer needs a particular service, it&#8217;ll ask the provider. Usually providers form a chain, so if the first provider does not know the service, it&#8217;ll ask the next one.</p>
<p>And no, it&#8217;s got nothing to do with web services&#8230;</p>
<p>You might want to read <a target="_blank" href="http://msdn.microsoft.com/msdnmag/issues/06/03/DesignerHosting/">Create And Host Custom Designers With The .NET Framework 2.0</a> Chapter &#8220;Extensibility with Services&#8221; for a slightly more elaborate description.</p></blockquote>
<p>For data exchange the developer has to define an interface (the service contract) and a class that implements the interface (the service). During startup he creates an instance of the service and registers it with the data exchange service (a service provider in itself). If you need it in an activity to do something worthwhile you ask the <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/aa349099.aspx">ActivityExecutionContext</a> (the service provider at hand, see <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.workflow.componentmodel.activity.execute.aspx">Activity.Execute</a>) for the service. Then you work with it.</p>
<p>Some activities already provide design time support for services and the activities for data exchange are among them (<a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.workflow.activities.handleexternaleventactivity.aspx">HandleExternalEventActivity</a> and <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.workflow.activities.callexternalmethodactivity.aspx">CallExternalMethodActivity</a>):</p>
<p><a href="http://ajdotnet.files.wordpress.com/2007/10/activity2.jpg"><img border="0" width="240" src="http://ajdotnet.files.wordpress.com/2007/10/activity2-thumb.jpg?w=240&#038;h=83" alt="activity2" height="83" style="border-width:0;" /></a>  <a href="http://ajdotnet.files.wordpress.com/2007/10/prop2.jpg"><img border="0" width="240" src="http://ajdotnet.files.wordpress.com/2007/10/prop2-thumb.jpg?w=240&#038;h=148" alt="prop2" height="148" style="border-width:0;" /></a></p>
<p><a href="http://ajdotnet.files.wordpress.com/2007/10/activity1.jpg"><img border="0" width="240" src="http://ajdotnet.files.wordpress.com/2007/10/activity1-thumb.jpg?w=240&#038;h=85" alt="activity1" height="85" style="border-width:0;" /></a>   <a href="http://ajdotnet.files.wordpress.com/2007/10/prop1.jpg"><img border="0" width="240" src="http://ajdotnet.files.wordpress.com/2007/10/prop1-thumb.jpg?w=240&#038;h=129" alt="prop1" height="129" style="border-width:0;" /></a></p>
<p>Please note that many of the predefined activities offer other anchors to attach your own code, events and the like, that do not provide easy access to the <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/aa349099.aspx">ActivityExecutionContext</a>, thus no service provider is readily available.</p>
<p><strong>A <a target="_blank" href="http://en.wikipedia.org/wiki/Silly_Walk">silly interface pattern</a></strong></p>
<p>When I first wanted to talk to a workflow, I knew I need an interface. To call into the workflow I expected a method; to get notified from the workflow I expected an event. Of course I expected to call and be called on my own thread. Guess what&#8230; .</p>
<p>Well, my attitude actually was &#8220;I &#8211; the code of the host application &#8211; create the workflow, I&#8217;m in charge, I define the point of view.&#8221; The reality of course is &#8220;I &#8211; the workflow &#8211; do not care what the host application code thinks who he is. I do the work, I&#8217;m in charge, I define the point of view.&#8221; This turns my initial expectations upside down. In other words: A call into the workflow instance <em>notifies</em> the instance of some external demand, thus it is made via an event. If the workflow instance has to say something it straightly calls a method. And it does not care what thread is involved.</p>
<blockquote><p>[ExternalDataExchange]<br />
<font color="#0000ff">interface</font> IVactionRequestWorkflow<br />
{<br />
    <font color="#008000"><em>// call into workflow instance</em></font><br />
    <font color="#0000ff">event</font> EventHandler&lt;ConfirmationEventArgs&gt; ConfirmVacationRequest;<br />
    <br />
    <font color="#008000"><em>// callback from workflow instance</em></font><br />
    <font color="#0000ff">void</font> ConfirmationProcessed(<font color="#0000ff">bool</font> confirmed);<br />
}</p></blockquote>
<p>Silly, isn&#8217;t it?</p>
<p><strong>Some threading issues </strong></p>
<p><img border="0" align="right" width="525" src="http://ajdotnet.files.wordpress.com/2007/10/communication1.jpg?w=525&#038;h=183" alt="communication1" height="183" style="border-width:0;margin:0 0 5px 5px;" />To elaborate more on the threading issue: We know that WF is inherently multithreaded. When you call into a workflow instance (pardon, when you signal it), the WF engine (more precisely the data exchange service) will catch the event on your thread, do some context switch magic, and signal the workflow instance on its thread. (It might have to load the workflow instance, which is just another reason for the decoupling.) If the workflow instance on the other hand has some information it calls your code on its own thread &#8212; the WF engine can hardly hijack your thread for some automatic context switch. Consequence: You signal the workflow instance and the call (more or less) immediately returns. But you don&#8217;t know when the workflow will actually get signaled, much less when it will have done the respective processing. You may issue a call from the workflow instance but <em>you</em> will have to care for the context switch and the proper reaction yourself.</p>
<p>This is pretty good for performance and scalability. But if you need synchronous behavior (as in our example) it hurts a bit.</p>
<p>To make a long story short, here&#8217;s <u>the pattern</u> we came about with:</p>
<ul>
<li><img border="0" align="right" width="525" src="http://ajdotnet.files.wordpress.com/2007/10/communication2.jpg?w=525&#038;h=183" alt="communication2" height="183" style="border-width:0;margin:0 0 5px 5px;" />The interface contains a <em>CallIntoWorkflowInstance</em> event and a respective <em>CallIntoWorkflowInstanceAcknowledge </em>callback method (<em>ConfirmVacationRequest </em>and <em>ConfirmationProcessed </em>in the interface above)</li>
<li>The workflow instance accepts the <em>CallIntoWorkflowInstance </em>event, does some work (supposed to be synchronous) and calls <em>CallIntoWorkflowInstanceAcknowledge </em>to tell you it finished its part.</li>
<li>The service implements the event (along with a SignalCallIntoWorkflowInstance helper method) and the method. It also has an <em>AutoResetEvent </em>for the synchronization.</li>
<li>The helper method (called from the web application thread) raises the event and afterwards waits for the <em>AutoResetEvent</em>.</li>
<li>The callback method (called from the workflow instance thread) simply signals the <em>AutoResetEvent</em>. This will cause the helper method on the other thread to be unblocked and to return.</li>
</ul>
<p>The service implementing the above interface consequently looks like this:</p>
<blockquote><p><font color="#0000ff">class</font> VacationRequestWorkflowService : IVactionRequestWorkflow<br />
{<br />
    AutoResetEvent _confirmationProcessed = <font color="#0000ff">new</font> AutoResetEvent(<font color="#0000ff">false</font>);<br />
    <br />
    <font color="#0000ff">public</font> <font color="#0000ff">event</font> EventHandler&lt;ConfirmationEventArgs&gt; ConfirmVacationRequest;<br />
    <br />
    <font color="#0000ff">public</font> <font color="#0000ff">void</font> OnConfirmVacationRequest(ConfirmationEventArgs ea)<br />
    {<br />
        <font color="#0000ff">if</font> (ConfirmVacationRequest != <font color="#0000ff">null</font>)<br />
            ConfirmVacationRequest(<font color="#0000ff">null</font>, ea);<br />
    }<br />
    <br />
    <font color="#0000ff">public</font> <font color="#0000ff">void</font> ConfirmationProcessed(<font color="#0000ff">bool</font> confirmed)<br />
    {<br />
        _confirmationProcessed.Set();<br />
    }    <font color="#0000ff">public</font> <font color="#0000ff">void</font> SynchronousConfirmVacationRequest(WorkflowInstance instance, <font color="#0000ff">bool</font> confirmed)<br />
    {<br />
        <font color="#008000"><em>// send event</em></font><br />
        OnConfirmVacationRequest(<font color="#0000ff">new</font> ConfirmationEventArgs(instance.InstanceId, confirmed));<br />
        <font color="#008000"><em>// wait for callback</em></font><br />
        _confirmationProcessed.WaitOne();<br />
    }<br />
}</p></blockquote>
<p>Now we have synchronized the workflow instance with out calling application. Of course we rely on the callback or we would wait endlessly, but that&#8217;s another story. </p>
<p>The next post will take a closer look at hosting.</p>
<p><font color="#008000">That’s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/133/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/133/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/133/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=133&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/10/activity2-thumb.jpg" medium="image">
			<media:title type="html">activity2</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/10/prop2-thumb.jpg" medium="image">
			<media:title type="html">prop2</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/10/activity1-thumb.jpg" medium="image">
			<media:title type="html">activity1</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/10/prop1-thumb.jpg" medium="image">
			<media:title type="html">prop1</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/10/communication1.jpg" medium="image">
			<media:title type="html">communication1</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/10/communication2.jpg" medium="image">
			<media:title type="html">communication2</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/10/02/workflow-communication/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Workflow Instance State Management</title>
		<link>http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/</link>
		<comments>http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/#comments</comments>
		<pubDate>Sun, 30 Sep 2007 14:34:24 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WF]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/</guid>
		<description><![CDATA[Note: This is part of a series: 1. Talking WF (introduction) more to come (communication, hosting, error management). Let&#8217;s skip the &#8220;how do I reference the necessary assemblies&#8221; stuff and assume the boilerplate work of setting up the WF engine and starting workflows has been done. (There&#8217;s plenty documenatation about this available elsewhere.) So let&#8217;s asume we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=120&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is part of a series:<br />
1. <a href="http://ajdotnet.wordpress.com/2007/09/22/talking-wf/">Talking WF</a> (introduction)<br />
more to come (communication, hosting, error management).</p></blockquote>
<p>Let&#8217;s skip the &#8220;how do I reference the necessary assemblies&#8221; stuff and assume the boilerplate work of setting up the WF engine and starting workflows has been done. (There&#8217;s plenty documenatation about this available elsewhere.) So let&#8217;s asume we have a page that starts workflow instances and the workflow is in place and running. Now, when you start thinking about a workflows you‘ll sooner or &#8230; well, even sooner, ask questions like „<em>How dows this piece of information get to my workflow instance?</em>“ and „<em>How does that piece get out?</em>“. In one word: data exchange.</p>
<p>Let‘s make that more tangible with an example: Let&#8217;s asume I‘m the project manager and I just got a notice that the guy across the room wanted to go on vacation when I planned going-live. Damn his insolence! How do I cancel his request?<br />
I start up <em>Vacations@SDX</em>, select the page that gives me a list of open vacation requests, and click the „<em>cancel vacation</em>“ button for the one in question. The page refreshes and the state of the vacation request becomes „<em>canceled for undue insolence</em>“ (Oh boy, if any of that happend, my collegues would kill me. But nastiness is so much fun <img src='http://s2.wp.com/wp-includes/images/smilies/icon_evil.gif' alt=':evil:' class='wp-smiley' />  ).</p>
<p>There a two things that happend here that are noteworthy:</p>
<ol>
<li>I saw a list of open vacation requests. And each request should be represented by a running workflow instance. Did I see a list of workflow instances? <em>Workflow instance state management.</em></li>
<li>I clicked a button and somehow the workflow took over and did something. As you know, this happens asynchronously, nevertheless I saw the correct state after the processing instantly. To make that work, the web application has to have a means to know when the state has changed. <em>Workflow communication.</em></li>
</ol>
<p><strong>Workflow instance state management</strong></p>
<p>The workflow instance has state. It knows about data somehow coming in, knows what activities have been executed and so forth. Therefore it would be possible to query all workflows, load them, and ask about certain details, e.g. read some properties. Wait, the workflow instance might process something asynchronously&#8230; . How do you synchronize? What if the workflow just terminated because you loaded it and it somehow finished? Do you really want to load thousands of workflow instances for every query? (OK, that‘s probably beyond the example application, but still&#8230;).</p>
<p>Once you‘ve thought along that line you‘ll realize that you need to maintain the business state (the vacation request in our example) <em>outside</em> of the workflow instance, i.e. in a database table. But now you have to face the problem of keeping the data in this table and the related workflow instance in sync. Here you have two feasible options:</p>
<ol>
<li>Keep the workflow instance oblivious of that table, let the web application read and write into the table (kind of a cache).</li>
<li>Let the workflow maintain its state in the table directly, let your web application read the table.</li>
</ol>
<p>Some people might vote for option 1, and with good reason. It keeps the business logic in one place, the web application; you don‘t have to deal with technically concurrent database access in semantically single „transactions“). It clearly limits the workflow instance to workflow stuff, which promotes <a target="_blank" href="http://en.wikipedia.org/wiki/Separation_of_concerns">separation-of-concerns</a>.</p>
<p><img border="0" align="right" width="455" src="http://ajdotnet.files.wordpress.com/2007/09/wf_state_table.jpg?w=455&#038;h=285" alt="wf_state" height="285" />All well and good. But I go for number 2. For two reasons: Number 1 would imply more communication and synchronization between workflow instance and web application (we‘ll look into that). And the main reason: If my workflow is long running, it might change its state (say to „timeout because no one cared“) at a time when no user is online and the web application is fast asleep. With number 1 some other piece of code would have to do what the web application already does.</p>
<p><u>The pattern</u> <a target="_blank" href="http://www.sdx-ag.de/">we</a> came to appreciate goes like this: </p>
<ul>
<li>Mirror the workflow state in a table (containing the state and the workflow instance ID)</li>
<li>Let the workflow maintain that state</li>
<li>Let the web application query that state</li>
<li>Provide cleanup, e.g. remove the respective row when the workflow finishes.</li>
<li>Ensure consistency (e.g. put in validation code that verifies that the information within the table is consistent with the workflow state, provide some diagnostic tool that checks whether the workflow instances still exists)</li>
</ul>
<p>This way it should be far easier to provide overview lists. And to interact with workflow instances from your web application you would need a table with workflow IDs anyway.</p>
<p>The next post will look into the workflow communication topic, the actual data exchange with the workflow instance.</p>
<p><font color="#008000">That’s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/120/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/120/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/120/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=120&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/09/wf_state_table.jpg" medium="image">
			<media:title type="html">wf_state</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/09/30/workflow-instance-state-management/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Talking WF&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2007/09/22/talking-wf/</link>
		<comments>http://ajdotnet.wordpress.com/2007/09/22/talking-wf/#comments</comments>
		<pubDate>Sat, 22 Sep 2007 15:11:38 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WF]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/09/22/talking-wf/</guid>
		<description><![CDATA[WF (for the record: Windows Workflow Foundation) is great. If you need it, you really need it. If you have the engine and one workflow running, adding other workflows is no sweat at all. If your workflows are persisted, you won‘t have to care for shutdowns. If you carefully designed your workflow you can use [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=118&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>WF (for the record: <a target="_blank" href="http://wf.netfx3.com/">Windows Workflow Foundation</a>) is great. If you need it, you really need it. If you have the engine and one workflow running, adding other workflows is no sweat at all. If your workflows are persisted, you won‘t have to care for shutdowns. If you carefully designed your workflow you can use the graphical view for discussions with the user. If you set it up correctly, even errors can be handled by workflows.</p>
<p>Well, WF is great. But there certainly are a lot of &#8220;if&#8221;s here&#8230;</p>
<p>I was at the <a target="_blank" href="http://www.microsoft.com/pdc">PDC 05</a> where Microsoft introduced the WWF (later to be renamed to WF due to some concerned <a target="_blank" href="http://en.wikipedia.org/wiki/World_Wildlife_Fund">Pandas</a> <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ) as THE big surprise. But I had to wait until earlier this year to get my &#8220;production hands&#8221; on it. Curiously that happened more or less simultaneously in more than one project. And curiously, despite the different nature of the task at hand they turned out to be very similar. Similar in terms of the problems, similar in terms of the pitfalls, similar in terms of the solutions. And also very similar in the demand for knowledge of things that are not WF specific but are far from common knowledge for the average developer&#8230; (and with that I mean the average knowledge areas, not developers of average knowledge&#8230; did that make sense? I have no intention to disqualify someone for <em>not </em>knowing all the stuff that‘s following!)</p>
<p>Curiously^3 while there is so much information available about WF—hosting, data exchange, and what else—it still did not answer our questions. I rather got the impression that my problems were largely ignored. Or if they were mentioned it stopped right there. &#8220;Here is something you will have to think about!&#8221; Period. &#8220;You should use XY.&#8221; Period. &#8220;That will be a problem.&#8221; Period.</p>
<p>So I had to rely on my BizTalk background to fill the gaps (and my knowlegde about multithreading even goes back to <a target="_blank" href="http://en.wikipedia.org/wiki/OS/2">OS/2</a>, sic! Am I in danger of becomming a dinosaur?). In the following posts I will dig in one or the other topic and some of the &#8220;best practices&#8221; (if it can be called that) we came about with, which might help the next developer.</p>
<p><a href="http://ajdotnet.files.wordpress.com/2007/09/vacation.jpg"><img border="0" align="right" width="159" src="http://ajdotnet.files.wordpress.com/2007/09/vacation-thumb.jpg?w=159&#038;h=240" alt="vacation" height="240" style="border:0;margin:0 0 5px 5px;" /></a>But for now let‘s just lay out the example application:</p>
<p>At <a target="_blank" href="http://www.sdx-ag.de">SDX</a> people work for various customers, usually on-site. If I would like to go to vacation I might have something to say about the matter myself. So does the customer. So does my account manager. And the back office. And&#8230; you get the idea. To manage that you need an informal workflow at least, once the head count of your company goes up you need it formalized. And this is what our example application (let‘s call it <em>Vacations@SDX</em>) does:</p>
<ul>
<li>Show me how many vacation days I have left.</li>
<li>Let me request a new vacation.</li>
<li>Let all people concerned with my vacation have their say.</li>
<li>If everyone involved acknowledged the vacation write the information to the payroll application.</li>
</ul>
<p>Of course since most people are mostly out of office, the application has to be a web application, the workflow long running, and notifications done by email. And the payroll application could be offline. And most importantly: DON‘T MESS WITH MY VACATION! Losing my request somewhere along the way simply WON‘T DO!</p>
<p>Nothing special here at all. Some kind of document review, order processing, or whatever workflow would have similar demands. Actually this is a very simple real world example. And yet, if done correctly it is a far from simple undertaking. Certainly it is not as simple as drawing a workflow and hooking up the basics as described in the available documentation.</p>
<p>On the list of things to talk about is workflow instance state, workflow communication, hosting, and error handling. This will be fairly basic stuff from an &#8220;architectural&#8221; point of view, but I will assume that you know or read up about the WF basics. I‘m not going to repeat the dozen lines of code it takes to host WF in a console application.</p>
<p>If that sounds interesting for you, stay tuned.</p>
<p><font color="#008000">That’s all for now folks,<br />
<strong>AJ.NET</strong></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/118/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/118/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/118/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=118&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/09/22/talking-wf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/09/vacation-thumb.jpg" medium="image">
			<media:title type="html">vacation</media:title>
		</media:content>
	</item>
		<item>
		<title>IDisposable reloaded</title>
		<link>http://ajdotnet.wordpress.com/2007/09/12/idisposable-reloaded/</link>
		<comments>http://ajdotnet.wordpress.com/2007/09/12/idisposable-reloaded/#comments</comments>
		<pubDate>Wed, 12 Sep 2007 16:01:45 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/09/12/idisposable-reloaded/</guid>
		<description><![CDATA[One of my last posts was about IDisposable. (Well regarded by the way, thanks for the feedback ) I should have thougt that covered the topic, but actually there are a few things I missed. And some of them certainly should be mentioned in &#8220;The Last Article about IDisposable&#8220;. Reference: [FDG] Framework Design Guidelines, Cwalina, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=115&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of my <a href="http://ajdotnet.wordpress.com/2007/05/28/idisposable-1-2-3/">last posts</a> was about <em>IDisposable</em>. (Well regarded by the way, thanks for the feedback <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ) I should have thougt that covered the topic, but actually there are a few things I missed. And some of them certainly should be mentioned in &#8220;<em>The Last Article about IDisposable</em>&#8220;.</p>
<p>Reference: [FDG] <a target="_blank" href="http://www.amazon.com/Framework-Design-Guidelines-Conventions-Development/dp/0321246756/ref=pd_bbs_sr_1/104-6419979-7190334?ie=UTF8&amp;s=books&amp;qid=1189275228&amp;sr=8-1">Framework Design Guidelines</a>, Cwalina, Abrams </p>
<p><strong>To IDispose or not to IDispose?</strong></p>
<p>A friend recently asked me &#8220;I hear you, but when should I actually implement IDisposable?&#8221;. Couriously my own answer didn&#8217;t convince me then. Now I&#8217;ll try better&#8230;</p>
<p>From the disposable pattern point of view there are only two relevant kinds of resources:</p>
<ol>
<li>unmanaged resources (i.e. not managed by the CLR)</li>
<li>managed, disposable resources (i.e. classes implementing <em>IDisposable</em>)</li>
</ol>
<p>Regarding unmanaged resources: When are you actually dealing with unmanaged resources? Well, talk about COM interop or P/Invoke and Win32 handles. In these cases I would have a look at the the <em>SafeHandle</em> class. This class does all and more of what any of us could think of. Once the resource is properly wrapped, I deal only with the wrapper which is a managed disposable ressource. Done.</p>
<p>That was easy, wasn&#8217;t it? Although unmanaged resources are the canonical justification for the <em>IDisposable </em>pattern (and finalizers for that matter), most developers rarely if ever deal with them directly. Database connection? <em>DbConnection</em> is a managed class. File handle? <em>System.IO.File</em> likewise.</p>
<p>Now for managed resources. When should you implement IDisposable? [FDG] gives two guidelines that in my opinion provide a <em>nearly </em>sufficient answer, thus I added a third one:</p>
<ul>
<li>DO implement <em>IDisposable </em>on types containing instances of disposable types. In other words &#8220;aggregation&#8221; is the keyword.</li>
<li>CONSIDER implementing <em>IDisposable </em>if the type is likely to have subtypes that might contain disposable types.</li>
<li>My own addition to that: CONSIDER implementing <em>IDisposable </em>if you lay some kind of infrastructure &#8230; (see <a href="http://ajdotnet.wordpress.com/2007/05/28/idisposable-1-2-3/">my last post</a> for an example).</li>
</ul>
<p>The first guideline is probably the most common case. And it has a pitfall. It says &#8220;instances of disposable types&#8221;, not &#8220;fields of disposable types&#8221;. There &#8220;Does any of the data members of my class have a type that implements IDisposable?&#8221; is actually the wrong question to ask! All the data member declaration tells you is the type of the data member; not the type of the instance it holds. Therefore the correct question would be &#8220;<em>May </em>any of the instances the data members of my class reference implement IDisposable?&#8221;. So take a hard look at your members of type <em>object </em>or any interface or base classes that would fall under the second guideline.</p>
<p><strong>To finalize or not to finalize?</strong></p>
<p>Most if not all articles about <em>IDisposable </em>present the pattern the way I did: Have the <em>IDisposable.Dispose</em> method call a virtual method <em>Dispose(bool)</em>, have the finalizer call the same method. But [FDG] takes a different approach:</p>
<ol>
<li>The &#8220;<em>Basic Dispose Pattern</em>&#8221; only takes the <em>IDisposable </em>interface into account and effectively addresses managed resources. It does not include the finalizer!</li>
<li>The &#8220;<em>Finalizable Types</em>&#8221; pattern acts as extension to the former, it adds the finalizer and deals with unmanaged resources.</li>
</ol>
<p>The rationale for the basic dispose pattern? Well, why call the<em> Dispose(bool) </em>method from a finalizer if no unmanged ressource has to be freed? (And remember that you are not allowed to touch managed resources in the finalizer, as they might already be finalized.) Why pay for the finalizer and add the runtime effort (maintaining the object in the finalization queue) that comes with it in the first place?</p>
<p>At first I had some severe concerns (basically about the increased complexity and the implied risk of missing finalizers) and was inclined to contradict people like Herb Sutter <img src='http://s1.wp.com/wp-includes/images/smilies/icon_redface.gif' alt=':oops:' class='wp-smiley' />  . But actually it really simplifies the picture. The two kinds of resources mentioned above actually match the guidelines:</p>
<ul>
<li>Unmanaged resources: <em>SafeHandle</em> implies (and goes beyond) &#8220;<em>Finalizable Type</em>&#8220;.</li>
<li>Managed ressouces: &#8220;<em>Basic Dispose Pattern</em>&#8221; and <em>no </em>finalizer!</li>
</ul>
<p>The implication is interesting: No need for you to ever write a finalizer!</p>
<p>But Wait! What about these cases:</p>
<ul>
<li>[FDG] also talks about &#8220;resources that need to be freed explicitely and that do not have finalizers&#8221;.<br />
In other words: unmanaged resources (already covered) or managed resources that are probably not implemented correctly (which rather needs a bugfix or workaround).</li>
<li>My initial concern: Having a class that implements <em>IDisposable </em>and at the same time omits the finalizer would be something unexpected and a surprise for most developers. So what if a derived class suddenly needed the finalizer and the developer wrongly assumed it was already there?<br />
The reason to need a finalizer would have to be an unmanaged resource. This calls for a wrapper class (e.g. <em>SafeHandle</em>) which in turn contradicts the use case.</li>
<li>What about classes that already implement a finalizer (and don&#8217;t have to)?<br />
Don&#8217;t worry. If it does the right thing it does nothing. So why bother?</li>
</ul>
<p>Because it is rather unexpected, I&#8217;d like to emphasise the corollary: If you rely on <em>SafeHandle </em>or some similar wrapper class, you&#8217;ll never need to provide a finalizer! (This appears to contradict most <em>IDisposable </em>advice, including <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.idisposable.aspx">IDisposable Interface</a>.)</p>
<p><strong>Exceptions, exceptions, 5 cent each!</strong></p>
<p>When .NET was still fresh there was a guideline not to throw exceptions in finalizers, because they would kill the finalizer thread and prevent other finalizers from being called. Early versions also didn&#8217;t guarantee that finalizers would be called during shutdown. Today the situation is as follows:</p>
<ul>
<li>Objects will be finalized during shutdown by default (since .NET 1.0)</li>
<li>Exceptions will kill the process rather than the thread (since .NET 2.0). This really improves the situation, as the exception will not stay unnoticed (as before).</li>
<li>The guideline is that exceptions in finalizers should be limited to critical ones intendend to shut down the application. The guideline for <em>Dispose </em>is similar. ([FDG])</li>
<li>C# finalizers of derived classes will ensure that the finalizer of the base class is called even in the presence of an exception (see <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms998547.aspx#scalenetchapt05_topic11">Finalize and Dispose Explained</a>).</li>
</ul>
<p>The last point is interesting. If you open the code of a class that overrides the finalizer in Reflector and choose C# format it will look like this:</p>
<blockquote><p>~DerivedDisposableObject()<br />
{<br />
    <font color="#0000ff">this</font>.Dispose(<font color="#0000ff">false</font>);<br />
}</p></blockquote>
<p>The very same code in VB format however has a slightly different outfit:</p>
<blockquote>
<pre>Protected Overrides Sub <strong><a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://BlogTestLib:1.0.0.0/BlogTestLib.DisposableObject/Finalize()">Finalize</a></strong>()
    Try
        Me.<a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://BlogTestLib:1.0.0.0/BlogTestLib.BasicDisposableObject/Dispose(Boolean)">Dispose</a>(False)
    Finally
        MyBase.<a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Object/Finalize()">Finalize</a>
    End Try
End Sub</pre>
</blockquote>
<p>All very well, the compiler does the work for us (as long as you are a decent C# developer <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':grin:' class='wp-smiley' />  ). But there still is one gap to fill: What about overriding the <em>Dispose</em> Method? Don&#8217;t the same issues apply here? They do. And does the compiler handle that as well? No, it doesn&#8217;t. Are we lost then? No, we aren&#8217;t.</p>
<p>First of all, I&#8217;m telling you how to do it right <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  . Secondly, I convinced Microsoft to check whether you did follow my advice. There is a rule in FxCop and Code Analysis in Visual Studio respectively (CA2215:DisposeMethodsShouldCallBaseClassDispose). Take the following code snippet:</p>
<blockquote><p><font color="#0000ff">protected</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> Dispose(<font color="#0000ff">bool</font> disposing)<br />
{<br />
    <font color="#0000ff">if</font> (disposing)<br />
    {<br />
        <font color="#008000"><em>// free managed resources</em></font><br />
    }<br />
    <br />
    <font color="#008000"><em>// call base</em></font><br />
    <font color="#0000ff">base</font>.Dispose(disposing);<br />
}</p></blockquote>
<p>If you enable Code Analysis (I really wish this would be the default) it will generate the following warning:</p>
<blockquote><p>MSBUILD : warning : CA2215 : Microsoft.Usage : Change DerivedObject.Dispose(Boolean):Void so that it calls its base class Dispose method for all code paths. Place the call in a finally block to ensure that resources are cleaned up when an exception is raised.</p></blockquote>
<p>As it states, the correct version would be:</p>
<blockquote><p><font color="#0000ff">protected</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> Dispose(<font color="#0000ff">bool</font> disposing)<br />
{<br />
    <font color="#0000ff">try</font><br />
    {<br />
        <font color="#0000ff">if</font> (disposing)<br />
        {<br />
            <font color="#008000"><em>// free managed resources</em></font><br />
        }<br />
    }<br />
    <font color="#0000ff">finally</font><br />
    {<br />
        <font color="#008000"><em>// call base</em></font><br />
        <font color="#0000ff">base</font>.Dispose(disposing);<br />
    }<br />
}</p></blockquote>
<p>Actually this little gem can be found in the documentation (e.g. in <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/fs2xkftw(vs.71).aspx">Implementing a Dispose Method</a>), although rarely and never really advertised.</p>
<p><strong>To null or not to null?</strong></p>
<p>&#8220;Shouldn&#8217;t I set the data members to null?&#8221;. A question I got more than once in various incarnations.</p>
<p>So, just for the record: There is <em>no need </em>to set data members referencing disposable objects (or any object) to null. It does not help freeing resources and the garbage collector won&#8217;t work faster.<br />
It might still be a good idea to set data members referencing disposable objects to null after disposing them. Just as a safety net. </p>
<p><strong>Other stuff&#8230;</strong></p>
<p>Right about the same time I wrote my initial post, MS decided the topic is worth being adressed. There was an article on MSDN magazine in the <a target="_blank" href="http://msdn.microsoft.com/msdnmag/issues/07/07/CLRInsideOut/default.aspx">CLR Inside Out</a><em> </em>column. I have to say, *ahaem*, <font size="1">it&#8217;s not nearly as complete as my coverage</font>. But it mentions security and I got some hints on <em>SafeHandle</em> and <em>try/finally</em> in Dispose from it (the later one employed but not described, sic!).</p>
<p>Well, I hope THAT covers the topic. Or did I still miss something?</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/09/12/idisposable-reloaded/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/09/12/idisposable-reloaded/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/115/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/115/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/115/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=115&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/09/12/idisposable-reloaded/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/09/12/idisposable-reloaded/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>partial methods for partial developers</title>
		<link>http://ajdotnet.wordpress.com/2007/09/04/partial-methods-for-partial-developers/</link>
		<comments>http://ajdotnet.wordpress.com/2007/09/04/partial-methods-for-partial-developers/#comments</comments>
		<pubDate>Tue, 04 Sep 2007 18:19:37 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Software Developers]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/09/04/partial-methods-for-partial-developers/</guid>
		<description><![CDATA[The evolution of C# has all but stopped. One addition with .NET 2.0 was partial classes. Probably meant to ease the usage of code generators (keeping generated code separate from hand written code) the common developer is not limited to &#8220;consuming&#8221; it, he may also actively employ it. E.g. it might serve a puprose to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=114&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The evolution of C# has all but stopped. One addition with .NET 2.0 was partial classes. Probably meant to ease the usage of code generators (keeping generated code separate from hand written code) the common developer is not limited to &#8220;consuming&#8221; it, he may also actively employ it. E.g. it might serve a puprose to separate production code from debug code. With .NET 3.5 there already was much talk about the language additions around LINQ, such as &#8230; well, just have a look at <a target="_blank" href="http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx">The LINQ Project</a> or <a target="_blank" href="http://weblogs.asp.net/scottgu/archive/tags/LINQ/default.aspx">ScottGu&#8217;s Blog</a>. And of course, these features are <em>meant </em>to be actively employed by the common developer.</p>
<p>Now we have a relatively new addition: Partial methods. (In case you haven&#8217;t hread, see <a target="_blank" href="http://blogs.msdn.com/wesdyer/archive/2007/05/23/in-case-you-haven-t-heard.aspx">In Case You Haven&#8217;t Heard</a>, see <a target="_blank" href="http://blogs.msdn.com/vbteam/archive/2007/03/27/partial-methods.aspx">Partial Methods</a> for the VB.NET camp). With this addition I&#8217;m not so sure it&#8217;s meant for me&#8230; .</p>
<blockquote><p>For the record: A partial method is a method <em>declared </em>in a partial class (hence the name). It may or may not be <em>implemented </em>in the same class (usually in another file). If it is implemented, the compiler will emit usual code. If it is not implemented, the compiler will emit nothing, not even metadata about that method. And will will also wipe out any calls to the method.</p>
<p>Ergo: Partial methods are purely a compiler feature. You need the code of the declaring class and it has to be prepared with declarations to support partial method implementation.</p></blockquote>
<p>The usual (probably the only relevant) use case for partial methods is <strong>light weight event handling</strong> in combination with <strong>code generation</strong>. Say, you parse a database or an XML file and generate data classes. Tens of classes, hundreds of properties, all fairly generic, boilerplate stuff. And also fairly common is the need to interfere with this method for validation or that property setter to update another one. So instead of manipulating the generated code or having hundreds of events and thousands of method calls during runtime (of which in most cases only a tiny fraction will actually do something) partial methods kick in. They are easier to declare and use than events (pay for what you need) and if not used they simply vanish (pay as you go).</p>
<p>Any other relevant use case? None that I am aware of. In other words we have a language feature that is very efficient for a very limited number of use cases.</p>
<p><strong>For whom are partial methods made?</strong></p>
<p>Implementors of code generators are the ones to employ partial methods. Today this means Microsoft and LINQ related stuff, tomorrow Microsoft may decide to use partial methods in other event laden environments, such as ASP.NET and WinForms. In these cases the common developer only consumes partial methods. Let me re-phrase this: The common developer <em>has </em>to consume partial methods. Why? With partial methods the code generator will certainly not generate any other means of extension, such as events or virtual methods. The very purpose of partial methods is to do away with these heavy weight means, right?</p>
<p><u>The pro:</u> If you follow the designer driven, RAD style, code based development style that ASP.NET or WinForms used for quite some time, the designer will eventually handle partial methods transparently. The only difference for the common developer is that he knows the stuff he is doing will be more efficient at runtime.</p>
<p><u>The con:</u> If you like metadata driven applications (and already struggled with ASP.NET databinding because there is no way to attach meta data)&#8230; well, prepare for some further loss of information. If you need some event for any property setter (for tracing or tracking), if you need any kind of dynamic behaviour (e.g. to attach some kind of generic rules engine),  &#8230; let&#8217;s just hope the developer of the code generator anticipated that use case (or prepare for some work). You have a clean layer separation and the entities should know nothing about the UI? Well, put your code riht into the data class will spoil that. But hey, you might use partial methods to implement real events. Manually.</p>
<p>So you and I, the common developer that is, will not gain very much from this use case. But we will become more dependend on the ability, the mercy, and the foresight of the developers of the code generators and designers.</p>
<p>Will we be able to employ partial methods (rather than only consuming them)? Let&#8217;s see&#8230; when did I last write a class that had to support a vast amount of events? (That actually occasionally happens when I lay some infrastructure for the next project or work on framework code.) A class that was at the same time <em>not </em>intended to act as base class? (OK, forget about the infastructure!). But I surely wrote code by hand (because there was no code generator) that looks exactly like a candidate? But then I simply wrote the methods I needed, as I needed them &#8212; no need for a partial declaration.</p>
<p>So, unless I enter the camp of the not-so-common-code-generator-writing-developers (it happens, but only rarely), I can see no relevant use case that allows me to employ partial methods. (I really don&#8217;t count the example of increasing the readability conditional compilation &#8212; as presented in the VB post above &#8212; as relevant for a new language feature.)</p>
<p>Again, for whom are partial methods made? In my opinion they are made for Microsoft. To help them writing code generators that generate more efficient code. Code that conforms with the constant shift from object oriented (inheritance and virtual methods), component oriented (interfaces, events), metadata driven (attributes) development to a more and more exclusively used code generation approach. Highly efficient, but really not meant for me.</p>
<p>Do I have a better solution for the problem partial methods solve? I don&#8217;t. Therefore I can&#8217;t blame Microsoft for putting them in. Do I have concerns about how that will affect my work? I certainly do. Therefore I do hope the developers employing them do it with utmost caution. And with the awareness that not everyone uses their tools in a point-and-click kind of fashion.</p>
<blockquote><p>There already has been some concern about partial methods in the .NET community &#8212; and for other reasons than the ones I mentioned: Language complexity, naming issues, other features higher on the wish list, and so on. I recommend reading the comments of the post above if you want to keep up with that. Whether partial methods are a good idea or not, they are easily the single most controversial language feature in C# so far.</p></blockquote>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/09/04/partial-methods-for-partial-developers/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/09/04/partial-methods-for-partial-developers/" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/114/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/114/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/114/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=114&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/09/04/partial-methods-for-partial-developers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/09/04/partial-methods-for-partial-developers/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Happy birthday&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2007/07/08/happy-birthday/</link>
		<comments>http://ajdotnet.wordpress.com/2007/07/08/happy-birthday/#comments</comments>
		<pubDate>Sun, 08 Jul 2007 15:13:13 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/07/08/happy-birthday/</guid>
		<description><![CDATA[Happy birthday to you, Happy birthday to you, Happy birthday, dear http://ajdotnet.wordpress.com/ … Damn, that bulky name spoiled it. Yes, roughly a year ago I startetd this blog. When I began blogging I had no idea, how long it would take until I ran out of topics. Similarly I had no idea whether anybody would [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=113&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://en.wikipedia.org/wiki/Happy_Birthday_to_You"><img align="right" src="http://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/Birthday_cake.jpg/280px-Birthday_cake.jpg" style="margin:0 0 5px 5px;" /></a> Happy birthday to you,<br />
Happy birthday to you,<br />
Happy birthday, dear <a href="http://ajdotnet.wordpress.com/">http://ajdotnet.wordpress.com/</a> …</p>
<p>Damn, that bulky name spoiled it. <img src='http://s2.wp.com/wp-includes/images/smilies/icon_evil.gif' alt=':evil:' class='wp-smiley' /> </p>
<p>Yes, roughly a year ago I startetd this blog. When I began blogging I had no idea, how long it would take until I ran out of topics. Similarly I had no idea whether anybody would actually read my blog (apart from the few people I could force to <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':grin:' class='wp-smiley' />  ). And now I&#8217;m 55 posts, nearly 100 comments (some controversial), over 4000 spam comments, and more than 22000 views from all over the world (kind of) older. Seems somebody is actually interested in what I have to say&#8230; <img src='http://s0.wp.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> </p>
<p>The evergreen of my posts is certainly <a href="http://ajdotnet.wordpress.com/2006/07/17/aspnet-20-databinding-examined/">ASP.NET 2.0 DataBinding Examined</a>. Only moderately rated on <a target="_blank" href="http://www.dotnetkicks.com/aspnet/ASP_NET_2_0_DataBinding_Examined">dotnetkicks.com</a> it is constantly among the top 3 posts.<br />
<a href="http://ajdotnet.wordpress.com/2007/05/28/idisposable-1-2-3/">IDisposable – 1, 2, 3, …</a> on the other hand is the shooting star. No other post got that kind of feedback or went up that fast and high in <a target="_blank" href="http://www.dotnetkicks.com/csharp/IDisposable_1_2_3">rating</a>. Actually I find that a little curious because it &#8220;only&#8221; subsumes stuff that is available in the documentation.<br />
Not surprisingly, the little excursion into the <a href="http://ajdotnet.wordpress.com/2007/02/10/java-ee-rip/">java world</a> is among the least viewed posts.<br />
My personal favourite (and that of some people whose opinion I value) however is <a href="http://ajdotnet.wordpress.com/2006/10/28/frameworks-dont-let-em-frame-you/">Frameworks &#8211; don’t let ‘em frame you!</a>.</p>
<p>When I began blogging I also made a promise to myself that I would seriously reconsider writing this blog somewhere down the road. And since I&#8217;ve run out of topics lately anway, this is the perfect occasion. (This is not to say there <em>are </em>no topics. Actually I have been enganged in too many things at the same time during these last weeks, with not enough time to properly contemplate the ramifications.) </p>
<p>Well, if you&#8217;ve got any suggestions or general feedback (including &#8221;Stop pestering us!&#8221; &#8211; just phrase it politely ;-) ) this is your chance. Just don&#8217;t expect a quick answer, for I&#8217;ve earned my vacation <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/113/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/113/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/113/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=113&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/07/08/happy-birthday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/Birthday_cake.jpg/280px-Birthday_cake.jpg" medium="image" />
	</item>
		<item>
		<title>IDisposable &#8211; 1, 2, 3, &#8230;</title>
		<link>http://ajdotnet.wordpress.com/2007/05/28/idisposable-1-2-3/</link>
		<comments>http://ajdotnet.wordpress.com/2007/05/28/idisposable-1-2-3/#comments</comments>
		<pubDate>Mon, 28 May 2007 14:28:00 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/05/28/idisposable-1-2-3/</guid>
		<description><![CDATA[Note: See also the sequel IDisposable Reloaded&#8230; IDisposable is one of these beasts. Considered to be common knowledge and yet I regularly encounter code that simply ignores the demand. A well documented pattern and yet I occasionally stumble over improper usage of the pattern. And this is just the beginning; the finer details are lost [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=112&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: See also the sequel <a href="http://ajdotnet.wordpress.com/2007/09/12/idisposable-reloaded/">IDisposable Reloaded</a>&#8230;</p></blockquote>
<p><a target="_new" href="http://en.wikipedia.org/wiki/Waste_management"><img align="right" src="http://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Recycle001.svg/173px-Recycle001.svg.png" alt="recycle" style="margin:0 0 5px 5px;" /></a><em>IDisposable</em> is one of these beasts. Considered to be common knowledge and yet I regularly encounter code that simply ignores the demand. A well documented pattern and yet I occasionally stumble over improper usage of the pattern. And this is just the beginning; the finer details are lost more often than not.</p>
<p><strong>Calling IDisposable</strong></p>
<p><em>IDisposable</em>’s sole purpose is to free scarce or expensive resources quickly and cleanly. The usually mentioned examples are files, database connections, and unmanaged resources. Rarely mentioned is the fact that a class becomes an expensive resource by the very fact that it implements <em>IDisposable </em>(and asuming the pattern below is used, including the finalizer. If <em>Dispose()</em> is not called the object will survive one garbage collection, making it to the second generation and live longer than intended, blocking memory and requiring a more thorough GC to get freed.)</p>
<p>Therefore the advice is: <u>If it implements <em>IDisposable</em>, call it. Always! </u></p>
<p><strong>Basic implementation</strong></p>
<p>Implementing <em>IDisposable </em>is a well <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.idisposable.aspx">documented pattern</a> but it regularly is <em>not </em>observed properly. The gist is:</p>
<ol>
<li>Implement <em>IDisposable.Dispose()</em> to call a protected virtual method <em>Dispose(bool disposing)</em> with <em>true</em> and deregister the object from finalization (i.e. call <em><a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.gc.suppressfinalize.aspx">GC.SuppressFinalize(this);</a></em>)</li>
<li>Implement the <a target="_blank" href="http://en.wikipedia.org/wiki/Finalizer">finalizer</a> to call <em>Dispose(false)</em> as fallback, should the caller forget the call to <em>IDisposable</em>.</li>
<li>Implement <em>Dispose(bool)</em> to free managed resources if <em>disposing</em> is <em>true </em>and to always free unmanaged resources.</li>
</ol>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> DisposableObject: IDisposable<br />
{<br />
    ~DisposableObject()<br />
    {<br />
        Dispose(<font color="#0000ff">false</font>);<br />
    }<br />
    <br />
    <font color="#0000ff">public</font> <font color="#0000ff">void</font> Dispose()<br />
    {<br />
        Dispose(<font color="#0000ff">true</font>);<br />
        GC.SuppressFinalize(<font color="#0000ff">this</font>);<br />
    }<br />
    <br />
    <font color="#0000ff">protected</font> <font color="#0000ff">virtual</font> <font color="#0000ff">void</font> Dispose(<font color="#0000ff">bool</font> disposing)<br />
    {<br />
        <font color="#0000ff">if</font> (disposing)<br />
        {<br />
            <font color="#008000"><em>// free managed resources</em></font><br />
        }<br />
        <br />
        <font color="#008000"><em>// free unmanaged resources</em></font><br />
    }<br />
}</p></blockquote>
<p>If you implement <em>IDisposable</em> you have to follow this pattern. Period. And you do implement it if your class manages other resources, e.g. if it holds a file reference or some kind of unmanaged handle.</p>
<p>OK, up to here we’ve covered what I should hope to be common knowledge. But there is more. Not terribly complicated but things to consider anyway.</p>
<p><strong>Advanced patterns</strong></p>
<p>One decision to be made is how the object will behave after disposing it.</p>
<ol>
<li>It could be revived, e.g. a file could be reopened. In this case it should <em><a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.gc.reregisterforfinalize.aspx">GC.ReRegisterForFinalize();</a></em> to start all over.</li>
<li>The call could be oblivious, i.e. not care at all but also not providing the means to do anything with it (e.g. providing the necessary calls only as c’tors).</li>
<li>It could be unforgiving; in which case it would throw an <em><a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.objectdisposedexception.aspx">ObjectDisposedException</a></em>.</li>
</ol>
<p>Please note that the following classes build on the above example (i.e. <em>DisposableObject</em>).</p>
<p>Revivable object:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> RevivableObject : DisposableObject<br />
{<br />
    <font color="#0000ff">public</font> RevivableObject()<br />
    {<br />
        <font color="#008000"><em>// not yet&#8230;</em></font><br />
        GC.SuppressFinalize(<font color="#0000ff">this</font>);<br />
    }<br />
    <br />
    <font color="#0000ff">public</font> <font color="#0000ff">void</font> Open(<font color="#008000"><em>/*&#8230;*</em></font>/)<br />
    {<br />
        <font color="#008000"><em>// open the resource</em></font><br />
        <br />
        <font color="#008000"><em>// and make sure the GC knows about this</em></font><br />
        GC.ReRegisterForFinalize(<font color="#0000ff">this</font>);<br />
    }<br />
}</p></blockquote>
<p>Oblivious object: </p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> UseOnlyOnceObject : DisposableObject<br />
{<br />
    <font color="#0000ff">public</font> UseOnlyOnceObject(<font color="#008000"><em>/*&#8230;*</em></font>/)<br />
    {<br />
        <font color="#008000"><em>// open the resource only via c&#8217;tor</em></font><br />
    }<br />
    <br />
}</p></blockquote>
<p>Guarded object: Every method needs to call <em>AssertNotDisposed()</em> as precondition.</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> GuardedObject : DisposableObject<br />
{<br />
    <font color="#0000ff">bool</font> _disposed = <font color="#0000ff">false</font>;<br />
    <br />
    <font color="#0000ff">protected</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> Dispose(<font color="#0000ff">bool</font> disposing)<br />
    {<br />
        <font color="#0000ff">base</font>.Dispose(disposing);<br />
        _disposed = <font color="#0000ff">true</font>;<br />
    }<br />
    <br />
    <font color="#0000ff">protected</font> <font color="#0000ff">void</font> AssertNotDisposed()<br />
    {<br />
        <font color="#0000ff">if</font> (_disposed)<br />
            <font color="#0000ff">throw</font> <font color="#0000ff">new</font> ObjectDisposedException(GetType().FullName);<br />
    }<br />
    <br />
    <font color="#0000ff">void</font> Foo()<br />
    {<br />
        <font color="#008000"><em>// check preconditions</em></font><br />
        AssertNotDisposed();<br />
        <br />
        <font color="#008000"><em>// &#8230;</em></font><br />
    }<br />
}</p></blockquote>
<p><strong>Dispose and tell</strong></p>
<p>A fair number of classes do not only dispose themselves, they also tell about it &#8212; via a respective event (e.g. the <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.componentmodel.component.disposed.aspx">component class</a>.)</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> ObservableObject : DisposableObject<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">event</font> EventHandler Disposed;<br />
    <br />
    <font color="#0000ff">protected</font> <font color="#0000ff">virtual</font> <font color="#0000ff">void</font> OnDisposed(EventArgs ea)<br />
    {<br />
        <font color="#0000ff">if</font> (Disposed != <font color="#0000ff">null</font>)<br />
            Disposed(<font color="#0000ff">this</font>, ea);<br />
    }<br />
    <br />
    <font color="#0000ff">protected</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> Dispose(<font color="#0000ff">bool</font> disposing)<br />
    {<br />
        <font color="#0000ff">base</font>.Dispose(disposing);<br />
        OnDisposed(EventArgs.Empty);<br />
    }<br />
}</p></blockquote>
<p><strong>Object graphs</strong></p>
<p>Consider the following use case: You implement some kind of controller pattern for your web pages; the controller manages references to business services. A simple implementation would look like this:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">interface</font> IBusinessService<br />
{<br />
}</p>
<p><font color="#0000ff">public</font> <font color="#0000ff">class</font> Controller<br />
{<br />
    Dictionary&lt;string, IBusinessService&gt; _services= <font color="#0000ff">new</font> Dictionary&lt;string,IBusinessService&gt;();<br />
    <br />
    <font color="#0000ff">public</font> IBusinessService GetBusinessService(<font color="#0000ff">string</font> name)<br />
    {<br />
        IBusinessService ret= <font color="#0000ff">null</font>;<br />
        _services.TryGetValue(name, <font color="#0000ff">out</font> ret);<br />
        <font color="#0000ff">if</font> (ret == <font color="#0000ff">null</font>)<br />
        {<br />
            ret = CreateBusinessService(name);<br />
            _services[name] = ret;<br />
        }<br />
        <font color="#0000ff">return</font> ret;<br />
    }<br />
    <br />
    <font color="#0000ff">protected</font> <font color="#0000ff">virtual</font> IBusinessService CreateBusinessService(<font color="#0000ff">string</font> name)<br />
    {<br />
        <font color="#008000"><em>// create business service, e.g. using a factory</em></font><br />
        <font color="#0000ff">return</font> <font color="#0000ff">null</font>;<br />
    }<br />
}</p>
<p><font color="#0000ff">public</font> <font color="#0000ff">class</font> PageWithController: Page<br />
{<br />
    Controller _controller;<br />
    <br />
    <font color="#0000ff">public</font> Controller Controller<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> _controller; }<br />
    }<br />
    <br />
    <font color="#0000ff">protected</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> OnPreInit(EventArgs e)<br />
    {<br />
        _controller = CreateController();<br />
        <font color="#0000ff">base</font>.OnPreInit(e);<br />
    }<br />
    <br />
    <font color="#0000ff">protected</font> <font color="#0000ff">virtual</font> Controller CreateController()<br />
    {<br />
        <font color="#008000"><em>// create controller , e.g. using a factory</em></font><br />
        <font color="#0000ff">return</font> <font color="#0000ff">new</font> Controller();<br />
    }<br />
    <br />
}</p></blockquote>
<p>Now, what does that have to do with <em>IDisposable</em>? No disposable object is taking part in this sample, right?<br />
However this implementation lays the infrastructure to be used with <em>derived </em>classes, controllers as well as business services. And those derived classes may very well implement <em>IDisposable</em>, e.g. a business service holding a database reference. Should the implementor of that business service have to build the disposing infrastructure for that service? Or should the infrastructure anticipate that need and already be aware of <em>IDisposable</em>? Take that as rhetorical question and have a look at the corrections:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> Controller: GuardedObject<br />
{<br />
    <font color="#008000"><em>// code as above&#8230;</em></font><br />
    <br />
    <font color="#0000ff">protected</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> Dispose(<font color="#0000ff">bool</font> disposing)<br />
    {<br />
        <font color="#0000ff">if</font> (disposing)<br />
        {<br />
            DisposeHelper.DisposeElements(_services.Values);<br />
            _services = <font color="#0000ff">null</font>;<br />
        }<br />
        <font color="#0000ff">base</font>.Dispose(disposing);<br />
    }<br />
    <br />
}</p>
<p><font color="#0000ff">public</font> <font color="#0000ff">class</font> PageWithController: Page<br />
{<br />
    <font color="#008000"><em>// code as above&#8230;</em></font><br />
    <br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> Dispose()<br />
    {<br />
        DisposeHelper.Dispose(_controller);<br />
        _controller = <font color="#0000ff">null</font>;<br />
        <font color="#0000ff">base</font>.Dispose();<br />
    }<br />
}</p></blockquote>
<p>I leave the implementation of the <em>DisposeHelper </em>class to your imagination.</p>
<p>So, the advice in this case is: <u>If you for lay some kind of basic infrastructure, anticipate the usage of disposable objects and build an uninterrupted “dispose trail”.</u></p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/05/28/idisposable-1-2-3/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/05/28/idisposable-1-2-3/" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/112/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/112/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/112/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/112/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=112&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/05/28/idisposable-1-2-3/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Recycle001.svg/173px-Recycle001.svg.png" medium="image">
			<media:title type="html">recycle</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/05/28/idisposable-1-2-3/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>About the Virtue of Not Improving Performance</title>
		<link>http://ajdotnet.wordpress.com/2007/05/20/about-the-virtue-of-not-improving-performance/</link>
		<comments>http://ajdotnet.wordpress.com/2007/05/20/about-the-virtue-of-not-improving-performance/#comments</comments>
		<pubDate>Sun, 20 May 2007 16:11:07 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/05/20/about-the-virtue-of-not-improving-performance/</guid>
		<description><![CDATA[I am very much in favour of performance awareness, as previous posts should have shown (optimize it,  cache as cache can, performance is king, &#8230;), nobody question that. But I repeatedly stumble over advice that I find &#8230; questionable. So, with this post, I thought I might pick up some of the more common hints and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=111&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am very much in favour of performance <em>awareness</em>, as previous posts should have shown (<a href="http://ajdotnet.wordpress.com/2006/10/10/optimize-it/">optimize it</a>,  <a href="http://ajdotnet.wordpress.com/2006/10/18/cache-as-cache-can/">cache as cache can</a>, <a href="http://ajdotnet.wordpress.com/2006/10/03/performance-is-king-3/">performance is king</a>, &#8230;), nobody question that. But I repeatedly stumble over advice that I find &#8230; questionable.</p>
<p>So, with this post, I thought I might pick up some of the more common hints and tell you why you should <em>not </em>(have to) apply them for performance reasons. Yes, at the price of processor cycles. Here are some links that contain that advice (not the only ones, though):</p>
<ul>
<li>&#8220;<a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms998530.aspx">Improving .NET Application Performance and Scalability</a>&#8221; ff (refered to as msdn)</li>
<li>&#8220;<a target="_blank" href="http://www.codeproject.com/useritems/ASPNET_Best_Practices.asp">ASP.NET Best Practices for High Performance Applications</a>&#8220;</li>
<li>&#8220;<a target="_blank" href="http://www.codeproject.com/useritems/Application_Performance.asp">Tips to improve Performance of Web Application</a>&#8220;</li>
<li>&#8220;<a target="_blank" href="http://aspalliance.com/818">Improving Application Performance in .Net</a>&#8220;</li>
</ul>
<p>Please note that my statements are meant for developers of ordinary line-of-business or web-applications. If you write real time software controlling atomic plants, this article is not for you. (Neither is it for the guys at Microsoft working on the .NET Framework or SQL Server.)</p>
<p>Please also note that I left out things related to garbage collection and finalization on purpose.</p>
<p><u><strong>Optimization techniques that adversely affect class design</strong> </u></p>
<p>Some optimization techniques address the way the CLR is working and are aiming to help the JIT compiler to produce better (read “faster”) code.</p>
<p><strong>Consider Using the sealed Keyword.</strong> The rationale behind this recommendation is “Sealing the virtual methods makes them candidates for inlining and other compiler optimizations.” (msdn)</p>
<p>The only candiates for this advice are derived classes of your application. Declare them as sealed won’t hurt the class design. But won’t the virtual methods usually be called via the base class? No very much to gain then anyway. Then why bother?</p>
<p><strong>Consider the Tradeoffs of Virtual Members? </strong>Consider the Benefits of Virtual Members, I’d rather say! “Use virtual members to provide extensibility.” (msdn). One should avoid making a method virtual if it’s not intended to be overwritten. But that’s a question of class design and design for extensibility rather than a performance related one. Avoiding a virtual declaration for performance reasons? No way.</p>
<p>These are just examples, there is other advice, e.g. regarding <em>voilatile</em> or properties. All in all, I personally have dismissed this category of performance related advice. It’s either unnecessary (i.e. should be done for reasons far more important, like “know what you do and design things right”) or of adverse effect (like scarifying good design for small gains of performance).</p>
<p><strong><u>Optimization techniques that adversely affect code </u></strong></p>
<p>Some techniques aim at eliminating unnecessary repetitive calls:</p>
<ul>
<li>Avoid Repetitive Field or Property Access</li>
<li>Inline procedures, i.e. copy frequently called code into the loop.</li>
<li>Use <em>for </em>loops rather than <em>foreach </em></li>
</ul>
<p>These … <em>hints</em>… are what I call developer abuse. Wasn’t <a target="_blank" href="http://en.wikipedia.org/wiki/Inlining">inlining</a>, <a target="_blank" href="http://en.wikipedia.org/wiki/Loop_unrolling">loop unrolling</a> and detection of <a target="_blank" href="http://en.wikipedia.org/wiki/Loop-invariant_code_motion">loop invariants</a> one of the better known optimization techniques of C++ compilers? And now I shall do that manually? “Optimizing compiler” is not part of my job description, sorry.</p>
<p><u><strong>String optimization</strong> </u></p>
<p>My special attention goes to … Mr. String. Mr. String, could you please come up to the stage… Applause for Mr. String!</p>
<p><strong><em>StringBuilder </em>abuse, i.e. forgetting about +/<em>String.Concat/String.Format, </em></strong>is very common. Take the following code snippet as example:</p>
<blockquote><p><font color="#0000ff">string</font> t1 = a + b + c + d;<br />
<font color="#0000ff">string</font> t2 = e + f;<br />
<font color="#0000ff">string</font> t3 = t1 + t2;<br />
<font color="#0000ff">return</font> t3;</p></blockquote>
<p>Quite complex, don&#8217;t you think? Wouldn&#8217;t you be using a <em>StringBuilder </em>instead? NO! Don&#8217;t fall or that <em>StringBuilder</em> babble. I cannot say that all the given advice is wrong; it just plainly forgets to mention <em>String.Concat</em> too often and leads one to a wrong impression.</p>
<p>How many temporary strings do you count? 3? (t1, t2, and t3) Or 5? (a+b put into a temporary, in turn added to c.) Well, the answer is 3, as the c# compiler will translate all appearances of + in one single expression into one call to <em>String.Concat</em>. If you have a straight forward string concatenation use + (but use it in one expression!). If it gets slightly more complex, using <em>String.Format</em> (which uses <em>StringBuilder.AppendFormat </em>internally) might be another option.</p>
<p>Use <em>StringBuilder </em>if you have to accumulate string contents over method calls, iterations, or recursions. Use it if you cannot avoid multiple expressions for your concatenation and to avoid memory shuffling. And please read “Treat StringBuilder as an Accumulator” (msdn) in order not to spoil the effect.</p>
<p><strong><u>ASP.NET related things</u></strong></p>
<p>My favourite category <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>Disable Session State If You Do Not Use It. </strong>That’s sound advice. You may do that for the application. But don’t do it just for one page. If you need session state, chances are you need it for all pages. That particular page is the exception? Well, it can’t be doing very much then and disabling it will hardly improve the performance of your application very much. If you stumble over it go ahead, but don’t waste your time looking for these pages. Spend that time on the majority of your pages that actually need session state; spend it on managing session state efficiently. This way your whole application will profit.</p>
<p><strong>Disable View State If You Do Not Need It. </strong>Don’t. You don’t want to do it for the page, as view state is a feature of the controls. You don’t want to do it declaratively for the controls, for that is tedious and error prone work. And you certainly don’t want to do it for every control, for some of them rely in view state to work correctly.<br />
Managing view state is the sensible approach. Find ways to avoid sending large view states back and forth to the client. Check if there is unintended view state usage. The view state is small? Well, why bother? Empty view state is not that expensive. If you worry about that, use derived controls that switch view state off by default.</p>
<p><strong>Using Server.Transfer to avoid the roundtrip caused by Response.Redirect </strong>is a bit like penny-wise but pound-foolish. The user requests page A but you decide he should see page B. Rather than letting him know that you just gave him what he did not ask for. If he does a page refresh (not to mention setting a bookmark), you will always get a request for page A and always have to transfer to page B. But rest assured, the last transfer definitely is more efficient than redirecting. Oh, and by the way, you just lied to the user. Telling him he is on the <em>Get_This_Gift_For_Free.aspx </em>page when he actually was on the <em>Buy_Overpriced_Stuff_You_Dont_Need.aspx </em>page. Interesting business model, though.</p>
<p><strong>Use Response.Redirect(&#8230;, false) instead of Response.Redirect(&#8230; [, true]). </strong>Now that’s an example of a half understood issue being made a common recommendation. (Am I becoming polemic? Sorry, could not resist <img src='http://s2.wp.com/wp-includes/images/smilies/icon_evil.gif' alt=':evil:' class='wp-smiley' />  .)<br />
<em>Redirect </em>throws a <em>ThreadAbortException</em>. &#8220;An exception! &#8211; Oh my, what can we do about that?&#8221; &#8220;Oh, don’t worry, we can go through all the data binding, page rending, event handling, and whatever else is left of the page life cycle, we will fight any opponent, such as this perkily grid control that refuses to bind against null. And at the end of the day we will have slain the dragon and it won’t fly again.&#8221; OK, now I <em>am </em>being polemic. Anyway. The problem with <em>not </em>throwing the exception should have become clear. If you want to avoid that, try to do it client side.</p>
<p><strong><u>What to conclude?</u></strong></p>
<p>Now I’m going to contradict myself: None of the above advice is actually wrong (well, &#8230;). Not if you look only on performance in terms of processor cycles. But they are far too expensive in terms of brain cycles and won’t get you the benefit you expect. They trade small gains in performance for adversely affected design, workload on the developers side and additional chances for errors. And they are far too fine grained and restricted to the code level to matter all that much. Usually the interaction patterns between different components or the chosen algorithms have more impact. Not the virtual call to that method, but this non-virtual, non-suspicious method that is called 500 times during one request. Not the fact that 5 strings are concatenated with +, but the fact that those strings result from 10 database calls.</p>
<p>I&#8217;m contradicting myself even further: I didn&#8217;t say, don’t do it at all. I said don’t do it for performance reasons. There may be other reasons to follow the advice. (E.g. I would “Avoid Repetitive Field or Property Access” in order to have more comprehensible code, code that better supports debugging sessions. “Consider the Tradeoffs of Virtual Members” is no bad advice either.)</p>
<p>If you want to follow some rule upfront, I strongly recommend a sound design and understanding of what you do. And once you’ve got past the broad scenarios, let the profiler tell you what parts of your application to optimize. This way you will spend the work where it matters.</p>
<p>Oh, by the way: Please note that I did not reject every advice. There is a lot of good advice which tells you how to improve performance simply by writing good code (in terms of design, readability, etc.). And quite a few hints for doing things efficiently without adverse effects. Just don’t do it blindly.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/05/20/about-the-virtue-of-not-improving-performance/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/05/20/about-the-virtue-of-not-improving-performance/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/111/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/111/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/111/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=111&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/05/20/about-the-virtue-of-not-improving-performance/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/05/20/about-the-virtue-of-not-improving-performance/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Javascript and ASP.NET</title>
		<link>http://ajdotnet.wordpress.com/2007/05/12/javascript-and-aspnet/</link>
		<comments>http://ajdotnet.wordpress.com/2007/05/12/javascript-and-aspnet/#comments</comments>
		<pubDate>Sat, 12 May 2007 14:03:17 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/05/12/javascript-and-aspnet/</guid>
		<description><![CDATA[ASP.NET was never a pure server side framework. Right from Version 1.0 it employed scripts for client side validation. Back then it was meant to&#8230;, well set IE users apart, because it worked only as improvement for them. Complementing one&#8217;s own server controls with script was the champions league of ASP.NET development &#8212; and deployment [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=109&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>ASP.NET was never a pure server side framework. Right from Version 1.0 it employed scripts for client side validation. Back then it was meant to&#8230;, well set IE users apart, because it worked only as improvement for them. Complementing one&#8217;s own server controls with script was the champions league of ASP.NET development &#8212; and deployment of these controls was a paint in the&#8230; (children around? Sorry!)</p>
<p>Anyway, much is changing in this area. With ASP.NET 2.0 Microsoft has introduced the <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.web.ui.webresourceattribute.aspx">WebResourceAttribute</a> to adress the deployment problem. (See <a target="_blank" href="http://weblogs.asp.net/dwahlin/archive/2007/04/29/creating-custom-asp-net-server-controls-with-embedded-javascript.aspx">Creating Custom ASP.NET Server Controls with Embedded JavaScript</a> for a better example.) Ajax is doing away with the browser dependency issues and Microsoft has changed its attitude accordingly, resulting in cross browser capabilities in <a target="_blank" href="http://ajax.asp.net/docs/">ASP.NET AJAX</a>.</p>
<p>There is still some work to do to better integrate server side and client side coding model. The <a target="_blank" href="http://ajax.asp.net/ajaxtoolkit/">ASP.NET AJAX Control Toolkit</a> uses some patterns to better handle scripts (via the <em>RequiredScriptAttribute</em>, though not documented) and to address client side properties and events. Supporting postbacks and server side events is still a little awkward, though.</p>
<p>One thing is for sure: With <a target="_blank" href="http://ajax.asp.net/docs/">ASP.NET AJAX</a> Microsoft is taking ASP.NET control development as well as scripting to the next level (if only of complexity). If you&#8217;ve coded controls using script before, this is a good thing for you. Or it will render your patterns obsolete, who knows. If you&#8217;ve only scratched scripting yet, well, prepare for some work. Javascript is <a target="_blank" href="http://msdn.microsoft.com/msdnmag/issues/07/05/JavaScript/default.aspx">not as easy at is seems</a> and <a target="_blank" href="http://ajax.asp.net/docs/">ASP.NET AJAX</a> definitely pushes the limits.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/05/12/javascript-and-aspnet/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/05/12/javascript-and-aspnet/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/109/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/109/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=109&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/05/12/javascript-and-aspnet/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/05/12/javascript-and-aspnet/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>(Framework) Extension Points</title>
		<link>http://ajdotnet.wordpress.com/2007/05/05/framework-extension-points/</link>
		<comments>http://ajdotnet.wordpress.com/2007/05/05/framework-extension-points/#comments</comments>
		<pubDate>Sat, 05 May 2007 20:19:24 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/05/05/framework-extension-points/</guid>
		<description><![CDATA[The web applications I usually build cannot do without session state. Remember that user choice, get complex parameters to the next page, hold this business object until the user finally says &#8220;I&#8217;m done, save it&#8221;. Session state on the other hand has a poor interface and a big potential for trouble. I therefore usually use a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=108&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The web applications I usually build cannot do without session state. Remember that user choice, get complex parameters to the next page, hold this business object until the user finally says &#8220;I&#8217;m done, save it&#8221;.</p>
<p>Session state on the other hand has a poor interface and a big potential for trouble. I therefore usually use a utility class rather than accessing the <em>Session </em>object directly. Call it <em>SessionData</em>, and it&#8217;s implemented as a singleton. <em>SessionData </em>would add serveral features, such as type safe getters/setters; optimizations for default values; checking the serializability of the objects to prevent the serialization problem (I may have mentioned it <a href="http://ajdotnet.wordpress.com/2007/03/03/bury-in-proc-session-state/">once</a> or <a href="http://ajdotnet.wordpress.com/2007/03/17/get-view-state-off-__viewstate/">twice</a>); getting some statistics about objects in state (number and size). You get the idea. Fairly generic stuff and a good candidate for the next project.</p>
<p>Then I usally add named properties for the project specific session data. And kiss reusability good bye. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':sad:' class='wp-smiley' /> </p>
<p>Well, I could use another utility class. Another <em>complementary </em>one? No way.<br />
I could derive from <em>SessionData</em> and use is as replacement. Grand idea. But what about my other generic code that may want to access the session state? How would it know about my derived class?</p>
<p>This is a quite common problem for framework developers. Frameworks need means for the user to change or extend their standard behaviour. This usually includes callbacks, events, and virtual methods. In most cases this relies on the ability to run your own code (e.g. to create your instance or to register your calllback) before the change takes effect. If you have a class that overrides a virtual method, someone has to instantiate your derived class. This someone (or rather the first in line) is usually framework code. Code that needs to know the class it instantiates. Code that has no knowledge of your code. Unless you use a <em>factory</em>.</p>
<p>There are two related patterns that allow a framework to work with user code right from the beginning:</p>
<ul>
<li><strong>Provider pattern</strong>: used to register a provider class/object that offers some service (e.g. translation) but that does not necessarily have to exist and does not have a default implementation</li>
<li><strong>Class substitution</strong>: used to replace standard behaviour with customized versions (e.g. session state handling). If it is not replaced, a default implementation will kick in. </li>
</ul>
<blockquote><p>Please note that the pattern names are (c) by AJ.NET. I made them up, so you may come across different names. The license to use the names is fairly simple: You may use them freely. But if you do I want you to stand up and say &#8220;I used this word with permission by AJ.NET.&#8221; <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':grin:' class='wp-smiley' /> </p></blockquote>
<p><strong>Provider pattern </strong></p>
<p>The provider pattern is actually quite simple:</p>
<ul>
<li>Some (singleton) object provides access to the actual provider. It uses the factory to instatiate the concrete implementation and handles the case that no provider implementation exists.</li>
</ul>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> TranslationProvider<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> ITranslationProvider Current <br />
    {<br />
        <font color="#0000ff">get</font><br />
        { <br />
<font color="#008000"><em>            // use factory to create the instance</em></font><br />
            <font color="#0000ff">if</font> (_current == <font color="#0000ff">null</font>) <br />
                _current= (ITranslationProvider)Factory.Current.Create(„ITranslationProvider“);<br />
            <font color="#0000ff">return</font> _current;<br />
        }<br />
    }</p></blockquote>
<blockquote><p><font color="#0000ff">&lt;</font><font color="#800000">object</font> <font color="#ff0000">name</font><font color="#0000ff">=“ITranslationProvider“</font> <font color="#ff0000">type</font><font color="#0000ff">=“AJ.Application.Providers.AppTranslationProvider,</font> <font color="#0000ff">AJ.Application.Providers“</font> <font color="#0000ff">/&gt;</font></p></blockquote>
<p>The calling code can ask for the provider and would do nothing if none is present.</p>
<p><strong>Class substitution </strong></p>
<p>Other than the provider pattern, class substitution needs a fully functional default implementation. However it provides the means to replace this standard implementation with a tailored version.</p>
<ul>
<li>A class provides the default implementation</li>
<li>Some (singleton) object provides access to the actual instance. It uses the factory to instantiate the concrete implementation and makes sure the standard implementation is used if no other implementation is available.</li>
</ul>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> SessionData<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> SessionData Current<br />
    {<br />
        <font color="#0000ff">get</font><br />
        {<br />
<font color="#008000"><em>            // use factory to create the instance</em></font><br />
            <font color="#0000ff">if</font> (_current == <font color="#0000ff">null</font>)<br />
                _current = (SessionData)Factory.Current.Create(<font color="#0000ff">typeof</font>(SessionData).FullName);<br />
<font color="#008000"><em>            // fall back to default implementation</em></font><br />
            <font color="#0000ff">if</font> (_current == <font color="#0000ff">null</font>)<br />
                _current = <font color="#0000ff">new</font> SessionData();<br />
            <font color="#0000ff">return</font> _current;<br />
        }<br />
    }<br />
}</p></blockquote>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> AppSessionData : SessionData<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">new</font> AppSessionData Current<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> (AppSessionData)SessionData.Current; }<br />
    }<br />
    <font color="#0000ff">public</font> Guid CurrentSelection<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> <font color="#0000ff">base</font>.GetString(<font color="#800000">&#8220;CurrentSelection&#8221;</font>, <font color="#0000ff">string</font>.Empty); }<br />
        <font color="#0000ff">set</font> { <font color="#0000ff">base</font>.SetString(<font color="#800000">&#8220;CurrentSelection&#8221;</font>, <font color="#0000ff">value</font>, <font color="#0000ff">string</font>.Empty); }<br />
    }<br />
}</p></blockquote>
<blockquote><p><font color="#0000ff">&lt;</font><font color="#800000">object</font> <font color="#ff0000">name</font><font color="#0000ff">=“AJ.Framework.Providers.SessionData“</font> <font color="#ff0000">type</font><font color="#0000ff">=“AJ.Application.Providers.AppSessionData,</font> <font color="#0000ff">AJ.Application.Providers“</font> <font color="#0000ff">/&gt;</font></p></blockquote>
<p>Now the custom type gets created and can be accessed as <em>AppSessionData.Current</em>. While this class offers type safe access to specific session data it is still guaranteed that the framework code accessing session state will use the very same object to do so. And if <em>AppSessionData </em>changed the behaviour of certain methods (e.g. add traces), user code as well as framework code would participate in this change.</p>
<p>BTW: Did you notice? Even the factory is not called directly, rather it uses the class substitution pattern.</p>
<p>This post concludes this little series about factories. Technically I probably didn&#8217;t solve very complex issues. Use a factory, work against interfaces, or in the case of class substitution against a base class. That&#8217;s about it. The value that goes beyond a technical approach is realized by the patterns: layer separation, mock object support, interception, and extension.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/05/05/framework-extension-points/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/05/05/framework-extension-points/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/108/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/108/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=108&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/05/05/framework-extension-points/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/05/05/framework-extension-points/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>InFactoring the Architecture</title>
		<link>http://ajdotnet.wordpress.com/2007/04/29/infactoring-the-architecture/</link>
		<comments>http://ajdotnet.wordpress.com/2007/04/29/infactoring-the-architecture/#comments</comments>
		<pubDate>Sun, 29 Apr 2007 12:45:40 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/04/29/infactoring-the-architecture/</guid>
		<description><![CDATA[As already mentioned the I use a factory within an application architecture as a means for layer separation. The „Layer“ in &#8220;layer separation&#8221; refers to the omnipresent 3-tier, 3+-tier, multi-layer, what-ever-you-call-it-layer approach that is used in one or the other incarnation for todays web applications and services. Let’s assume the most basic incarnation for a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=106&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As already <a href="http://ajdotnet.wordpress.com/2007/04/13/the-factory-factor/">mentioned</a> the I use a factory within an application architecture as a means for layer separation. The „Layer“ in &#8220;layer separation&#8221; refers to the omnipresent <a target="_blank" href="http://en.wikipedia.org/wiki/Three-tier_%28computing%29">3-tier, 3+-tier, multi-layer, what-ever-you-call-it-layer approach</a> that is used in one or the other incarnation for todays web applications and services. Let’s assume the most basic incarnation for a web application, i.e. 3 classical layers.</p>
<p>I described the understanding of the term &#8220;factory&#8221; in my <a href="http://ajdotnet.wordpress.com/2007/04/21/building-the-factory/">last post</a>, now let&#8217;s see how to employ it.</p>
<p><strong>The architecture</strong></p>
<p>I‘ll spare you (and me) the boring picture of three blocks sitting on top of each other. Curiously no application is built purely this way, anyway. But let’s go ahead and structure the core layers and add the necessary vertical layers.</p>
<p><img src="http://ajdotnet.files.wordpress.com/2007/04/architecture.gif" alt="architecture.gif" style="margin:0 10px 0 0;" /></p>
<p>Still very simple. Just for the bookkeeping: “Presentation” stands for the Web Application (the bunch of config files, .aspx files, .css files, etc.) and I assumed some kind of MVC (or related) pattern for the UI layer, implemented in the &#8220;Controller&#8221; block.<br />
“Data Structures” contains the [<em>please fill in your favourite choice of Data Sets, Value Objects, Entity Objects, or in whatever shape your data flows across the data layer, business layer, and presentation layer</em>].<br />
“Utils &amp; Factory” contains orthogonal services, e.g. helper classes, tracing, error handling, and &#8211; hey! &#8211; our factory would reside here.</p>
<p><strong>The factory</strong></p>
<p>Let&#8217;s stress the fact that the business layer and the data access layer have a small interface block. This block is meant to be the only visible part of the respective layer. No bypassing allowed! Thinking of code, this part would be made out of C# interfaces and layer specific exceptions (VB.NET? No, sorry, you can&#8217;t do that in VB <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ). The implementation block of the layer contains the actual implementation classes and whatever else is needed.</p>
<p>The interface blocks are also the place where the factory enters the stage: The calling layer will never access these implementation classes directly, in fact it should not even know them. Rather it will ask the factory for an object that supports one particular interface. The factory will create the respective object and return it. E.g. the presentation layer would access some kind of customer information like this:</p>
<p>1. The business layer defines a customer service interface and a correponding implementation (within the respective blocks.</p>
<p>2. The business service is registered to be used by the factory with the type name of the interface as key:</p>
<blockquote><p><font color="#0000ff">&lt;</font><font color="#800000">typeNames</font><font color="#0000ff">&gt;</font><br />
    <font color="#0000ff">&lt;</font><font color="#800000">add</font><br />
        <font color="#ff0000">key</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;SDX.MyApp.Business.Contract.ICustomerService&#8221;<br />
    </font><font color="#ff0000">    value</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;SDX.MyApp.Business.Components.CustomerService, SDX.MyApp.Business.Components&#8221;</font> <font color="#0000ff">/&gt;<br />
</font>    &#8230; <br />
<font color="#0000ff">&lt;/</font><font color="#800000">typeNames</font><font color="#0000ff">&gt;</font> </p></blockquote>
<p>3. The presentation code uses the factory to gain access to the business service: </p>
<blockquote><p>ICustomerService o= Factory&lt;ICustomerService&gt;.Create();</p></blockquote>
<p>In case you didn&#8217;t notice: I just repeated the sample from my last post. It&#8217;s that simple &#8212; and yet, it still introduces additional complexity and error conditions.</p>
<p><strong>The bennefits </strong></p>
<p>So, what would be gained by this approach (other than complicating object instantiation and satisfying the play instinct of a certain architect <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  )? Well, there are very different aspects and they vary depending on the project life cycle:</p>
<p><em>Think of the early project stages&#8230; </em></p>
<p>The &#8220;Best Case&#8221; starting a development project would probably be to have a business specification with detailed descriptions. Descriptions that you can analyze to determine the business data and the operations upon this data &#8230; . In other words, you design the business entities and the (business) interface. <em>In other words</em> &#8212; since this also depends on the demands of the presentation layer &#8212; you do some kind of negotiation between those two layers &#8212; a process called contracting in the SOA world. Yes, we just introduced some SOA concepts into application design. The interfaces are being designed <em>prior </em>to the implementation and <em>in close negotiation </em>between the responsible developers of the respective layers. That should yield better results than ad-hoc implementations (and you may take that as understatement).</p>
<p>Once those interfaces are in place the different layers can be developed independently from each other. The presentation layer team can start to develop the frontend using some simulation classes as long as the business layer team is still working on the implementation. The business layer team can use unit tests as frontend simulation. Thus we also reduced team dependencies.</p>
<p><em>Think of development &#8230;</em></p>
<p>During development you will encounter additional orthogonal (cross cutting) behaviour, e.g. caching, routing, or security. Take caching as example. If every read or write access of customers is done via (exactly) one business service interface, this interface defines when to cache and when to invalidate cached data. Rather than putting the caching code in the business service (and spoiling the business logic) or in the presentation layer (sprinkling it all over the layer), we can inject it <em>between</em> the two layers, using a pattern called <em>interception</em>.</p>
<p>For example:</p>
<blockquote><p><font color="#0000ff">&lt;</font><font color="#800000">typeNames</font><font color="#0000ff">&gt;</font><br />
    <font color="#0000ff">&lt;</font><font color="#800000">add</font><br />
        <font color="#ff0000">key</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;SDX.MyApp.Business.Contract.ICustomerService&#8221;<br />
    </font><font color="#ff0000">    value</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;SDX.MyApp.Business.Components.<strong>Cached</strong>CustomerService, SDX.MyApp.Business.Components&#8221;</font> <font color="#0000ff">/&gt;<br />
</font>    <font color="#0000ff">&lt;</font><font color="#800000">add</font><br />
        <font color="#ff0000">key</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;SDX.MyApp.Business.Contract.ICustomerService-<strong>CACHED</strong>&#8220;<br />
    </font><font color="#ff0000">    value</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;SDX.MyApp.Business.Components.CustomerService, SDX.MyApp.Business.Components&#8221;</font> <font color="#0000ff">/&gt;<br />
</font>    &#8230; <br />
<font color="#0000ff">&lt;/</font><font color="#800000">typeNames</font><font color="#0000ff">&gt;</font> </p></blockquote>
<p>And the <em>CachedCustomerService</em> looks somewhat like this:</p>
<blockquote><p><font color="#0000ff">public</font> ICustomerService Service<br />
{<br />
    <font color="#0000ff">get</font><br />
    {<br />
        <font color="#0000ff">if</font> (_service==<font color="#0000ff">null</font>)<br />
        {<br />
            <font color="#008000"><em>// create the real service<br />
</em></font>           <font color="#0000ff">string</font> key= <font color="#0000ff">typeof</font>(ICustomerService).FullName+<font color="#800000">&#8220;-CACHED&#8221;</font>;<br />
            _service = Factory&lt;ICustomerService&gt;.CreateAlias(key);<br />
        }<br />
        <font color="#0000ff">return</font> _service;<br />
    }<br />
}</p>
<p><font color="#0000ff">public</font> IList&lt;Customer&gt; GetCustomerList(&#8230;)<br />
{<br />
    <font color="#0000ff">string</font> key = <font color="#800000">&#8220;CustomerList-&#8221;</font> + &#8230;;<br />
    <br />
    IList&lt;Customer&gt; ret = HttpContext.Current.Cache[key] <font color="#0000ff">as</font> IList&lt;Customer&gt;;<br />
    <font color="#0000ff">if</font> (ret == <font color="#0000ff">null</font>)<br />
    {<br />
        <font color="#008000"><em>// call the real service</em></font><br />
        ret = Service.GetCustomerList(&#8230;);<br />
        HttpContext.Current.Cache[key] = ret;<br />
    }<br />
    <font color="#0000ff">return</font> ret;<br />
}</p></blockquote>
<p>This way we have introduced caching without the need to change either the presentation layer or the business logic. In fact, neither layer is even aware that there is a <a target="_blank" href="http://en.wikipedia.org/wiki/Man-in-the-middle">man-in-the-middle</a>.</p>
<blockquote><p>As a side note: The idea of „interceptors“ is nothing new. MTS/COM+ used call interception to add runtime behaviour (e.g. transactions and security) to existing interfaces. The <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/bb410104.aspx">Policy Injection Application Block</a> does something <a target="_blank" href="http://blogs.msdn.com/tomholl/archive/2007/02/23/announcing-the-policy-injection-application-block.aspx">similar</a>, <a target="_blank" href="http://blogs.msdn.com/edjez/archive/2007/02/23/policy-injection-app-block-behind-the-scenes.aspx">using remoting proxies</a>.</p></blockquote>
<p>Other features that could be added this way include tracing, data tracking, performance counting, error handling, call routing and other infrastructure services. Implementing these things as interceptors rather than within the layers provides flexibility and also promotes <a target="_blank" href="http://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a>.</p>
<p><em>Think of testing &#8230;</em></p>
<p>The two patterns we have used so far &#8212; simulators and interceptors &#8212; can be used for testing as well. Simulators (or more appropriate <a target="_blank" href="http://en.wikipedia.org/wiki/Mock_Object"><em>mock objects</em></a>) can easily replace real implementations for component tests. Interceptors can be used to induce simulated error conditions that are hard to create i.r.l.. (You wouldn&#8217;t crash you disk drive on purpose, would you?).</p>
<p><strong>The limits</strong></p>
<p>Of course this approach has weak spots and does not fit in any situation. I found it particullarly valuable on the presentation layer/business layer boundary when working with entity objects of some kind. Realizing the same bennefit between business layer and data access layer may be harder, though. An object mapper for example may be reluctant to fit into a clean layer structure, <em>DataSets </em>also carry data access logic enough to question the need for a layer with a service like interface. Real simple applications (i.e. nothing more than a simple database frontent) with little to no business logik will probably contain the same interfaces as business interfaces as well as data access interfaces, and the business layer will simply route any call to the data access layer. Why go through that trouble anyway? (Other than my experience that no applications stays that simple.)</p>
<p>This approach also profits from project teams of a certain size that have their responsibilities clearly separated horizontaly, aligned to layers, and assigned to different people (although I still like the contracting part even in a one-man show). It may not work so well if you have a vertical separation (aligned to business features).</p>
<p>Anyway, I&#8217;ve used this approach in small and mid-sized projects and it definitely payed off. Big projects need some additional thoughts but the principle still holds.</p>
<p>The next post will talk about using a factory for framework extensions points.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/04/29/infactoring-the-architecture/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/04/29/infactoring-the-architecture/" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/106/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/106/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/106/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=106&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/04/29/infactoring-the-architecture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/04/architecture.gif" medium="image">
			<media:title type="html">architecture.gif</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/04/29/infactoring-the-architecture/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Building the factory</title>
		<link>http://ajdotnet.wordpress.com/2007/04/21/building-the-factory/</link>
		<comments>http://ajdotnet.wordpress.com/2007/04/21/building-the-factory/#comments</comments>
		<pubDate>Sat, 21 Apr 2007 14:11:48 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/04/21/building-the-factory/</guid>
		<description><![CDATA[I hope my last post left you curious enough to come back . Before diving into the patterns I mentioned, I need to talk a bit about factories. Pave the way, so to speak. I’ll assume that you know what a factory is &#8212; if smoking chimneys cross you mind you may leave right now [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=105&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I hope my <a href="http://ajdotnet.wordpress.com/2007/04/13/the-factory-factor/">last post</a> left you curious enough to come back <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  . Before diving into the patterns I mentioned, I need to talk a bit about factories. Pave the way, so to speak.</p>
<p>I’ll assume that you know what a factory is &#8212; if smoking chimneys cross you mind you may leave right now <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  &#8211; but since factories and the related patterns come in various flavours I should clarify what I define as „a Factory“ (if only for this post):<br />
To put it simply: <em>A factory is an object that takes a name (somehow describing the object instance I need) and returns a reference to an object or interface.</em> Period. Well, OK, let’s assume there is some configuration file that maps names to types.</p>
<p><strong>In more detail…</strong></p>
<p>Since our factory shall take names and map them to types it will need some kind of dictionary, presumably supplied as config file, say something like this:</p>
<blockquote><p><font color="#0000ff">&lt;</font><font color="#800000">typeNames</font><font color="#0000ff">&gt;<br />
    </font><font color="#0000ff">&lt;</font><font color="#800000">add</font> <font color="#ff0000">key</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;Name1&#8243;</font> <font color="#ff0000">value</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;Namspace1.Type1, Assembly1&#8243;</font> <font color="#0000ff">/&gt;<br />
</font>    <font color="#0000ff">&lt;</font><font color="#800000">add</font> <font color="#ff0000">key</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;Name2&#8243;</font> <font color="#ff0000">value</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;Namspace2.Type2, Assembly2&#8243;</font> <font color="#0000ff">/&gt;</font><br />
    &#8230;<br />
<font color="#0000ff">&lt;/</font><font color="#800000">typeNames</font><font color="#0000ff">&gt;</font> </p></blockquote>
<p>Once we have the type, we need to create an object. In .NET creating objects dynamically should be done via the <em><a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.activator.aspx">Activator</a> </em>class.</p>
<blockquote><p>Activator “Contains methods to create types of objects locally or remotely, or obtain references to existing remote objects.” and is the recommended way to do just that. The <em>AppDomain </em>class also contains methods to create objects, as do other classes, but they usually call <em>Activator </em>themselves.</p>
<p>It is also possible to invoke the constructor directly via reflection. This is however <em>not </em>recommended.</p></blockquote>
<p>Assuming the configuration has been loaded and put in some dictionaries, the core method of our homegrown factory looks somewhat like this (error handling omitted for brevity):</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">object</font> Create(<font color="#0000ff">string</font> name)<br />
{<br />
    <font color="#0000ff">string</font> assembly= _nameToAssembly[name];<br />
    <font color="#0000ff">string</font> type= _nameToType[name];<br />
    ObjectHandle handle = Activator.CreateInstance(assembly, type);<br />
    <font color="#0000ff">return</font> handle.Unwrap();<br />
}</p></blockquote>
<p>The usage would look like this (assuming a respective singleton implementation of the factory):</p>
<blockquote><p><font color="#008000"><em>// typeless</em></font><br />
<font color="#0000ff">object</font> o= Factory.Instance.Create(“Name1”);<br />
<font color="#008000"><em>// typed access </em></font><br />
IMyInterface t= (IMyInterfacse)Factory.Instance.Create(“Name2”);</p></blockquote>
<p>Conceptually there is really nothing more to it. Of course some code to fill the hash tables and some error handling, but that’s all. Well, that’s all that’s needed for the purposes I have currently in mind, but certainly not all that is possible. Let’s look at some enhancements.</p>
<p><strong>Type safety </strong></p>
<p>The first improvements to come up with are type safety and getting rid of the name argument, as it is prone to typos. A common use case for the factory is as follows: I have an interface and need an object that implements this interface. Wherever and whenever I ask for an implementation of that interface I get an object of a certain type &#8212; configurable but nevertheless always of the same type. In other words, the interface type is in itself a sufficient key and a type safe helper method taking that into account may look like this:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">class</font> Factory&lt;ObjectType&gt;<br />
{ <br />
    <font color="#0000ff">static</font> <font color="#0000ff">public</font> ObjectType Create() <br />
    { <br />
        <font color="#0000ff">return</font> (ObjectType)Factory.Instance.Create(<font color="#0000ff">typeof</font>(ObjectType).FullName); <br />
    }<br />
}</p></blockquote>
<p>Complemented with a configuration that mapps interface type names to implementation classes:</p>
<blockquote><p><font color="#0000ff">&lt;</font><font color="#800000">typeNames</font><font color="#0000ff">&gt;</font><br />
    <font color="#0000ff">&lt;</font><font color="#800000">add</font><br />
        <font color="#ff0000">key</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;SDX.MyApp.Business.Contract.IAccountService&#8221;<br />
        </font><font color="#ff0000">value</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;SDX.MyApp.Business.Components.AccountService, SDX.MyApp.Business.Components&#8221;</font> <font color="#0000ff">/&gt;</font> <br />
    <font color="#0000ff">&lt;</font><font color="#800000">add</font><br />
        <font color="#ff0000">key</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;SDX.MyApp.Business.Contract.ICustomerService&#8221;<br />
    </font><font color="#ff0000">    value</font><font color="#0000ff">=</font><font color="#0000ff">&#8220;SDX.MyApp.Business.Components.CustomerService, SDX.MyApp.Business.Components&#8221;</font> <font color="#0000ff">/&gt;<br />
</font>    &#8230; <br />
<font color="#0000ff">&lt;/</font><font color="#800000">typeNames</font><font color="#0000ff">&gt;</font> </p></blockquote>
<p>The usage would now be more convenient:</p>
<blockquote><p>IMyInterface o= Factory&lt;IMyInterface&gt;.Create();</p></blockquote>
<p><strong>Other improvements </strong></p>
<p>The following improvements are definitely for more sophisticated usage scenarios than the ones I have in mind. But since this post is dedicated to factories in general I think I should to mention them anyway.</p>
<p>Here are some strategies to change or improve the object creation and initialization:</p>
<ul>
<li>The factory could decide not to create a new object with every call, rather it could return the previously created instance again (effectively implementing a <strong>singleton mechanism</strong>). This requires the object to be reentrant and stateless, but if that’s the case, this will be a big improvement in terms of memory and performance.<br />
 </li>
<li>A <strong>pooling approach </strong>could be implemented for objects that are particular expensive to create. It would require a base class that would implement <em>IDisposable</em> in a way that the object is not destructed but put back into the pool.<br />
 </li>
<li>Talking about performance, creating objects dynamically is not exactly the most efficient thing to do. In fact it takes about 10^3 times more time than direct calls to <em>new</em>. If objects knew themselves how to create new instances of the same type (which is something <em>ICloneable </em>could help with), the factory could leverage this to implement a <strong>prototype mechanism</strong>: When an object is requested for the first time, a prototype instance is created dynamically and stored in an internal list. Rather than returning it, it is asked to create a new instance (efficiently via the mentioned interface) which is returned. Subsequent calls will use the prototype in the same way, resulting in a big performance boost for objects that are requested quite often. <br />
 </li>
<li>It is possible to specify not only the type in the config file, but also <strong>constructor parameters</strong>. These parameters could reference other objects also configured to be created by the factory. This would result in not only one object being created but a whole object graph. But this is no little amount of work to do and exactly what factory frameworks do.</li>
</ul>
<p><strong>Factory frameworks </strong></p>
<p>If the last suggestion regarding constructor arguments in the config file is something you like, then <a target="_blank" href="http://www.springframework.net/">Spring.NET</a> may be the tool for you. It supports not only constructor arguments, but property setters as well. It handles references to other configured objects and some other cases, such as collections. And it supports the singleton mechanism out of the box (as I am <a href="http://ajdotnet.wordpress.com/2006/07/28/anatomie-of-a-bug/">painfully aware of</a>). It lacks prototype or pooling support, but that could easily be build on top of it (as on every other factory framework).<br />
On other hand, Spring.NET (when I last looked at it) does not follow the recommendation to create objects via the <em>Activator </em>class. Rather it tries to find an appropriate constructor (which does not always succeed) and invoke it directly. It also creates all singleton objects right away, which may cause problems of its own.</p>
<p>Short factory framework list:</p>
<ul>
<li><a target="_blank" href="http://www.springframework.net/">Spring.NET</a> is certainly not a bad choice if you need the flexibility. And it goes beyond a pure factory framework (even if it is still behind the <a target="_blank" href="http://www.springframework.org/">java spring framework</a>), but I have no experience with those features, sorry.</li>
<li>I have not worked with <a target="_blank" href="http://www.castleproject.org/container/index.html">MicroKernel/Windsor</a> yet (certainly I have not looked at the code), but the documentation looks interesting enough to give it a try.</li>
<li>The <a target="_blank" href="http://www.codeplex.com/ObjectBuilder">Object Builder</a>, being written by the <a target="_blank" href="http://msdn.microsoft.com/practices">Microsoft patterns and practices group</a> and used by the <a target="_blank" href="http://msdn.microsoft.com/entlib">Enterprise Library</a>, may be something to keep an eye on. It appeared a bit like a second class citizen or a pure necessity when it came out; but together with the <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/bb410104.aspx">Policy Injection Application Block (PIAB)</a> it may gain more relevance.</li>
<li>Wikipedia lists <a target="_blank" href="http://en.wikipedia.org/wiki/Inversion_of_control#.NET">some more options</a> but I have no knowledge about them.</li>
</ul>
<p>Lastly let me point out that if your demands are as simple as described in the first part of this post, it is perfectly feasible to write a factory yourself. It won’t take weeks and it certainly has the benefit of <em>not</em> introducing external dependencies. OK, and it might be fun, too. </p>
<p>In my next post I will employ the factory as a means for layer separation and I will add some additional patterns built on top of a factory. This should (hopefully) highlight the bennefits of using a factory.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/04/21/building-the-factory/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/04/21/building-the-factory/" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/105/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/105/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=105&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/04/21/building-the-factory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/04/21/building-the-factory/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>The factory factor</title>
		<link>http://ajdotnet.wordpress.com/2007/04/13/the-factory-factor/</link>
		<comments>http://ajdotnet.wordpress.com/2007/04/13/the-factory-factor/#comments</comments>
		<pubDate>Fri, 13 Apr 2007 19:48:44 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/04/13/the-factory-factor/</guid>
		<description><![CDATA[Lately dependency injection has become a popular topic within the developer community. This may be caused (or be the cause for – a bit like chicken and egg) by the availability of respective containers. One of the first broadly used containers was probably Spring.NET (a .NET port of the java Spring Framework), the castle project came [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=104&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Lately <a target="_blank" href="http://www.martinfowler.com/articles/injection.html">dependency injection</a> has become a popular topic within the developer community. This may be caused (or be the cause for – a bit like <a target="_blank" href="http://en.wikipedia.org/wiki/Chicken_and_egg">chicken and egg</a>) by the availability of respective containers. One of the first broadly used containers was probably <a target="_blank" href="http://www.springframework.net/">Spring.NET</a> (a .NET port of the <a target="_blank" href="http://www.springframework.org/">java Spring Framework</a>), the <a target="_blank" href="http://www.castleproject.org/">castle project</a> came to my attention a few times, and the latest addition is the <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/bb410104.aspx">Policy Injection Application Block</a> (PIAB) as part of the <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/aa480453.aspx">Enterprise Library 3.0</a> (Microsoft patterns &amp; practices group).</p>
<p>If you are new to dependency injection, the castle project “<a target="_blank" href="http://www.castleproject.org/container/gettingstarted/index.html">getting started</a>” does a good job of highlighting the gist. Since the PIAB is a relatively new addition to the Enterprise Library (and came quite as a surprise) you may want to have a look at the <a target="_blank" href="http://blogs.msdn.com/tomholl/archive/2007/02/23/announcing-the-policy-injection-application-block.aspx">announcement</a> with a general introduction or some <a target="_blank" href="http://blogs.msdn.com/edjez/archive/2007/02/23/policy-injection-app-block-behind-the-scenes.aspx">implementation details</a>.</p>
<p>Dependency injection as a basic concept that has its value on its own, yet it is also tied to some other concepts, namely factories (the usual way to realize dependency injection) and <a target="_blank" href="http://en.wikipedia.org/wiki/Aspect-oriented_programming">aspect oriented programming</a> (AOP, aspects being just special dependencies to inject).</p>
<p>I have to admit that I am not exactly a big fan of AOP (to say the least). And dependency injection in all its broad beauty requires some real hard thinking during design, discipline during development, and a sound understanding of concept <em>and</em> design during maintenance. Some of these demands may be in short supply &#8212; which is neither surprising nor exactly a bad thing; different developers (especially corporate developers) simply have different backgrounds and different topic priorities. Therefore, despite the technical fanciness and the fact that dependency injection can boost flexibility, I really need a compelling reason to employ it.</p>
<p><strong>Lower one&#8217;s sights</strong></p>
<p><img align="right" src="http://upload.wikimedia.org/wikipedia/en/thumb/d/d5/PowerPlantEkibastus.jpg/280px-PowerPlantEkibastus.jpg" /></p>
<p>So what if dependency injection is considered too complex in a certain situation? Are we back to hardcoding? Certainly not! Enter factories.</p>
<p>I am a big fan of factories. Factories are a well know <a target="_blank" href="http://en.wikipedia.org/wiki/Factory_pattern">pattern</a> since the advent of patterns in <a target="_blank" href="http://en.wikipedia.org/wiki/GOF">public awareness</a>. They also have (the potential to have) more impact on software <em>architecture</em> than most other basic patterns. Did I mention that they may lay the foundation for more complex patterns, such as dependency injection and AOP?</p>
<p>I have used factories of a certain kind to great benefit with different patterns. Actually these patterns can be seen as degraded variants of dependency injection. (They may also have characteristics of AOP, but I won’t admit that <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ). The primary purposes I use them for are:</p>
<ol>
<li>Layer separation</li>
<li>(Framework) Extension points</li>
</ol>
<p>Despite the fact that the actual factory patterns I use are quite simple and quite easy to grasp, my approach has several benefits, e.g.:</p>
<ul>
<li>Better layer interfaces/layer separation/separation of concerns</li>
<li>The easy employment of simulators and mock objects allows independent development of layers and better testability</li>
<li>“Chaining” or “call interception” (if needed!) can be used to add orthogonal functionality such as caching. Actually this works exactly like described in the <a target="_blank" href="http://blogs.msdn.com/edjez/archive/2007/02/23/policy-injection-app-block-behind-the-scenes.aspx">PIAB</a>, albeit not with tool support.</li>
<li>The possibility to adorn common features with application specific features.</li>
</ul>
<p>Of course all this (and probably more) can be done with fully fledged dependency injection. But at the cost of more complexity (and container dependency may be an issue, too). (And to prevent angry comments: I&#8217;m not saying dependency injection is bad &#8212; Au contraire! &#8212; I&#8217;m just presenting an alternative approach.)</p>
<p>I’m going to dig into the details in the following posts, concepts and code. But not today.</p>
<p><font color="#008000">That’s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/04/13/the-factory-factor/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/04/13/the-factory-factor/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/104/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/104/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/104/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=104&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/04/13/the-factory-factor/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/en/thumb/d/d5/PowerPlantEkibastus.jpg/280px-PowerPlantEkibastus.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/04/13/the-factory-factor/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Those who would give up&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2007/04/01/those-who-would-give-up/</link>
		<comments>http://ajdotnet.wordpress.com/2007/04/01/those-who-would-give-up/#comments</comments>
		<pubDate>Sun, 01 Apr 2007 11:48:49 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/04/01/those-who-would-give-up/</guid>
		<description><![CDATA[&#8220;Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety.&#8221; &#8211; Benjamin Franklin &#8220;The basis of a democratic state is liberty.&#8221; &#8211; Aristotle &#8220;Homo homini lupus&#8221; &#8211; Thomas Hobbes Something not to be forgotten&#8230; AJ.NET<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=103&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img align="right" src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/11/European-parliament-strasbourg-inside.jpg/200px-European-parliament-strasbourg-inside.jpg" alt="European Parliament in Strasbourg" /></p>
<blockquote><p>&#8220;Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety.&#8221;<br />
&#8211; <a target="_blank" href="http://en.wikiquote.org/wiki/Benjamin_Franklin">Benjamin Franklin</a></p></blockquote>
<blockquote><p>&#8220;The basis of a democratic state is liberty.&#8221;<br />
&#8211; <a target="_blank" href="http://en.wikiquote.org/wiki/Aristotle">Aristotle</a></p></blockquote>
<blockquote><p>&#8220;Homo homini lupus&#8221;<br />
&#8211; <a target="_blank" href="http://en.wikiquote.org/wiki/Thomas_Hobbes">Thomas Hobbes</a></p></blockquote>
<p>Something not to be forgotten&#8230;<br />
<font color="#008000"><strong>AJ.NET</strong></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/103/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/103/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/103/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=103&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/04/01/those-who-would-give-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/commons/thumb/1/11/European-parliament-strasbourg-inside.jpg/200px-European-parliament-strasbourg-inside.jpg" medium="image">
			<media:title type="html">European Parliament in Strasbourg</media:title>
		</media:content>
	</item>
		<item>
		<title>List the List</title>
		<link>http://ajdotnet.wordpress.com/2007/03/24/list-the-list/</link>
		<comments>http://ajdotnet.wordpress.com/2007/03/24/list-the-list/#comments</comments>
		<pubDate>Sat, 24 Mar 2007 15:51:17 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/03/24/list-the-list/</guid>
		<description><![CDATA[This post is again going deep down to the bits (writing on high-level topics takes so much more time&#8230;). Suppose (again) you were writing some kind of generic serializer or databinding code. Sooner or later you would have to deal with lists. Collections. Arrays. In other words, you would have to deal with a situation [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=102&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post is again going deep down to the bits (writing on high-level topics takes so much more time&#8230;).</p>
<p>Suppose (again) you were writing some kind of generic serializer or databinding code. Sooner or later you would have to deal with lists. Collections. Arrays. In other words, you would have to deal with a situation like this: </p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> MyObject<br />
{<br />
    <font color="#008000"><em>// &#8230;</em></font><br />
}</p>
<p><font color="#0000ff">public</font> <font color="#0000ff">class</font> MyCollection : CollectionBase<br />
{<br />
    <font color="#008000"><em>// &#8230;</em></font><br />
}</p>
<p><font color="#0000ff">public</font> <font color="#0000ff">class</font> Data<br />
{<br />
    <font color="#0000ff">public</font> <strong><font color="#0000ff">MyObject</font>[]</strong> MyObjectArray { <font color="#008000"><em>/* &#8230; *</em></font>/ }<br />
    <font color="#0000ff">public</font> <strong>MyCollection</strong> CollectionOfMyObject { <font color="#008000"><em>/* &#8230; *</em></font>/ }<br />
    <font color="#0000ff">public</font><strong> IList&lt;MyObject&gt;</strong> GenericListOfMyObject { <font color="#008000"><em>/* &#8230; *</em></font>/ }</p>
<p>    <font color="#0000ff">public</font> <strong>ArrayList</strong> ListOfMyObjects { <font color="#008000"><em>/* &#8230; *</em></font>/ }<br />
    <font color="#0000ff">public</font> <font color="#0000ff"><strong>object</strong></font> ThisCouldBeAListOfMyObjects { <font color="#008000"><em>/* &#8230; *</em></font>/ }<br />
}</p></blockquote>
<p>In order to analyze some arbitrary object (say an instance of <em>Data</em>), you would use either <em>type.GetProperties()</em> (more suited for serializers) or <em>TypeDescriptor.GetProperties(type)</em> (the better choice for databinding and design time related stuff). You would then look at each property&#8217;s type, recognize it is a collection type, and somehow deduce the type of the collection elements (to create them dynamically or to read their properties to create list columns during databinding).</p>
<p>Let&#8217;s have a look on what our code could be presented with:</p>
<ol>
<li><strong>Arrays. </strong>They are the most simple collection type, embedded in the language, and are often used by code generation tools. Supporting them is a must.</li>
<li>Collection classes derived from <em><strong>CollectionBase</strong></em>. MSDN <a target="_blank" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionscollectionbaseclasstopic.asp">states</a> that<br />
    <em>&#8220;This base class [CollectionBase] is provided to make it easier for implementers to create a strongly typed custom collection. Implementers should extend this base class instead of creating their own.&#8221;</em><br />
Therefore <em>CollectionBase</em> was the means of choice before we had generics. Please note that this class comes with a pattern that implies type safe methods in the derived class.</li>
<li>Collections implementing <strong><em>ICollection </em>or <em>IList</em></strong>. This is a more generic approach than using <em>CollectionBase</em>. We will have to look closer at this, but if it worked, it would automatically cover the <em>ColectionBase </em>approach.</li>
<li>Generic collections, implementing <strong><em>ICollection&lt;T&gt;</em> or <em>IList&lt;T&gt;</em></strong>. This is propably the way new code will present collections to our code. Please note that a bunch of methods (like <em>Add</em>, <em>Remove</em>, etc.) that are in the non-generic version part of <em>IList </em>have been pushed down to <em>ICollection&lt;T&gt; </em>in the generic version.</li>
<li>The predefined collection classes in the <em>System.Collections</em> namespace, notably <em><strong>ArrayList</strong></em>, will also have been used quite often.</li>
<li>There is a special interface <em><strong>ITypedList</strong></em>, meant to support databinding. This may help (or it may not.)</li>
<li>Finally we may have to deal with collections that may be present in some <strong>untyped property</strong>.</li>
</ol>
<p>Now let&#8217;s see which of these cases we can support to what degree:</p>
<p><em><strong>Arrays: </strong></em>You can check if it&#8217;s an array using <em>Type.IsArray</em> and use Type.GetElementType() to get the type of the elements.<br />
 <img src='http://s1.wp.com/wp-includes/images/smilies/icon_arrow.gif' alt=':arrow:' class='wp-smiley' />  Supporting arrays is mandatory and no sweat at all. 100% done.</p>
<p><em><strong>CollectionBase, ICollection/IList: </strong></em>Neither <em>CollectionBase </em>nor one of the interfaces (also implemented by <em>CollectionBase</em>) tell you something about the element type. The usage of <em>CollectionBase</em> however implies a pattern that will have the implementor support type safe overloads of the usuall collection methods. What we can do is get hold of one of those members (e.g. the <em>Add </em>method or the indexer) and analyze its type.<br />
 <img src='http://s1.wp.com/wp-includes/images/smilies/icon_arrow.gif' alt=':arrow:' class='wp-smiley' />  Supporting arbitrary <em>ICollection</em> classes can be done if they adhere to some pattern (implied by but not restricted to <em>CollectionBase</em>). Let&#8217;s call that 90% covered.</p>
<p><em><strong>ICollection&lt;T&gt;/IList&lt;T&gt;: </strong></em>This case is as easy as arrays are. Well, appart from <a href="http://ajdotnet.wordpress.com/2006/08/01/is-getinterface-broken/">figuring out the interface</a>. But let&#8217;s ignore this exotic cases and settle with, say 99% coverage? Once you got hold of the interface it&#8217;s just a matter of calling <em>type.GetGenericArguments()</em>.<br />
 <img src='http://s1.wp.com/wp-includes/images/smilies/icon_arrow.gif' alt=':arrow:' class='wp-smiley' />  Supporting generic collections is mandatory and no sweat at all. 99% done.</p>
<p><em><strong>ArrayList: </strong></em>Here we will raise the white flag. The type of ArrayList does not tell us anything about the element type and no way to get it working. Can we live with that? <em>ArrayList </em>is &#8220;not the best choice&#8221; as property type, so this restriction might be the encouragement the developer needed to improve his data structures&#8230; (allways point out the positive aspects <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  )<br />
 <img src='http://s1.wp.com/wp-includes/images/smilies/icon_arrow.gif' alt=':arrow:' class='wp-smiley' />  Supporting ArrayList stays at 0%.</p>
<p><em><strong>ITypedList: </strong></em>ITypedList will give you direct access to the element&#8217;s properties (similar to <em>TypeDescriptor.GetProperties(type)</em>). This may be usefull for databinding and design time features &#8212; in fact I would regard that as a must, since it is part of the databinding infrastructure of .NET.<br />
For serializers might be used to get the properties and guess the component type (&#8220;von hinten durch die Brust ins Auge&#8221; &#8212; german proverb, literally &#8221;from the back through the cest into the eye&#8221;, used for arkward indirect ways to achive something). I would consider that only if I absolutely had to.<br />
 <img src='http://s1.wp.com/wp-includes/images/smilies/icon_arrow.gif' alt=':arrow:' class='wp-smiley' />  Supporting ITypedList depends on the purpose of our code. For databinding it should be considered (100% coverage), for serializers it may be a fallback chance, though unreliable. No more than 50% coverage.</p>
<p><em><strong>Untyped property: </strong></em>No type, no chance to even know it&#8217;s a collection.<br />
 <img src='http://s1.wp.com/wp-includes/images/smilies/icon_arrow.gif' alt=':arrow:' class='wp-smiley' />  0%.</p>
<p><strong>Further complications&#8230;</strong></p>
<p>So far we&#8217;ve looked at collection types, not at elements. If the collection type does not tell us enough, we may look at the first element in the collection. Asuming that there is one. If not, a serializer might have no problem, yet a databinding scenario might &#8212; which is the very reason Microsoft came up with <em>ITypedList</em>.</p>
<p>Another aspect has so far been ignored: We &#8230; (OK, <em>I</em>) asumed homogenous collections, i.e. collections of elements of the same type. Collections containing elements of different types (they may have a common base class, or be completely arbitrary) will pose a whole new bunch of problems. This is probably beyond what databinding can support, serializers would have to make sure that each list entry is stored along with type information.</p>
<p><strong>Where are we?</strong></p>
<p>If you take a look at what can be supported and what can&#8217;t, you&#8217;ll notice that it is simply not possible to cover 100% of the theoretically possible cases. Even some feasible cases will only be covered by 80%. However, if you look closer, those 80% may very well be all you&#8217;ll ever need. And if you really stumble over one of the 20% cases (<em>ArrayList</em> might be one of those), don&#8217;t try to guess out of the blue; think of some way to feed additional meta information into your serializer.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/03/24/list-the-list/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/03/24/list-the-list/" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/102/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/102/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/102/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=102&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/03/24/list-the-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/03/24/list-the-list/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Get view state off __VIEWSTATE!</title>
		<link>http://ajdotnet.wordpress.com/2007/03/17/get-view-state-off-__viewstate/</link>
		<comments>http://ajdotnet.wordpress.com/2007/03/17/get-view-state-off-__viewstate/#comments</comments>
		<pubDate>Sat, 17 Mar 2007 14:59:12 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/03/17/get-view-state-off-__viewstate/</guid>
		<description><![CDATA[As I announced in a previous post there is something to say about storing the view state on the server… ASP.NET saves transient control data across postbacks in the &#8220;view state&#8221;. The means for persisting that data is a hidden field in the pages HTML code. Take some complex controls &#8212; especially grids that save [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=101&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As I announced in a <a href="http://ajdotnet.wordpress.com/2007/01/26/viewstate-state/">previous post</a> there is something to say about storing the view state on the server…</p>
<p>ASP.NET saves transient control data across postbacks in the &#8220;view state&#8221;. The means for persisting that data is a hidden field in the pages HTML code. Take some complex controls &#8212; especially grids that save the complete data they are working on in view state &#8212; the amount of view state data can easily reach, even exceed, the size of the remaining HTML. This can severely affect response times, not to mention the processing time on the server to de/serialize the data and to protect against tampering and other view state attacks.</p>
<p>Apart from enabling HTTP compression (which you should do anyway) and spending some thought on whether you need that particular view state data at all (not a bad idea either) the obvious solution for these issues is <em>not</em> to send the view state data over the wire at all. Let&#8217;s take a closer look at that option.</p>
<p><strong>ASP.NET 1.1</strong></p>
<p>In ASP.NET 1.1. the page class supports customization of view state persistence with two methods:</p>
<ul>
<li><em>void Page.SavePageStateToPersistenceMedium(object viewState)</em> (see <a target="_blank" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIPageClassSavePageStateToPersistenceMediumTopic.asp">MSDN</a>)</li>
<li><em>object Page.LoadPageStateFromPersistenceMedium()</em> (see <a target="_blank" href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebUIPageClassLoadPageStateFromPersistenceMediumTopic.asp">MSDN</a>)</li>
</ul>
<p>This has to be done for every page, but I would recommend using a common base class for all pages anyway.</p>
<p>The default implementation of <em>SavePageStateToPersistenceMedium </em>simply stores the view state in a member variable, actually storing it is defered until <em>Page.OnFormRender </em>is called. <em>OnFormRender </em>uses a <em>LosFormatter </em>to serialize the data into a string representation and puts it into a hidden field. <em>LoadPageStateFromPersistenceMedium </em>uses a <em>LosFormatter </em>to do the reverse. The role of that <em>LosFormatter </em>is noteworthy; the documentation <a target="_blank" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUILosFormatterClassTopic.asp">states</a>:</p>
<blockquote><p>The limited object serialization (LOS) formatter is designed for highly compact ASCII format serialization. This class supports serializing any object graph, but is optimized for those containing strings, arrays, and hash tables. It offers second order optimization for many of the .NET Framework primitive types.</p></blockquote>
<p>One should pay special attention to the fact that <em>LosFormatter </em>can deal with objects that are not marked as seriablizable, and thus cannot be handled by the standard .NET serialization.</p>
<p>If you want to take the view state data out of the hidden field you can do this simply by overriding those two methods. The things to take into account include:</p>
<ul>
<li>In order to properly support the browser history you need to track the particular page request and link it to the view state data. E.g. you may still use a hidden field to store some kind of view state ID.</li>
<li>You must decide how much view state packages you maintain on the server. It&#8217;s not feasible to store all view states as long as the user session is alive. Store just one and the second &#8220;browser back&#8221; in a row will fail.</li>
<li>You need some persistence medium to store the view state. The obvious choice would be the user session. However, since your session should be held out-of-proc (i.e. managed by the ASP.NET State Service) you cannot simply put the view state object into the state &#8212; see the serialization problem mentioned above &#8212; but you may use a <em>LosFormatter </em>and put that string in the session.</li>
</ul>
<blockquote><p>As a sidenote: Other articles about this can be found on the internet. They usually propose the ASP.NET cache or a file based approach.<br />
The cache suffers from the same problems that in-proc session state has (see <a href="http://ajdotnet.wordpress.com/2007/03/03/bury-in-proc-session-state/">here</a>). It also may remove cache entries far earlier than suitable for view state (e.g. under load conditions).<br />
The file based approach will need some additional cleanup mechanism but has the best potential to support view state with a limitless browser history. It also consumes the least amount of memory.<br />
The session approach suffers from the fact that all session content (triggered by and including all maintained view state packages) has to be serialized with every request. Cleanup however is done automatically.</p>
<p>If I had to think about a fully-fledged high-throughput solution, I would probably try out a combination of database (with a cleanup job) and caching.</p></blockquote>
<p>I&#8217;m not going to provide code, since the algorithm can easily be taken form ASP.NET 2.0 and be applied to ASP.NET 1.1 (i.e. attached to <em>SavePageStateToPersistenceMedium </em>and <em>LoadPageStateFromPersistenceMedium</em>). The good news is that this implementation will work as well if you move to ASP.NET 2.0.</p>
<p><strong>ASP.NET 2.0 </strong></p>
<p>With ASP.NET 2.0 there is no change in principle, just some additional concepts. Make that a huge additional concept. And pittfalls.</p>
<p>Fact one: ASP.NET 2.0 introduced the concept of adapters which are registered in &#8221;.browser&#8221;-files for bowser types. Adapters can interfere with different control aspects, such as rendering &#8212; and view state.</p>
<p>Fact two: The <em>Page </em>class now has a virtual property <em>PageStatePersister</em>. The default implementation of the ASP.NET 1.1 methods mentioned above now delegate the work to the instance returned by this property. And while <em>HiddenFieldPageStatePersister </em>still is the default persister, one may also return <em>SessionPageStatePersister</em>. Or a custom class.</p>
<p>Fact three: The documented way to replace the persister is to a) write an adapter and b) register it in a .browser file. And c) I don’t like this. First, .browser files do a lot more than just replacing the adapter. Second, how should anybody realize how this happens (the guy who has to maintain my code after I left). Third, in what way is this replacement browser specific? And anyway, I really don’t care for browser differences.</p>
<p>But why not simply forget about the “documented way” and just overwrite the property?</p>
<blockquote><p>PageStatePersister _pageStatePersister;</p>
<p><font color="#0000ff">protected</font> <font color="#0000ff">override</font> PageStatePersister PageStatePersister<br />
{<br />
    <font color="#0000ff">get</font><br />
    {<br />
        <font color="#0000ff">if</font> (_pageStatePersister == <font color="#0000ff">null</font>)<br />
            _pageStatePersister = <font color="#0000ff">new</font> SessionPageStatePersister(<font color="#0000ff">this</font>);<br />
        <font color="#0000ff">return</font> _pageStatePersister;<br />
    }<br />
}</p></blockquote>
<p>Great, just a few lines of code and I can throw away all the work I did for ASP.NET 1.1 … . ? What’s that? A serialisation exception? Oh boy, I <em>know </em>that problem. OK, I’ll derive my own persister … let&#8217;s see&#8230; persisters have a method <em>CreateStateFormatter </em>… which is internal? OK, … the formatter isn’t used anyway? The view state is simply put into the session state? And the method doing this is … well, of course it&#8217;s <em>not </em>virtual!</p>
<p>So, this leaves two options:</p>
<ol>
<li>If you already have a homegrown APS.NET 1.1 algorithm, just leave it as it is. It works, so why bother.</li>
<li>If you start something new, try “copy and mend”, i.e. use your favourite help tool (Reflector!) to get the code from <em>SessionPageStatePersister </em>and fix the problems (just use a <em>LosFormatter </em>before putting the view state in the session). Don’t bother with virtual methods, you are the user of a framework, not the implementor.<br />
And this can easily be ported back to ASP.NET 1.1 if the need arises.</li>
</ol>
<p>So, finally there. And not too much work either. However this little experience has again raised the question whether (ASP).NET is meant to be extended and tailored to one&#8217;s needs &#8212; or just to be used as-is.</p>
<p><font color="#008000">Thats all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/03/17/get-view-state-off-__viewstate/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/03/17/get-view-state-off-__viewstate/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/101/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/101/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/101/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=101&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/03/17/get-view-state-off-__viewstate/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/03/17/get-view-state-off-__viewstate/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>New version of my AddIn&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2007/03/10/new-version-of-my-addin/</link>
		<comments>http://ajdotnet.wordpress.com/2007/03/10/new-version-of-my-addin/#comments</comments>
		<pubDate>Sat, 10 Mar 2007 19:25:45 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Software Developers]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/03/10/new-version-of-my-addin/</guid>
		<description><![CDATA[I just put a new version of my addin on my web site (for a first introduction see this post). Here are the major changes (apart from bug fixing): Browse current file: Methods now show signatures Browse current file: Generics shown correctly Browse (all): Support of progress bar Browse (all): Persistent window size AddIn: first tests [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=98&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img align="right" src="http://ajdotnet.files.wordpress.com/2007/03/browsecurrentfile.jpg" alt="BrowseCurrentFile.jpg" />I just put a new version of my addin on <a target="_blank" href="http://www.alexander-jung.net/download/download.htm">my web site</a> (for a first introduction see <a href="http://ajdotnet.wordpress.com/2006/12/16/its-christmas-time/">this post</a>). Here are the major changes (apart from bug fixing):</p>
<ul>
<li>Browse current file: Methods now show signatures</li>
<li>Browse current file: Generics shown correctly</li>
<li>Browse (all): Support of progress bar</li>
<li>Browse (all): Persistent window size</li>
<li>AddIn: first tests under Vista</li>
</ul>
<p>There is currently an issue under vista with language packs. Menu icons are not shown and shortcut keys are not assigned.</p>
<blockquote><p>Obviously MS has changed the loading scheme of the resource DLL &#8212; I need to fix that, once I get an idea how to do that). They also made the same mistake the once made with localized VBA languages (remember your VBA keywords being translated from IF-THEN-ELSE to WENN-DANN-SONST?). Now they translate the key codes (&#8220;Ctrl-Up Arrow&#8221; to &#8220;Strg-NACH-OBEN-TASTE&#8221;) as well as the commands. Can you believe that?</p>
<p>Anyway, I took care that the AddIn works, but nothing more. The missing icons are no vital part. Regarding shortcuts you need to assign them manually until I have fixed that issue. </p></blockquote>
<p>I think I have addressed some of the feedback I got (if only in the FAQ help page). Other feedback has been placed on my todo list (including flattened presentation, i.e. a list control rather than a tree control for browse).</p>
<p>I hope you enjoy it.</p>
<p><font color="#008000">That’s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/03/10/new-version-of-my-addin/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/03/10/new-version-of-my-addin/" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/98/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/98/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=98&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/03/10/new-version-of-my-addin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/03/browsecurrentfile.jpg" medium="image">
			<media:title type="html">BrowseCurrentFile.jpg</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/03/10/new-version-of-my-addin/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Bury in-proc session state!</title>
		<link>http://ajdotnet.wordpress.com/2007/03/03/bury-in-proc-session-state/</link>
		<comments>http://ajdotnet.wordpress.com/2007/03/03/bury-in-proc-session-state/#comments</comments>
		<pubDate>Sat, 03 Mar 2007 20:29:01 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/03/03/bury-in-proc-session-state/</guid>
		<description><![CDATA[In ASP.NET session state can be held in 3+ locations. The choice is between in-proc (i.e. managed in the app domain), out-of-proc (with either ASP.NET state service or in SQL Server), or custom built. When you create a new web application, in-proc is used by default &#8211; which is the worst choice one could make. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=97&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In ASP.NET session state can be held in 3+ locations. The choice is between in-proc (i.e. managed in the app domain), out-of-proc (with either ASP.NET state service or in SQL Server), or custom built.</p>
<p>When you create a new web application, in-proc is used by default &#8211; which is the worst choice one could make. Apparantly this is the case for simplicity, because it does not need additional setup and works out of the box. ASP.NET state service needs a running service (which is by default not the case), and SQL Server or custom built solutions obviously need even more setup work.</p>
<p>What you should do immediately is to <strong>switch to out-of-proc mode!</strong></p>
<p>Why? Well, not for the usually mentioned reasons. Not because using out-of-proc session state increases robustness, i.e. the state will survive if the application restarts, allegedly after some kind of error. Not because MSDN advises against in-proc session state for <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms178586.aspx">web garden scenarios</a> (see „caution“). And also not because there is a <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms178581.aspx">serialization issue</a> (see „note“).</p>
<p>Don‘t get me wrong, those are all valid reasons. Especially the serialization issue is the very reason why you should use out-of-proc mode right from the beginning rather than switching later. But the reason you should switch is more simple and evene more serious: <strong>In-proc session state does not work!</strong></p>
<p>„Are you nuts? I always used it and never had any problems…“. Yes I know. But sorry, you were just lucky. Just because the problem didn&#8217;t manifest itself doesn&#8217;t mean you didn&#8217;t have it. Actually Microsoft tells <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/aa479328.aspx">all the facts</a> one needs to know (they just forgot to tell about the consequence):</p>
<blockquote><p>„The worker process is subject to a feature named process recycling. Process recycling consists in the aspnet_isapi ability of automatically starting a new process when the existing one is consuming too much memory, responds too slowly, or just hangs. When this happens, new requests are serviced by the new instance, which becomes the new active process.“</p></blockquote>
<p>And what happens to the in-proc state? Right. Nothing. In other words it dies with the app domain. Session state lost, sorry. And by the way, this is by intention.</p>
<p>„OK, I can allways switch in production, no big deal!“ Yes you can. But don‘t make too many plans for the weekend, you might have to track down that serialization issue. That one is particularly nasty, because it happens out of sync. You can put anything from integers to objects to french fries into the state. ASP.NET just won‘t complain. Only at the end of the request life cycle the session state is serialized and only if some non-serializable object is in the state you (or rather the end user) will be „served“ with a serialization exception. Try to find the root cause for that exception in a non-trivial application and without knowing what the user did beforehand.<br />
Therefore you should wok out-of-proc during development. If you did not do that you are probably better off with in-proc session state and loosing the sessions now and then.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/03/03/bury-in-proc-session-state/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/03/03/bury-in-proc-session-state/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/97/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/97/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/97/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=97&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/03/03/bury-in-proc-session-state/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/03/03/bury-in-proc-session-state/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Security analysis on WCF for the German Gouvernment</title>
		<link>http://ajdotnet.wordpress.com/2007/02/23/security-analysis-on-wcf-for-the-german-gouvernment/</link>
		<comments>http://ajdotnet.wordpress.com/2007/02/23/security-analysis-on-wcf-for-the-german-gouvernment/#comments</comments>
		<pubDate>Fri, 23 Feb 2007 20:54:09 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/02/23/security-analysis-on-wfc-for-the-german-gouvernment/</guid>
		<description><![CDATA[Something I was waiting for but nearly missed: Michael Willers has announced the security analysis on Windows Communication Foundation he and his collegues did for the German Federal Office for Information Security (Bundesamt für Sicherheit in der Informationstechnik, BSI). I had the luck to hear Michael talk about this stuff last october. There where two [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=95&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img align="right" src="http://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/ChessSet.jpg/250px-ChessSet.jpg" style="margin:0 0 5px 5px;" /></p>
<p>Something I was waiting for but nearly missed: Michael Willers has <a target="_blank" href="http://staff.newtelligence.net/michaelw/CommentView,guid,a7b0683b-b87f-474b-97e1-7427ed4cf6ce.aspx">announced</a> the security analysis on Windows Communication Foundation he and his collegues did for the German Federal Office for Information Security (<a target="_blank" href="http://www.bsi.bund.de/english/index.htm">Bundesamt für Sicherheit in der Informationstechnik, BSI</a>).</p>
<p>I had the luck to hear Michael talk about this stuff last october. There where two interesting points in his talk:</p>
<ol>
<li>He took us through some <a target="_blank" href="http://msdn2.microsoft.com/en-us/security/aa570413.aspx">threat modelling</a>. That may be intersting from a security point of view but what impressed me more was that this was the most sound and structured architecture review I ever saw.</li>
<li>Michael emphasised the fact that developing a secure application was only the first part of the deal. Deploying it &#8212; or more to the point <em>secure deployment</em> &#8212; turned out to be a challenge of its own. Consequently the statement on his blog:</li>
</ol>
<blockquote><p>&#8220;The results of this study demonstrates how to implement and <strong>securely deploy </strong>service oriented distributed systems on the Microsoft .NET Platform. &#8220;</p></blockquote>
<p>Documentation and code (under GPL) can be obtained at the <a target="_blank" href="http://www.bsi.bund.de/fachthem/betriebssysteme/indigo/index.htm#indigoen">BSI site</a>:</p>
<blockquote><p>&#8220;Beside the complete source code of the WCF reference application the BSI distributes manuals covering WCF specific architecture aspects, authentication, data access, development autonomy, distributed error handling, the hosting environment, transport security, securing resources, and secure service set-up and installation.&#8221;</p></blockquote>
<p>It&#8217;s definitely worth a closer look.</p>
<p><strong>UPDATE: </strong>Microsoft has provided some of the results as templates and libaries for download. See here (<a target="_blank" href="http://staff.newtelligence.net/michaelw/PermaLink,guid,e6ffa921-f07b-4bf5-8db3-a8a5c393c6e4.aspx">Michael&#8217;s announcement</a>) and on the <a target="_blank" href="http://www.microsoft.com/germany/msdn/library/security/MSDNCASToolsUndBestPractices.mspx?mfr=true">MSDN CAS Tools &amp; Best Practices</a> site (both in German, sorry, but the downloadable content should be in english).</p>
<p>PS: The BSI is &#8220;the central IT security service provider for the German Government.&#8221; (<a target="_blank" href="http://www.bsi.bund.de/english/index.htm">http://www.bsi.bund.de/english/index.htm</a>)</p>
<p>PPS: The usage of voting machines for elections in Germany does not seem to require IT security <img src='http://s2.wp.com/wp-includes/images/smilies/icon_evil.gif' alt=':evil:' class='wp-smiley' />  , therefore they are checked and certified by the &#8220;<a target="_blank" href="http://www.ptb.de">Physikalisch-Technische Bundesanstalt, PTB</a>&#8220;.</p>
<blockquote><p>&#8220;The Physikalisch-Technische Bundesanstalt (PTB) is the national metrology institute providing scientific and technical services. PTB measures with the highest accuracy and reliability – metrology as the core competence.&#8221; (<a target="_blank" href="http://www.ptb.de/en/zieleaufgaben/dieptb.html">http://www.ptb.de/en/zieleaufgaben/dieptb.html</a>).</p></blockquote>
<p>PPPS: And by the way: Germany uses <a target="_blank" href="http://en.wikipedia.org/wiki/Nedap">Nedap</a> machines, the ones you can <a target="_blank" href="http://www.wijvertrouwenstemcomputersniet.nl/English">play chess</a> with&#8230;  <img src='http://s2.wp.com/wp-includes/images/smilies/icon_twisted.gif' alt=':twisted:' class='wp-smiley' /> </p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/02/23/security-analysis-on-wfc-for-the-german-gouvernment/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/02/23/security-analysis-on-wfc-for-the-german-gouvernment/" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/95/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/95/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=95&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/02/23/security-analysis-on-wcf-for-the-german-gouvernment/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/ChessSet.jpg/250px-ChessSet.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/02/23/security-analysis-on-wfc-for-the-german-gouvernment/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>When are we going to see Glasnost?</title>
		<link>http://ajdotnet.wordpress.com/2007/02/17/when-are-we-going-to-see-glasnost/</link>
		<comments>http://ajdotnet.wordpress.com/2007/02/17/when-are-we-going-to-see-glasnost/#comments</comments>
		<pubDate>Sat, 17 Feb 2007 10:13:24 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/02/17/when-are-we-going-to-see-glasnost/</guid>
		<description><![CDATA[There is a world in which glasnost has never happened. The iron curtain is still in place. The so-called free part of the world &#8212; in all its inconsistent chaotic beauty &#8212; stands against the firmly organized part where some kind of party decides upon the future development and people more or less follow those [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=93&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>There is a world in which glasnost has never happened. </em>The iron curtain is still in place. The so-called free part of the world &#8212; in all its inconsistent chaotic beauty &#8212; stands against the firmly organized part where some kind of party decides upon the future development and people more or less follow those directions. There is the occasional traitor and spy games are not unusual. But the average citizen in each block does not care about the other side and does not know very much about it. If asked however, he would testify to the worst about the people on the other side. Sometimes those bad asumptions are even actually true which is regularly used by some group in the own camp to propagate <a target="_blank" href="http://en.wikipedia.org/wiki/Fear%2C_uncertainty_and_doubt">FUD</a> and to cement a stable political system.<br />
Let&#8217;s just hope &#8220;<a target="_blank" href="http://en.wikipedia.org/wiki/The_Day_After">The Day After</a>&#8221; does not happen anytime soon….</p>
<p>Sounds like a description of the cold war in the &#8217;80s? Well, actually I am refering to the IT world today, the opposing blocks being the Java and .NET communities. You think that&#8217;s exaggerated and ask why I have that impression? Well, there&#8217;s proof after proof after proof&#8230;</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_exclaim.gif' alt=':!:' class='wp-smiley' />  Have a look at the comments in major IT newstickers (german readers have a look at <a target="_blank" href="http://www.heise.de">www.heise.de</a>) and the onging flame wars. (Those may be just proxy wars.)</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_exclaim.gif' alt=':!:' class='wp-smiley' />  Have you ever talked to people form the other camp? (If not, why not?) Have you been confronted with the usual arrogances and prejudices?</p>
<ul>
<li>&#8220;One cannot build software on that plattform; developers working on that plattform are simply too stupid to realize the truth; &#8230;&#8221;</li>
<li>&#8220;Monstrous, inperformant, over-engineered, software molochs; arrogant oo-fanatics; …&#8221;</li>
</ul>
<p>Sounds familliar? Any problem placing the &#8220;Java&#8221; or &#8220;.NET&#8221; tag on those lines?</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_exclaim.gif' alt=':!:' class='wp-smiley' />  So far my favourite is a java guy who stood in an office (team office for a .NET project) and announced (allegedly to a collegue but loud enough to be heard on the next floor) &#8220;one cannot build software with Microsoft!&#8221;. He did that after talking to his collegue and in the process stating that he did not have a clue about (ASP).NET. Single-minded, arrogant idiot.</p>
<p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_exclaim.gif' alt=':!:' class='wp-smiley' />  The final experience that led to this post was that little research I did for the <a href="http://ajdotnet.wordpress.com/2007/02/10/java-ee-rip/">last post</a>. Although a little less religious, I realized that the level of ignorance of the other side is daunting. Some examples:</p>
<p><em>Java minded people:</em></p>
<ul>
<li>&#8220;The complexity of JEE is minimal when compared to .Net &#8220;. Nonsense. Just compare &#8220;<a target="_blank" href="http://java.sun.com/javaee/technologies/">Java EE Technologies</a>&#8221; with &#8220;<a target="_blank" href="http://msdn2.microsoft.com/en-us/netframework/aa497336.aspx">.NET Technology Overview</a>&#8220;. The complexity of the plattform is all in all comparable, the complexity of the various specifications of Java EE is considerably higher than the respective .NET documentation.<br />
(I didn&#8217;t include WinFX parts in the equation because there is no counterpart on the Java side; see &#8220;<a target="_blank" href="http://blogs.msdn.com/kaevans/archive/2006/06/11/626299.aspx">.NET Framework 3.0: Clearing the Confusion</a>&#8221; for infos on that topic.)</li>
<li>&#8220;I see by far more Java services than .Net.&#8221;. Well, I see more .NET services. Perhaps that&#8217;s because I work mainly in .NET and you in Java dominated environments? Actually I see more none-service based integration (database imports, ftp file exchange, …) &#8230;</li>
<li>&#8220;Microsoft environments are typically more homogenous, which requires less integration thereby reducing the benefits of SOA.&#8221;. Nonsense. In enterprise environments (where else would I need a notable degree of integration and SOA?), Java usually has the bigger installation base on servers, i.e. <em>more</em> integration demand.</li>
</ul>
<p><em>.NET minded people:</em></p>
<ul>
<li>&#8220;… the core of J2EE (EJB) was never really designed for the web, and the whole async ethos. &#8220;. Nonsense. EJB is as much designed and suited for the web as COM+ is. Both are component management systems that gained momentum with the success of the internet. The were <em>the very means </em>to enable the development of scalable web applications. Asynchronicity is in addition a core part both systems (<a target="_blank" href="http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/EJBConcepts5.html">message driven beans</a> in EJB and <a target="_blank" href="http://msdn2.microsoft.com/en-gb/library/cwd2fx9t(vs.80).aspx">queued components</a> in COM+).</li>
<li>&#8220;Java EE turned out to be about as rigid as CORBA.&#8221;. Yes, sure. Ever heard of the &#8220;Java Community Process&#8221;? Was it possible to use just certain parts of CORBA and replace others?</li>
<li>&#8220;Really, compared to .Net J2EE development is pain.&#8221;. It is? Did you ever use J2EE with a decent IDE, say Eclipse? Did you ever try to write a .NET application without Visual Studio? Why did Microsoft change the build system to MS-Ant, sorry, MSBuild?</li>
<li>&#8220;So far .Net has avoided becoming rigid &#8211; it is still an open platform as to allowing many different approaches to achieve a solution.&#8221; An open plattform? Don&#8217;t you confuse implementation with usage? Who decides on how to evolve the .NET Framework and Visual Studio?</li>
</ul>
<p>So much for the people living in both blocks. But there is another thing which is again just like in the cold war: Despite public appearance and various cold and hot proxy wars, there is considerable cooperation between the opposing camps. Politically each contributes to the welfare of the other and draws bennefits as well as self-affirmation from it. And talking about &#8220;the powers that rule&#8221;, IBM and Microsoft work very well together if it suites their needs, see <a target="_blank" href="http://ws-i.org/">http://ws-i.org/</a> for example. </p>
<p>So, how far can the similarities be stessed? What would &#8220;<a target="_blank" href="http://en.wikipedia.org/wiki/Berlin_Wall#The_fall.2C_1989">the fall of the wall</a>&#8221; in IT look like and who would be the winners and loosers? Would we have to face similar problems as <a target="_blank" href="http://en.wikipedia.org/wiki/Yugoslavia">we had in the 1990s</a>, i.e. the struggle betweeen Sun and IBM? Given these potential problems and the political situation today, do we really want the wall to come down? (Metaphorically speaking, I&#8217;m glad the real wall came down!)</p>
<p>Of course there are positive examples as well. During one Java project I worked with two Java guys who did not have a clue about .NET. But they were open minded and just hadn&#8217;t had the opportunity to look into the stuff yet. Actually they were surprised that the .NET Framework and some Visual Studios versions are free. They gave it a try, they saw the pros and cons, they were even impressed by some aspects. They never seriously considered switching to .NET but we had some interesting discussions about different technical and &#8220;cutural&#8221; aspects.</p>
<p>I guess I should stop here, perhaps go to listen to some music. &#8220;<a target="_blank" href="http://www.lyricsfreak.com/s/sting/russians_20132086.html">Russians</a>&#8220; (Sting) would be fittingly, or &#8220;<a target="_blank" href="http://www.lyricsfreak.com/r/rush/witch+hunt_20120003.html">Witch Hunt</a>&#8220; (Rush)&#8230; .</p>
<p>PS: This is my last excursion into Java related areas. I&#8217;m going to focus on .NET again, it&#8217;s less political there. </p>
<p><font color="#008000">That&#8217;s all for now,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/02/17/when-are-we-going-to-see-glasnost/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/02/17/when-are-we-going-to-see-glasnost/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/93/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/93/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/93/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/93/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/93/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=93&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/02/17/when-are-we-going-to-see-glasnost/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/02/17/when-are-we-going-to-see-glasnost/" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Java EE, R.I.P.?</title>
		<link>http://ajdotnet.wordpress.com/2007/02/10/java-ee-rip/</link>
		<comments>http://ajdotnet.wordpress.com/2007/02/10/java-ee-rip/#comments</comments>
		<pubDate>Fri, 09 Feb 2007 22:21:27 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/02/10/java-ee-rip/</guid>
		<description><![CDATA[After the last post I still owe you an opinion about &#8220;Analysts see Java EE dying in an SOA world&#8220;. Well, here it is (perhaps a little overstated): This article is fundamentally flawed. It confuses the SOA architectural approach, SOA environments and frameworks, services and service implementations. It implies wrong architectural attempts to prove the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=92&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After the <a href="http://ajdotnet.wordpress.com/2007/02/02/will-somebody-please-defend-java-ee/">last post</a> I still owe you an opinion about &#8220;<a target="_blank" href="http://searchwebservices.techtarget.com/originalContent/0,289142,sid26_gci1198211,00.html">Analysts see Java EE dying in an SOA world</a>&#8220;. Well, here it is (perhaps a little overstated):</p>
<p><strong>This article is fundamentally flawed.</strong> It confuses the SOA architectural approach, SOA environments and frameworks, services and service implementations. It implies wrong architectural attempts to prove the inability to deliver something upon it. It ignores todays tool ladden development environments that manage complexity quite well. It even dismisses Java as a plattform &#8212; for reasons that would also apply to .NET &#8211;, at the same time contradicting itself.</p>
<p>I picked just some points to justify may statements:</p>
<ul>
<li>&#8220;The Java EE world is fundamentally not built for SOA&#8221;. SOA is about architectures that (technically speaking) deal with message exchange patterns <em>between </em>independend services. Java EE on the other hand is an implementation technology for those services, i.e. it covers the inner workings of a service and its interface. For this Java EE is perfectly suited. <em>Confusion of SOA and service implementation.</em></li>
<li>Also the same paragraph states that &#8220;Java is specifically a framework for implementing n-tier architectures&#8221; which has been the architecture of choice for scaleable and reliable web applications even before they have been adorned with SOAP interfaces. <em>Contradiction.</em></li>
<li>&#8220;Object orientation (OO) as implemented in Java EE does not fit well with the service orientation that is the heart of SOA&#8221;. This implies that the OO approach is used at the SOA level, i.e. accross services. This is exactly what remote object technologies (CORBA, DCOM, RMI) tried to do. They failed &#8212; hardly any news at all &#8212; and services entered the stage to address the respective problems. <em>Implication of wrong architectural attempts</em>. (Again, this does by no means rule out Java as implementation technology for services itself.)</li>
<li>&#8220;It&#8217;s the method in which you&#8217;re exchanging the data that matters, not the programming model behind the data.&#8221; So, if the programming model does not matter from a SOA perspective, why dismiss any programming model at all? Why argue about virtual machines or portability in the first place? <em>Contradiction</em>.</li>
<li>&#8220;You&#8217;ll see that Java EE focuses on providing a framework for scalable n-tier architectures like those that large, transactional Web sites require&#8221;. Which is also exactly what business services need. <em>Contradiction </em>or just <em>lack of understanding?</em> </li>
<li>&#8220;However, if you were to set out to create an enterprise-class framework for SOA&#8230;&#8221; Now what is that? A framework to unify the service implementations? And I thought &#8220;the service orientation makes the need for a unified platform such as Java EE irrelevant.&#8221; <em>Contradiction</em>. Or does this refer to some kind fo SOA plattform, say an ESB? Who just said &#8220;it&#8217;s not what&#8217;s serving up the communications that&#8217;s important, it&#8217;s the communications itself.&#8221; <em>Contradiction</em>. And by the way: The only noteable SOA plattform <em>not </em>built on Java is MS BizTalk.</li>
<li>&#8230;</li>
</ul>
<p>Now, I can understand that analysts riding the SOA hype need to attract attention and statements that strong do that especially well. But these staements do not do them credit, rather they show some vital lack of understanding of SOA* &#8212; or deliberate obfuscation. Which one, I cannot say. I can only hope that they have been quoted distortingly or out of context.</p>
<p>* It cannot be lack of understanding of Java EE since one of the quoted analysts is an author of well regarded books on Java (<a target="_blank" href="http://www.amazon.com/J2EE-Web-Services-Richard-Monson-Haefel/dp/0321146182/sr=8-3/qid=1169237629/ref=pd_bbs_sr_3/104-6581173-4127944?ie=UTF8&amp;s=books">J2EE Web Services</a> and <a target="_blank" href="http://www.amazon.com/Enterprise-JavaBeans-3-0-Bill-Burke/dp/059600978X/sr=8-2/qid=1169237629/ref=pd_bbs_sr_2/104-6581173-4127944?ie=UTF8&amp;s=books">Enterprise JavaBeans 3.0</a> &#8212; which I own myself. Sic!)</p>
<p>As I said: This may be overstated, but it&#8217;s straight to the point. And it&#8217;s only an opinion, no insult intended!</p>
<p>So, well… . I &#8212; yeah, that is me, the one who usually signs its posts with AJ<em><font color="#008000">.NET</font> </em>&#8211; can firmly stand up and announce publicly and unequivocal with loud and clear voice:<br />
<strong>Java EE ist still alive and kicking! Any reports allegedly anouncing his death are wrong.<br />
</strong>As we say in german: &#8220;Totgesagte leben länger…&#8221; (proverb, something like &#8220;people declared death/written off live longer&#8230;&#8221;).</p>
<p>Please note that I&#8217;m not saying that the role of Java EE (read EJB) is not changing: Au contraire! It is quite obvious that lightweight approaches gain more and more momentum in situations where EJB is overkill. But there still are complex demands that ask for transactional and component life time services, security, operations support, etc.. I guess it boils down to &#8220;use the right tool&#8221;. However, the fact that our toolbox has more items in it does not mean one should throw away the &#8220;older&#8221; tools. Usually they got old because they had value.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.EE</strong> <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  </font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/02/10/java-ee-rip/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/02/10/java-ee-rip/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/92/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/92/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/92/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=92&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/02/10/java-ee-rip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/02/10/java-ee-rip/" medium="image" />
	</item>
		<item>
		<title>Will somebody please defend Java EE?</title>
		<link>http://ajdotnet.wordpress.com/2007/02/02/will-somebody-please-defend-java-ee/</link>
		<comments>http://ajdotnet.wordpress.com/2007/02/02/will-somebody-please-defend-java-ee/#comments</comments>
		<pubDate>Fri, 02 Feb 2007 18:50:45 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/02/02/will-somebody-please-defend-java-ee/</guid>
		<description><![CDATA[Some time ago a fellow programmer pointed me to &#8220;Analysts see Java EE dying in an SOA world&#8221; and asked about my opinion. Since then it always lingered in my mind to shape my thoughts into a blog post… &#8212; but that will have to wait! Since I did not want to do the nth [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=91&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Some time ago a fellow programmer pointed me to &#8220;<a target="_blank" href="http://searchwebservices.techtarget.com/originalContent/0,289142,sid26_gci1198211,00.html">Analysts see Java EE dying in an SOA world</a>&#8221; and asked about my opinion. Since then it always lingered in my mind to shape my thoughts into a blog post… &#8212; but that will have to wait!</p>
<p>Since I did not want to do the n<em>th</em> repetition of things already said before, I began with searching the web. Given the nature of the article and the fact that it is 6 months old, it is not surprising that I found more than a few pages. Google lists <a target="_blank" href="http://www.google.com/search?q=%22analysts+see+java+ee+dying+in+an+soa+world%22">~400 hits</a>. What I found to be quite interesting is what the various replies said &#8212; and what they didn&#8217;t say.</p>
<p>The immediate replies fall in three different categories:</p>
<ol>
<li>The &#8220;me too&#8221; replies: They simply link to the article or quote and rephrase in the attempt to explain what was clear in the first place. They don&#8217;t offer an own opinion. This is the biggest group in the set of replies.</li>
<li>The &#8220;that is not true!&#8221; and &#8220;how dare you!&#8221; replies: They simply state that the article is wrong and that they would have never thought such insolence possible (they tend to be personally offended). What they don&#8217;t do is to back up their opinion. Those replies are numerous as well.</li>
<li>The by far smallest group is the group of more or less usefull replies, replies that offer an opinion. The opinions vary in their support and rejection of the article and I certainly don&#8217;t agree with all those opinions. But that doesn&#8217;t matter, I can live with that. Different opinions are a good thing in itself. One of the better replies is probably &#8220;<a target="_blank" href="http://blogs.ittoolbox.com/eai/business/archives/is-java-ee-dying-with-soa-adoption-10643">Is JAVA EE Dying with SOA Adoption?</a>&#8220;.<br />
<em>However! </em>All those replies picked just one or other aspect of the article. I could not find one that addressed the article as a whole, none that mentioned the fundamental problems*.</li>
<li>In the interest of fairness I have to admit that there is a fourth group &#8212; luckily not all too numerous &#8211;, the &#8220;I always knew it!&#8221; replies from the .NET camp (e.g. <a target="_blank" href="http://michaelplatt.net/blogs/architecture/archive/2006/12/29/analysts-see-java-ee-dying-in-an-soa-world.aspx">this one</a>).  </li>
</ol>
<p>Far more can be gained by not looking at immediate replies but at the discussions triggered by them. I found particularly those forums and comments to be &#8230; well, &#8220;interesting&#8221;:<br />
<a target="_blank" href="http://java.meetup.com/15/boards/view/viewthread?thread=2021011">http://java.meetup.com/15/boards/view/viewthread?thread=2021011</a><br />
<a target="_blank" href="http://www.infoq.com/news/Java-EE-Demise-Report">http://www.infoq.com/news/Java-EE-Demise-Report</a><br />
And of course the obvious suspects:<br />
<a target="_blank" href="http://www.theserverside.com/news/thread.tss?thread_id=41283#213270">http://www.theserverside.com/news/thread.tss?thread_id=41283#213270</a><br />
<a target="_blank" href="http://www.theserverside.net/news/thread.tss?thread_id=41325">http://www.theserverside.net/news/thread.tss?thread_id=41325</a></p>
<p>This is a very sorry result. A controversial article that is sure to draw attention actually got very little direct response in terms of hard facts. No reply I found was able to dismount the article. To get better arguments I had to look at various discussions. Those discussions however contained all kinds of opinion: wrong and right, objective and religious, informed and misled &#8212; and of course the usual share of off-topic and &#8220;unpleasant&#8221; replies.</p>
<p>Controversial articles are a good thing. They may show new perspectives, revive deadlock situations, or just generally shake up things a bit. If the dust settles down, people should have at least a better understanding of the topic. However (in this particular case) the debate was held in relatively closed communities, not in the open limelight in which the article was placed. People just reading newstickers or otherwise not part of the respective developer communities (usually the ones with the money to spend on projects) won&#8217;t even know it took place. That&#8217;s a little unsatisfying.</p>
<p>PS: Please note that I checked only a part of the search results. If I missed the one article that really gets to the point, please provide that link. Thank you.</p>
<p>* just stay tuned, I&#8217;m not finished yet <img src='http://s2.wp.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  .</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/02/02/will-somebody-please-defend-java-ee/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/02/02/will-somebody-please-defend-java-ee/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/91/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/91/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/91/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=91&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/02/02/will-somebody-please-defend-java-ee/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/02/02/will-somebody-please-defend-java-ee/" medium="image" />
	</item>
		<item>
		<title>Shiny new web (german)</title>
		<link>http://ajdotnet.wordpress.com/2007/01/31/shiny-new-web/</link>
		<comments>http://ajdotnet.wordpress.com/2007/01/31/shiny-new-web/#comments</comments>
		<pubDate>Wed, 31 Jan 2007 18:08:13 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[SDX]]></category>
		<category><![CDATA[Software Developers]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/01/31/shiny-new-web-german/</guid>
		<description><![CDATA[This is some news for our german readers&#8230; &#60;language culture=&#8220;de-DE&#8220; /&#62; Der Web-Auftritt von SDX ist komplett überarbeitet, runderneuert und neu gestaltet worden. Für den Auftritt wurde diesmal eine Marketingagentur mit eingespannt (unsere Kunden kommen zu uns wenn sie professionelle Hilfe brauchen  &#8211; warum sollten wir das anders halten?). Die Agentur hat dann allerdings erstmal dafür [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=87&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is some news for our german readers&#8230; <a href="http://www.sdx-ag.de" target="_new"><img style="margin:5px;" src="http://ajdotnet.files.wordpress.com/2007/01/sdxlogo.gif?w=92&#038;h=28" alt="" width="92" height="28" align="right" /></a></p>
<p><span style="color:#0000ff;">&lt;<span style="color:#800000;">language</span> <span style="color:#ff0000;">culture</span>=<span style="color:#000000;">&#8220;</span>de-DE<span style="color:#000000;">&#8220;</span> /&gt;</span></p>
<blockquote><p> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  Der Web-Auftritt von <a href="http://www.sdx-ag.de" target="_blank">SDX</a> ist komplett überarbeitet, runderneuert und neu gestaltet worden.</p>
<p>Für den Auftritt wurde diesmal eine <a href="http://www.4ft.de/" target="_blank">Marketingagentur</a> mit eingespannt (unsere Kunden kommen zu uns wenn sie professionelle Hilfe brauchen <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  &#8211; warum sollten wir das anders halten?).<br />
Die Agentur hat dann allerdings erstmal dafür gesorgt, daß wir alle den Kopf <a href="http://www.sdx-ag.de/jobs/j-news.aspx#september" target="_blank">hinhalten</a> müssen&#8230; <img src='http://s1.wp.com/wp-includes/images/smilies/icon_eek.gif' alt='8O' class='wp-smiley' /> . (Die Erfahrung war&#8217;s wert, aber ein Jobwechsel kommt nicht in Betracht.)</p>
<p>Viele Stunden und einige Abende gingen dann noch für&#8217;s Texten drauf &#8212; kein SDX&#8217;ler der nicht seinen Anteil daran hätte &#8212; und é voilà, das neue <a href="http://www.sdx-ag.de" target="_blank">www.sdx-ag.de</a>.</p>
<p>Und Schuld an allem ist <a href="http://www.sdx-ag.de/sdxag.aspx" target="_blank">diese Dame</a>! (Ehre wem Ehre gebührt! <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  )</p>
<p> <img src='http://s1.wp.com/wp-includes/images/smilies/icon_arrow.gif' alt=':arrow:' class='wp-smiley' />  <a href="http://www.sdx-ag.de/jobs.aspx" target="_blank">http://www.sdx-ag.de/jobs.aspx</a></p></blockquote>
<p><span style="color:#0000ff;">&lt;/<span style="color:#800000;">language</span>&gt; </span></p>
<p><span style="color:#008000;">That&#8217;s all for now folks,<br />
</span><span style="color:#000080;"><strong>AJ@SDX</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/01/31/shiny-new-web/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/01/31/shiny-new-web/" border="0" alt="" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/87/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/87/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/87/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=87&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/01/31/shiny-new-web/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2007/01/sdxlogo.gif" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/01/31/shiny-new-web/" medium="image" />
	</item>
		<item>
		<title>ViewState State &#8230;</title>
		<link>http://ajdotnet.wordpress.com/2007/01/26/viewstate-state/</link>
		<comments>http://ajdotnet.wordpress.com/2007/01/26/viewstate-state/#comments</comments>
		<pubDate>Fri, 26 Jan 2007 20:23:12 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/01/26/view-viewstate-state-and-control-controlstate-state/</guid>
		<description><![CDATA[View state is one of those areas the one can use without actually understanding it. But dealing with view state correctly is mandatory when designing a custom control. &#8220;Design&#8221; in this case begins only after understanding view state technically and includes dealing with various view state implications, leveraging view state for advanced tasks, or gracefully falling [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=85&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>View state is one of those areas the one can use without actually understanding it. But dealing with view state correctly is mandatory when designing a custom control. &#8220;Design&#8221; in this case begins only after understanding view state technically and includes dealing with various view state implications, leveraging view state for advanced tasks, or gracefully falling back if view state is switched of.<br />
However, trying to find a complete and sufficient coverage of view state turns out to be &#8230;, well. Anyway, those hints might help:</p>
<p>The <strong>starting point </strong>in MSDN for view state is probably &#8220;<a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms178197">ASP.NET View State</a>&#8220;. The better introduction may be &#8220;<a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms972976.aspx">Understanding ASP.NET View State</a>&#8220;, but it only covers ASP.NET 1.1.<br />
You may also want to have a look at  &#8221;<a target="_blank" href="http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx">TRULY Understanding ViewState</a>&#8220;. Despite falling short of its own claims (to give a complete coverage of the topic, yet view state persistence is omitted and security issues are missing), it&#8217;s written quite amusing and also explains some misuse scenarios.</p>
<p>To get a better feeling for <strong>the problem side</strong> (ever had a grid with a dataset containing 16000 rows in viewstate?), this link might provide some insight: &#8220;<a target="_blank" href="http://blogs.msdn.com/tess/archive/2006/11/24/asp-net-case-study-bad-perf-high-memory-usage-and-high-cpu-in-gc-death-by-viewstate.aspx">Death By ViewState</a>&#8221; (&#8220;I get enough issues relating to bad perf caused by large viewstate that I felt like it is time to dedicate some blog space to it, so here is a typical problem description for this type of problem.&#8221;)</p>
<p>The article &#8220;<a target="_blank" href="http://msdn.microsoft.com/msdnmag/issues/04/10/ViewState/">Speed Up Your Site with the Improved View State in ASP.NET 2.0</a>&#8221; talks about <strong>improvements in ASP.NET 2.0</strong>, yet it forgot to mention &#8220;<a target="_blank" href="http://msdn2.microsoft.com/en-us/library/aa479403.aspx">ASP.NET 2.0 Page State Persister</a>&#8220;. Persisters provide a way to manage view state persistence (aptly named, aren&#8217;t they?), e.g. in the session instead of on the wire (which causes other problems&#8230; &#8212; but this might become another post <font size="2"> <img src='http://s2.wp.com/wp-includes/images/smilies/icon_twisted.gif' alt=':twisted:' class='wp-smiley' /> </font>).</p>
<p>And by the way, there is a new thing in ASP.NET 2.0, called <strong>control state</strong>. Which is much like view state (technically identical), but there actually <em>is </em>a difference. See &#8221;<a target="_blank" href="http://msdn2.microsoft.com/en-us/library/1whwt1k7.aspx">Control State vs. View State Example</a>&#8220; to get a better idea.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/01/26/viewstate-state/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/01/26/viewstate-state/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/85/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/85/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=85&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/01/26/viewstate-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/01/26/viewstate-state/" medium="image" />
	</item>
		<item>
		<title>Coding conventions (addendum)</title>
		<link>http://ajdotnet.wordpress.com/2007/01/20/coding-conventions-addendum/</link>
		<comments>http://ajdotnet.wordpress.com/2007/01/20/coding-conventions-addendum/#comments</comments>
		<pubDate>Sat, 20 Jan 2007 16:50:41 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/01/20/coding-conventions-addendum/</guid>
		<description><![CDATA[After thinking about my last post about that topic, I thought some additional information for people wondering about where to start with coding conventions might be prudent: ANY coding convention will be better than NO coding convention. If you have no convention in place, MSDN provides a good starting point: &#8220;NET Framework General Reference &#8212; Design Guidelines [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=84&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After thinking about my last <a href="http://ajdotnet.wordpress.com/2007/01/06/coding-conventions-are-a-precondition-to-readability/">post</a> about that topic, I thought some additional information for people wondering about where to start with coding conventions might be prudent:</p>
<ol>
<li>ANY coding convention will be better than NO coding convention.</li>
<li>If you have no convention in place, MSDN provides a good starting point: &#8220;<a target="_blank" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconnetframeworkdesignguidelines.asp">NET Framework General Reference &#8212; Design Guidelines for Class Library Developers</a>&#8220;.</li>
<li>An alternative or extension may be the following <a target="_blank" href="http://submain.com/blog/FreeCVBNETCodingGuidelinesEbookDownload.aspx">download</a>.</li>
</ol>
<p>If you followed conventions implied in existing classes and code but have never read a formalized document, I recommend doing it. You may find same clarification (as the people at Microsoft did no allways follow their own conventions), so reading MSDN might be enlighting.<br />
People who change projects or customers regularly should ask for the coding conventions when beginning to work in a new project. This will save you from later trouble. And in case there is none, that might tell you something about the state of the project.</p>
<blockquote><p>At <a target="_blank" href="http://www.sdx-ag.de">SDX</a> we built our set of conventions upon the MSDN guidenlines (apart from saving effort, this avoids unnecessary discussions) and added conventions regarding file and directory structures, commenting, and other things. We complemented this with similar conventions for XML, guidelines regarding project setup (tool set, source code control, automated testing, …), and delivery templates (project document, installation document, …).<br />
One major intention we had in mind was: All this is meant to guide and assist the developers, to help them doing their day-to-day work. We did not want to create a bureaucracy that gets in the way of the developer and creates additional burden.</p></blockquote>
<p>A little bit beyond simple coding conventions, yet a usefull addition is &#8220;<a target="_blank" href="http://www.amazon.com/Framework-Design-Guidelines-Conventions-Development/dp/0321246756/sr=8-1/qid=1169241926/ref=pd_bbs_sr_1/104-6581173-4127944?ie=UTF8&amp;s=books">Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries</a>&#8220;.<br />
Another book that covers coding style and quite a few other topics (and is one of my all-time-favourites &#8212; I own the first edition published &#8217;93): &#8220;<a target="_blank" href="http://www.amazon.com/Code-Complete-Second-Steve-McConnell/dp/0735619670/sr=8-1/qid=1169312149/ref=pd_bbs_sr_1/104-6581173-4127944?ie=UTF8&amp;s=books">Code Complete</a>&#8220;, <a target="_blank" href="http://www.stevemcconnell.com">Steve McConnell</a>.</p>
<p>And finally <a target="_blank" href="http://labnotes.org/">assaf</a>&#8216;s comment on another post deserves to be repeated: <a target="_blank" href="http://thedailywtf.com/Articles/Little_Black_Book.aspx">http://thedailywtf.com/Articles/Little_Black_Book.aspx</a> <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/01/20/coding-conventions-addendum/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/01/20/coding-conventions-addendum/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/84/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/84/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=84&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/01/20/coding-conventions-addendum/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/01/20/coding-conventions-addendum/" medium="image" />
	</item>
		<item>
		<title>Early 2000 and today&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2007/01/14/early-2000-and-today/</link>
		<comments>http://ajdotnet.wordpress.com/2007/01/14/early-2000-and-today/#comments</comments>
		<pubDate>Sun, 14 Jan 2007 16:29:43 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/01/14/early-2000-and-today/</guid>
		<description><![CDATA[Last week I did a little talk (about half a day) about XML. Nothing fancy, just trying to raise the level of basic knowledge for some people. I based this talk on a workshop I did early 2000. Which reminded me of the situation we had back then and how it evolved until today… Early [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=78&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Last week I did a little talk (about half a day) about XML. Nothing fancy, just trying to raise the level of basic knowledge for some people. I based this talk on a workshop I did early 2000. Which reminded me of the situation we had back then and how it evolved until today…</p>
<p><strong>Early 2000 </strong>was in the middle of the XML hype, XML was the silver bullet.<br />
<strong>Today </strong>we don&#8217;t even mention XML anymore, we just use it.</p>
<p><strong>Early 2000 </strong>we had the core XML standard, yet the other family members were still in their infancy, which usually led to the usage of precursory &#8212; read inconsistent and proprietary &#8212; technologies.<br />
<strong>Today </strong>we have what I call the XML family, namely XML, XML namespaces, XSD, XPath, and XSLT, and everybody has agreed on those.</p>
<p><strong>Early 2000 </strong>we built a prototype application that had a server part serving XML (read Web Service), used heavy scripting in IE, exchanged XML data asynchonously with the server, and provided rich editing capability known the only in rich client applications. Then we abandoned it. Proprietary technology.<br />
<strong>Today </strong>the dead horse (read AJAX) is riding again and even triggered a new hype. And it&#8217;s probably here to stay.</p>
<p><a target="_blank" href="http://ajdotnet.files.wordpress.com/2007/01/wap.png"></a><strong>Early 2000 </strong>we had another hype called WAP &#8212; which burned out and died. But in this context we also speculated about push technologies as replacement for SMS.<br />
<strong>Today </strong>we have blackberry.</p>
<p><strong>Early 2000 </strong>we were in the the middle of the &#8220;<a target="_blank" href="http://www.amazon.com/Com+-Battle-Middle-Roger-Sessions/dp/0471317179">Battle for the Middle Tier</a>&#8220;, seeing the two major camps &#8212; Microsoft with COM based (read whatever you like) MTS/COM+ against EJB &#8212; fighting for the application server market, Microsoft on the loosing side.<br />
<strong>Today </strong>Microsoft has caught up with .NET, the java community has rediscovered light-weight approaches, and heterogenous environments where both camps work nicely together are far from unusual.</p>
<p><strong>Early 2000 </strong>we had a little hype about SOAP and an early notion of WebServices. Mainly it was a protocol intended by Micrososft to gain access to the java world, supported by IBM to gain access to the Microsoft world… . This hype would have died, had it not had such prominent supporters that kept it alive until additional technologies had been set up to constitute the next hype: SOA.<br />
<strong>Today </strong>we have SOA, used to cultivate heterogenity on the technical level, but more importantly to reshape whole companies on the business level.</p>
<p><strong>Early 2000 </strong>I thought I allready know a lot about technology.<br />
<strong>Today </strong>I know how much I did not know then. Which makes me wonder about the years to come.</p>
<p>What else did I learn from these observations?</p>
<ol>
<li>Hypes come and go. They are important, they take us somewhere, surprisingly mostly forward. Unfortunately you never know where &#8220;forward&#8221; actually is until you are there.</li>
<li>Fighting over technologies isn&#8217;t worth the effort. Any technology with serious support is likely to stay, technologies without will die. This is only loosely related to the quality particular technologies.</li>
</ol>
<p>Sorry if I got a little nostalgic, maybe due to the change of the year and my approaching birthday… <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/78/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/78/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/78/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=78&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/01/14/early-2000-and-today/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Coding conventions are a precondition to readability</title>
		<link>http://ajdotnet.wordpress.com/2007/01/06/coding-conventions-are-a-precondition-to-readability/</link>
		<comments>http://ajdotnet.wordpress.com/2007/01/06/coding-conventions-are-a-precondition-to-readability/#comments</comments>
		<pubDate>Sat, 06 Jan 2007 20:57:39 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2007/01/06/coding-conventions-are-a-precondition-to-readability/</guid>
		<description><![CDATA[The other day I talked to a collegue about some technical details and doing this I took notes directly in code. When we finished this collegue asked me not to delete these comments. A little peculiar in itself (who would have done such a thing?) in this particular case the comment had a double meaning: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=77&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The other day I talked to a collegue about some technical details and doing this I took notes directly in code. When we finished this collegue asked me <em>not to delete these comments</em>. A little peculiar in itself (who would have done such a thing?) in this particular case the comment had a double meaning: The code being some more or less complex mapping of numeric ranges would not have been comprehensible without comments. And in my opinion <strong>incomprehensible code is worse than bad code</strong>. Bad code can be fixed after all.</p>
<p>About the same time I stumbled over an article that pointed to &#8220;<a target="_blank" href="http://blog.labnotes.org/2006/12/01/proof-reading-is-more-important-than-composition/">Proof reading is more important than composition</a>&#8220;. The authors opinion about readability is something to applaud. All the more irritating how wrong his conclusions are (just my opinion of course!). He deprecates coding conventions as being of adverse effect for readability. Having worked on software in teams of up to 80 developers and of different age (in terms of versions and maintenance impact) I am accustomed to read and evolve existing code as well as write code that has to be understood by other developers after I have moved on. And of one thing I am certain: <strong>Coding conventions are a necessary requirement for readability.</strong> Of course they are not sufficient, but do away with them and readability will follow shortly. All it needs is the next developer working on the code and using his personal coding style. This has to happen only once, no way to put the chicken back in the egg.</p>
<p>While the author of this article started with a right assumption and quickly got it wrong, the author of <a target="_blank" href="http://tomhobbs.wordpress.com/2006/12/11/you-are-obligated-to-make-your-code-maintainable/">the article that pointed to it</a> did the opposite: He started with a wrong assumption (&#8220;few people actually … are going to come back and read that code&#8221; &#8212; if the code matters, people <em>will</em> come back) but he quickly gets it right. I especially like his distinction between programmers and developers:</p>
<ul>
<li>Programmers write code to solve problems</li>
<li>Developers write code that can be read by other people and to solve problems</li>
</ul>
<p>I recommend reading <a target="_blank" href="http://tomhobbs.wordpress.com/2006/12/11/you-are-obligated-to-make-your-code-maintainable/">that post</a> because the author makes some good points getting there and even better ones based on that statement.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2007/01/06/coding-conventions-are-a-precondition-to-readability/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/01/06/coding-conventions-are-a-precondition-to-readability/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/77/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/77/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=77&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2007/01/06/coding-conventions-are-a-precondition-to-readability/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2007/01/06/coding-conventions-are-a-precondition-to-readability/" medium="image" />
	</item>
		<item>
		<title>It&#8217;s christmas time&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2006/12/16/its-christmas-time/</link>
		<comments>http://ajdotnet.wordpress.com/2006/12/16/its-christmas-time/#comments</comments>
		<pubDate>Sat, 16 Dec 2006 20:52:14 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Software Developers]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/12/16/its-christmas-time/</guid>
		<description><![CDATA[&#8230; and Christmas means presents. Well, here&#8217;s my present for you: I just finished a first version of my AddIn v2.0 for Visual Studio 2005. Its focus is on code navigation: navigate C# code files with cursor keys, e.g. Ctrl-Down to go to the next type, method or whatever (something I got used to under [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=76&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a target="_new" href="http://en.wikipedia.org/wiki/Image:Juletr%C3%A6et.jpg"><img align="right" width="215" src="http://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Juletr%C3%A6et.jpg/215px-Juletr%C3%A6et.jpg" height="296" style="margin:0 0 5px 5px;" /></a></p>
<p>&#8230; and Christmas means presents. Well, here&#8217;s my present for you:</p>
<p>I just finished a first version of my <a href="http://www.alexander-jung.net/download/ajaddin2.zip">AddIn v2.0 for Visual Studio 2005</a>. Its focus is on code navigation:</p>
<ol>
<li>navigate C# code files with cursor keys, e.g. Ctrl-Down to go to the next type, method or whatever (something I got used to under Eclipse).</li>
<li>browse solution files or types and quickly jump to the one you need using filter criterions (similar to the respctive dialogs in ReSharper).</li>
</ol>
<p>There are more details in the readme and help file.</p>
<p>The addin has been tested by me and some friends and should be reasonably stable. It is however a first version and may have some bugs, in this case please sent me the stack trace from the output window.</p>
<p>Also I decided to get it out (in order to get feedback) as early as feasible rather than trying to do the 110% implementation. Therefore there is &#8220;room for improvement&#8221; in several areas (e.g. showing method signatures, browse inherritance hierarchy, and other stuff). Any comments and wishes regarding future development are welcome as well.</p>
<p><a target="_new" href="http://en.wikipedia.org/wiki/Image:Sydney_New_Year%27s_Eve_2.jpg"><img align="left" width="133" src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Sydney_New_Year%27s_Eve_2.jpg/290px-Sydney_New_Year%27s_Eve_2.jpg" height="100" style="margin:0 5px 0 0;" /></a></p>
<p>Christmas also means even less time than usual; christmas dinners, visiting of relatives, etc. take their toll.</p>
<p>Since this is probably my last post for 2006 I wish you all a peacefull christmas and a happy new year.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/12/16/its-christmas-time/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/12/16/its-christmas-time/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/76/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/76/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/76/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=76&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/12/16/its-christmas-time/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Juletr%C3%A6et.jpg/215px-Juletr%C3%A6et.jpg" medium="image" />

		<media:content url="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Sydney_New_Year%27s_Eve_2.jpg/290px-Sydney_New_Year%27s_Eve_2.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/12/16/its-christmas-time/" medium="image" />
	</item>
		<item>
		<title>Got GAT?</title>
		<link>http://ajdotnet.wordpress.com/2006/12/02/got-gat/</link>
		<comments>http://ajdotnet.wordpress.com/2006/12/02/got-gat/#comments</comments>
		<pubDate>Sat, 02 Dec 2006 12:38:17 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/12/02/got-gat/</guid>
		<description><![CDATA[I have been working with the Guidance Automation Toolkit (GAT) for some time now and thought I could give you a little motivation to look into it yourself. What is GAT anyway? GAT is a framework to build Visual Studio addins of a certain kind. Emphasis here is on the &#8216;G&#8217; in GAT, G like [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=75&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://en.wikipedia.org/wiki/Lego"><img align="right" width="180" src="http://upload.wikimedia.org/wikipedia/en/thumb/c/c4/Legobrick.jpg/180px-Legobrick.jpg" height="122" /></a></p>
<p>I have been working with the <a target="_blank" href="http://msdn.microsoft.com/vstudio/teamsystem/Workshop/gat/intro.aspx">Guidance Automation Toolkit (GAT)</a> for some time now and thought I could give you a little motivation to look into it yourself.</p>
<p><strong>What is GAT anyway?</strong></p>
<p>GAT is a framework to build Visual Studio addins of a certain kind. Emphasis here is on the &#8216;G&#8217; in GAT, G like &#8220;<em>Guidance</em>&#8220;. GAT makes it very easy to provide the user of the GAT package you developed (i.e. another developer) with templates, snippets, and most importantly with wizards and the ability to fullfill complex tasks. Typical usage scenarioas may include:</p>
<ul>
<li>Create a new class (boilerplate code), say an exception or form, based on user input (wizard), register it with some kind of configuration (complex task), enterprise library <a target="_blank" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/entlibjan2006_exceptionhandlingappblock.asp">exception handling</a> or <a target="_blank" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/uipab.asp">UIP application block</a>, and update the project structure accordingly, i.e. create the project entry, deal with SCC, etc. (again comlex task)</li>
<li>Create code based on some configuration or other information. E.g. generate standard web pages supporting display and <a target="_blank" href="http://en.wikipedia.org/wiki/Create%2C_read%2C_update_and_delete">CRUD operations</a> on data, based on an existing dataset or XML schema.</li>
<li>Create your own wrapper class for some service description (like WSDL or other) that adresses special needs such as error handling or logging.</li>
</ul>
<p>In other words, use GAT &#8230;</p>
<ul>
<li>whenever you have to create a new code file that is boilerplate but requires a few parameters (a Wizard) and is a little too complex for code snippets.</li>
<li>whenever you have to create a family of related code files (as group, all or none), say a form and accompanying resource and configuration file.</li>
<li>whenever creating a new file requires addition work, like registering it in a central configuartion file</li>
<li>whenever work shall be triggered via context menu entries on project items</li>
<li>whenever these things span multiple projects or depend on project types</li>
<li>whenever these things need to be done &#8220;transactional&#8221;, i.e. support an undo mechanism</li>
</ul>
<p><strong>How does it work?</strong></p>
<p>GAT is a bit like <a target="_blank" href="http://en.wikipedia.org/wiki/Lego">Lego</a>. It&#8217;s a set of small building blocks of different type and for different purpose. There are references, type converters (<a href="http://ajdotnet.wordpress.com/2006/11/18/more-on-type-converters/">rings a bell</a>, doesn&#8217;t it? <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ), value providers, actions, all playing nicely together. Just like with Lego you have to know how the pices work together, not only where to fit them in but how to shape them into a working system. On the other hand, many of the components you will undoubtedly have to write tend to be very reusable &#8212; if you do it carefully &#8212; and quite often are unrelated to the specific task at hand. A recipe to update a config file for web applications? A type converter that provides a list of the web projects within the current solution &#8212; or better yet, it can be configured to show this or that kind of projects &#8212; has nothing to do with the special config file.</p>
<p>The place for assembling the pieces into a larger system is a central XML file in each GAT package. Here you describe logical units of work, called recipes. A recipe usually contains four major parts:</p>
<ul>
<li>infrastructure information, like in which menu the recipe will be available, which text and icon it will show.</li>
<li>arguments or rather data declaration. This is where &#8220;variables&#8221; are declared and associated with type converters and value providers</li>
<li>a wizard to get information from the user</li>
<li>a sequence of actions to do the actual work</li>
</ul>
<p>This set up reminds me a bit of <a target="_blank" href="http://en.wikipedia.org/wiki/COBOL">COBOL</a> file structure <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>The XML file may contain multiple recipes and it also has some global infrastructure information, like name or help file URL. There is also a special recipe called during the registration of the GAT package, used to register the other recipes. This registration employs a reference object that further decides whether the respective recipe will be available or not (e.g. one may check the current project type and only allow the menu entry in web projects).</p>
<p>Recipes may be the the major concept in GAT but it certainly does not stop here. GAT also includes template engines (solution, project, and file templates), packages may install code snippets, and it comes with a management component for the end user (the &#8220;Guidance Package Manager&#8221;).</p>
<p><strong>What can&#8217;t be done?</strong></p>
<p>Whatever you do plainly with GAT is available via GAT only and surfaced to the user mainly via menu entries on project items (with the exception of solution and project templates). The consequences:</p>
<ul>
<li>No way to react on anything but menu entries, especially not on other Visual Studio events, say starting a recipe automatically when saving a file. To accomplish that you&#8217;ll have to build a regular addin the hardcore way.</li>
<li>No way to use the actions somewhere else, in paritular no way to leverage them within the build process. MSBuild support or some command line tool would be more suited to that need.</li>
<li>GAT is also not exactly suited to work &#8220;within&#8221; a file, i.e. provide recipes that modifies a part of an existing code file, available depending on the current cursor location. Something like &#8220;<em>Implement Interface</em>&#8221; or &#8220;<em>Encapsulate Field</em>&#8221; in the context menu depending on whether you are at the location of an interface or a field. Again this would be better done within a regular addin. (Fortunatelly someone within Microsoft allready thought of the examples I just mentioned&#8230;)</li>
</ul>
<p>It is not as if GAT is out of question in these cases. It just won&#8217;t solve all requirements and you need to carefully plan a layered implementation approach. Put core functionality in a Core.DLL and call it from a GAT action as well as from your favourite command line tool.</p>
<p><a target="_blank" href="http://en.wikipedia.org/wiki/...Famous_Last_Words…"><strong>Famous last words&#8230;</strong></a></p>
<p>Well, it has to be said: GAT is only a Technology Preview right now. It&#8217;s quite stable and fairly complete, but some things may need some improvement (user fedback in error cases, SCC awareness, shortcommings of existing components). Another issue is the documentation which is better than one would expect but still needs a good deal of improvement. And of course noone knows whether the next release will break existing code and no final release date has been announced yet.</p>
<p>Anyway, if the above description of GAT sounds like something you have been looking for I recommend to give it a try. For those interested: there is a <a target="_blank" href="http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=78">forum</a> in which you will even get feedback from the authors and a dedicated <a target="_blank" href="http://guidanceautomation.net/">GAT web site</a> which also has sample code.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET </strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/12/02/got-gat/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/12/02/got-gat/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/75/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/75/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/75/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=75&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/12/02/got-gat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/en/thumb/c/c4/Legobrick.jpg/180px-Legobrick.jpg" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/12/02/got-gat/" medium="image" />
	</item>
		<item>
		<title>Phantom property values</title>
		<link>http://ajdotnet.wordpress.com/2006/11/24/phantom-property-values/</link>
		<comments>http://ajdotnet.wordpress.com/2006/11/24/phantom-property-values/#comments</comments>
		<pubDate>Fri, 24 Nov 2006 21:40:55 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/11/24/phantom-property-values/</guid>
		<description><![CDATA[Here&#8217;s a quick tip for design time coders: Suppose you had a control or component and you would want to change a design time property from your code (say as reaction to a designer verb or the change of another property). Something like the following: [ToolboxData("&#60;{0}:PropertyTextBox runat=server /&#62;")] public class PropertyTextBox : TextBox {     public [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=73&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick tip for design time coders: Suppose you had a control or component and you would want to change a design time property from your code (say as reaction to a designer verb or the change of another property). Something like the following:</p>
<blockquote><p>[ToolboxData(<font color="#800000">"&lt;{0}:PropertyTextBox runat=server /&gt;"</font>)]<br />
<font color="#0000ff">public</font> <font color="#0000ff">class</font> PropertyTextBox : TextBox<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">string</font> StandardCss { &#8230; }<br />
    <font color="#0000ff">public</font> <font color="#0000ff">string</font> ErrorCss { &#8230; }<br />
    <br />
    <font color="#0000ff">bool</font> _noCssHandling;<br />
    <font color="#0000ff">public</font> <font color="#0000ff">bool</font> NoCssHandling<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> _noCssHandling; }<br />
        <font color="#0000ff">set</font><br />
        {<br />
            _noCssHandling = <font color="#0000ff">value</font>;<br />
            <font color="#0000ff">if</font> (_noCssHandling)<br />
            {<br />
                _standardCss = <font color="#800000">&#8220;&#8221;</font>;<br />
                _errorCss = <font color="#800000">&#8220;&#8221;</font>;<br />
            }<br />
        }<br />
    }<br />
}</p></blockquote>
<p>Looks good? OK. Put it on your page, switch to design view, go to the property dialog, and change the two string members. Now switch to code view and you&#8221;ll see the respective attributes in the contol tag:</p>
<blockquote><p><font color="#0000ff">&lt;<font color="#800000">cc1</font>:<font color="#800000">PropertyTextBox</font> <font color="#ff0000">ID</font>=&#8221;PropertyTextBox1&#8243; <font color="#ff0000">runat</font>=&#8221;server&#8221; <font color="#ff0000">ErrorCss</font>=&#8221;TextBoxError1&#8243; <font color="#ff0000">StandardCss</font>=&#8221;TextBox1&#8243;/&gt;</font></p></blockquote>
<p>Looks still good? OK. Switch to design view, change the property <em>NoCssHandling </em>to <em>true</em>, and enjoy the fact that the other two properties are miraculously set to empty.</p>
<p>Looks still good? Still content? Well, just for the fun of it switch to code view&#8230;</p>
<blockquote><p><font color="#0000ff">&lt;<font color="#800000">cc1</font>:<font color="#800000">PropertyTextBox</font> <font color="#ff0000">ID</font>=&#8221;PropertyTextBox1&#8243; <font color="#ff0000">runat</font>=&#8221;server&#8221; <font color="#ff0000">ErrorCss</font>=&#8221;TextBoxError1&#8243; <font color="#ff0000">NoCssHandling</font>=&#8221;True&#8221; <font color="#ff0000">StandardCss</font>=&#8221;TextBox1&#8243;/&gt;</font></p></blockquote>
<p>Wait a moment! Empty strings are not supposed to contain old values, right? You could even debug the code and verify that the dependend properties have been set and returned the correct values. And yet, within the markup code of your .aspx file the repective HTML attributes remain unchanged.</p>
<p><strong>Catching the phantom</strong></p>
<p>The reason for this effect is &#8230; I <em>may</em> have mentioned that before <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  &#8230; design time is different. At runtime you have only one instance of your object. At design time there may be phantoms, ghosts and astral bodies &#8211; different incarnations of the same object, shadows that reflect different time spans. There is but one file, but what you see is just one of possibly many presentations of that file in the appearance in which the current designer presents it. This may be the .aspx markup view, the design surface, the property dialog, the code view, the component view.</p>
<p>If one designer triggers a change on your object, none of the other designers knows about it. And thus, none will reflect that change, leaving the different designers in an inconsistent state. The trick is to announce the change to the other designers and the means to do that is the <em>IComponentChangeService </em>interface. (This is something you would only want to happen at design time to avoid unexpected behaviour at runtime.)</p>
<p>BTW: This is called Document/View concept, a derivation of the Model/View/Controller pattern and well known from MFC. No fairies or other surreal creatures. No <a target="_blank" href="http://en.wikipedia.org/wiki/Leprachaun">leprechauns</a> either, what a pity.)</p>
<p>Here is a version that takes the design time requirements into account: </p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">bool</font> NoCssHandling<br />
{<br />
    <font color="#0000ff">get</font> { <font color="#0000ff">return</font> _noCssHandling; }<br />
    <font color="#0000ff">set</font><br />
    {<br />
        _noCssHandling = <font color="#0000ff">value</font>;<br />
        <font color="#0000ff">if</font> (_noCssHandling)<br />
        {<br />
            <font color="#0000ff">if</font> ((<font color="#0000ff">this</font>.Site != <font color="#0000ff">null</font>) &amp;&amp; (<font color="#0000ff">this</font>.Site.DesignMode))<br />
            {<br />
                SetValue(<font color="#0000ff">this</font>, GetPropertyDescriptor(<font color="#0000ff">this</font>, <font color="#800000">&#8220;StandardCss&#8221;</font>), <font color="#800000">&#8220;&#8221;</font>);<br />
                SetValue(<font color="#0000ff">this</font>, GetPropertyDescriptor(<font color="#0000ff">this</font>, <font color="#800000">&#8220;ErrorCss&#8221;</font>), <font color="#800000">&#8220;&#8221;</font>);<br />
            }<br />
            <font color="#0000ff">else</font><br />
            {<br />
                _standardCss = <font color="#800000">&#8220;&#8221;</font>;<br />
                _errorCss = <font color="#800000">&#8220;&#8221;</font>;<br />
            }<br />
        }<br />
    }<br />
}</p>
<p><font color="#0000ff">static</font> PropertyDescriptor GetPropertyDescriptor(IComponent component, <font color="#0000ff">string</font> property)<br />
{<br />
    PropertyDescriptorCollection properties =<br />
        TypeDescriptor.GetProperties(component.GetType());<br />
    <font color="#0000ff">foreach</font> (PropertyDescriptor pd <font color="#0000ff">in</font> properties)<br />
    {<br />
        <font color="#0000ff">if</font> (pd.Name == property)<br />
        <font color="#0000ff">return</font> pd;<br />
    }<br />
    <font color="#0000ff">return</font> <font color="#0000ff">null</font>;<br />
}</p>
<p><font color="#0000ff">static</font> <font color="#0000ff">void</font> SetValue(IComponent component, PropertyDescriptor pd, <font color="#0000ff">object</font> <font color="#0000ff">value</font>)<br />
{<br />
    <font color="#0000ff">object</font> oldValue = <font color="#0000ff">null</font>;<br />
    IComponentChangeService componentChangeService = (IComponentChangeService)<br />
        component.Site.GetService(<font color="#0000ff">typeof</font>(IComponentChangeService));<br />
    <br />
    <font color="#0000ff">if</font> (componentChangeService != <font color="#0000ff">null</font>)<br />
    {<br />
        <font color="#0000ff">try</font><br />
        {<br />
            <font color="#008000"><em>// rememeber old value</em></font><br />
            oldValue = pd.GetValue(component);<br />
            <font color="#008000"><em>// announce before change</em></font><br />
            componentChangeService.OnComponentChanging(component, pd);<br />
        }<br />
        <font color="#0000ff">catch</font> (CheckoutException ex)<br />
        {<br />
            <font color="#008000"><em>// under source control, the checkout may be canceled by the user</em></font><br />
            <font color="#0000ff">if</font> (ex != CheckoutException.Canceled)<br />
                <font color="#0000ff">throw</font>;<br />
        }<br />
    }<br />
    <br />
    <font color="#0000ff">try</font><br />
    {<br />
        <font color="#008000"><em>// try to set new value</em></font><br />
        pd.SetValue(component, <font color="#0000ff">value</font>);<br />
    }<br />
    <font color="#0000ff">catch</font><br />
    {<br />
        <font color="#0000ff">value</font> = oldValue;<br />
        <font color="#0000ff">throw</font>;<br />
    }<br />
    <font color="#0000ff">finally</font><br />
    {<br />
        <font color="#008000"><em>// announce after change</em></font><br />
        <font color="#0000ff">if</font> (componentChangeService != <font color="#0000ff">null</font>)<br />
            componentChangeService.OnComponentChanged(component, pd, oldValue, <font color="#0000ff">value</font>);<br />
    }<br />
}</p></blockquote>
<p>Well, that&#8217;s fairly much code just to set a property value. And to announce it to the design time environment. And to take source control and other effects into account. And it&#8217;s not even property specific? Wow. Reusable and a good candidate for a helper class. Not much code if you really think about it.</p>
<p>From now on, your property value changes at design time will be properly advertised to all designers and they will happily reflect those changed values.</p>
<p><font color="#008040">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/11/24/phantom-property-values/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/11/24/phantom-property-values/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/73/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/73/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=73&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/11/24/phantom-property-values/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/11/24/phantom-property-values/" medium="image" />
	</item>
		<item>
		<title>More (on) type converters</title>
		<link>http://ajdotnet.wordpress.com/2006/11/18/more-on-type-converters/</link>
		<comments>http://ajdotnet.wordpress.com/2006/11/18/more-on-type-converters/#comments</comments>
		<pubDate>Sat, 18 Nov 2006 14:15:25 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/11/18/more-on-type-converters/</guid>
		<description><![CDATA[After the last post I thought I might come up with some real world examples. Just to give you an idea how usefull type converters can be at design time. Configured lists There are various situations where a string property should be set to a value from a given set (if only non-exclusive default values [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=72&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After the last <a href="http://ajdotnet.wordpress.com/2006/11/11/reach-out-at-design-time/">post</a> I thought I might come up with some real world examples. Just to give you an idea how usefull type converters can be at design time.</p>
<p><strong>Configured lists</strong></p>
<p>There are various situations where a string property should be set to a value from a given set (if only non-exclusive default values to speed up typing), the set being (made) available in some kind of configuration file. Examples I encountered so far include:</p>
<ul>
<li>appSettings keys</li>
<li>navigation graph information for the <a target="_blank" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/uip.asp">User Interface Process (UIP) Application Block</a></li>
<li>named permissions on buttons</li>
<li>standard IDs for textboxes, buttons, etc.</li>
</ul>
<p>In this case a type converter that reads an the web.config and returns the /configuration/appSettings/add/@key values solves the first demand. The step to a type converter base class that reads any xml file and provides a list of values according to some XPath expression is no rocket science. Given that base class any of those examples can be implemented using a simple derived class that only has to specify the file and XPath.</p>
<p><strong>Artificial Enumerations </strong></p>
<p>Consider the following (quite common) situation: You have an enumeration of certain values for some property of your component. The component shall act as base class and will be extended in different contexts. For example, a database action enumeration could include values like <em>Save</em>, <em>Delete </em>and <em>Update</em>.<br />
The first approach that comes to mind would be to define a C# enumeration and the respective property. Afterwards your property can be set in the properties pane, the pane will automatically present a drop down list of the enumeration values, not allowing any other input. Of course working on the code level with eumerations is type safe and supported with intellisense.</p>
<p>However there is also a serious issue: The set of valid values for that property cannot be extended. .NET does not support something like inherritance of enumerations. If the derived class should need additional values one could either provide some special enumeration value in the base class for future use (some kind of &#8220;Custom&#8221;) and add an additional property to describe that custom value (making the act of describing the database action a two-stage process), or extend the enumeration with the custom value itself (spoiling the base class with information of derived functionality, making it visible to any other derived class and causing maintenance hurdles).</p>
<p>One could also revert to using a string instead of an enumeration. This would allow free choice of values and keep the base class clean of special cases. On the down side would be the lack of design time support, intellisense support (this could be solved with constants, yet this doesn&#8217;t help within the designer), and the need to remember all valid values in a given context. I see typos having a party&#8230;</p>
<p>Frankly, if these are the alternatives, I would prefer the spoiled enumeration.</p>
<p>However, a TypeConverter can help with these issues:<br />
First, some attributes could describe the valid values of a property (they have to be specified somehow and an attribute looks good for me). A derived class could use one of these attributes to extend the set defined by the base class (say an attribute at the class level could take the name of the property and the additional values).<br />
A type converter could then examine the property (the information is available through the context parameter) and the respective attributes along the inherritance hierarchy to build up a list of values which in turn causes the property grid to show a drop down list at design time. What&#8217;s more, the list will vary depending on the context, showing only the values that make sense in the given situation. Voilá, a string property with &#8220;extendable enumeration behaviour&#8221; at runtime.</p>
<p><strong>Reflection information</strong></p>
<p>Sometimes one needs to specify types (for dynamically created objects), methods (to be invoked dynamically), or properties (to get data from). All respective candidates (say all properties of an object) can be made available at designtime, given the right type converter.</p>
<p><strong>Solution or project information</strong></p>
<p>For navigation to another page it would be usefull to have a list of .aspx files in your project to select the page at design time. A type converter could get this list using the Visual Studio automation model.<br />
This area is especially usefull if you are working with the <a target="_blank" href="http://msdn2.microsoft.com/en-us/teamsystem/aa718948.aspx">Guidance Automation Toolkit (GAT)</a> where type converters play a role in providing and converting informations for and from wizards. Examples include a list of projects, base classes, or the conversion of a project folder to a respective namespace for a new class.</p>
<p><strong>Real type conversion</strong></p>
<p>We should not forget the function type converters have by name. If you have a look at a windows form control at design time (the windows forms designer seems to make better use of this than the webforms designer), you will notice that you can type in something like &#8220;75;50&#8243; in the properties pane for the Size property. You may also click on the little + and set the Width and Height property directly. The ability to set the values of contained properties (in this case Width and Height) on the object itself (in this case Size) comes with a &#8230; guess what? &#8230; type converter. In this case it converts the string with two numbers to an instance of the Size struct and vice versa.<br />
Thus type converters can help to simplify the modification of properties of complex structs.</p>
<p>Code? Sorry, not this time. These are all real world examples from actual projects. I can share knowledge and experience but not customers&#8217; code.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/11/18/more-on-type-converters/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/11/18/more-on-type-converters/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/72/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/72/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=72&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/11/18/more-on-type-converters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/11/18/more-on-type-converters/" medium="image" />
	</item>
		<item>
		<title>Reach out at design time</title>
		<link>http://ajdotnet.wordpress.com/2006/11/11/reach-out-at-design-time/</link>
		<comments>http://ajdotnet.wordpress.com/2006/11/11/reach-out-at-design-time/#comments</comments>
		<pubDate>Sat, 11 Nov 2006 16:05:55 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/11/11/reach-out-at-design-time/</guid>
		<description><![CDATA[Some developers are not even aware that their code actually runs at design time. Others try to ignore that fact as long as possible. One reason for this is probably this: design time is different. Not just &#8220;not runtime&#8221;, but really different. The weird kind of different. Like Babylon 5 hyperspace where physical laws don&#8217;t [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=64&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Some developers are not even aware that their code actually runs at design time. Others try to ignore that fact as long as possible. One reason for this is probably this: design time is different. Not just &#8220;not runtime&#8221;, but really different. The weird kind of different. Like <a target="_blank" href="http://en.wikipedia.org/wiki/Babylon_5">Babylon 5</a> hyperspace where physical laws don&#8217;t apply. Objects get instantiated with the type of their base class, some events occure while others don&#8217;t, types may not be available or change their version, data that depends on configuration will be unconfigured, context information available at runtime will not be present, and so on.</p>
<p>There are usually two reasons to have to look into design time: One is some issue at design time, e.g. a control that no longer renders itself properly. The other is the desire to provide better design time support.</p>
<p>There are several &#8220;levels of design time involvement&#8221; of your code:</p>
<ol>
<li>Regular code that does <strong>not run at design time</strong>. We can safely ignore this code from now on. It&#8217;s still worth mentioning since it is sometimes quite important to know whether the code will be called or not (e.g. in the case of certain events).</li>
<li>Regular code that runs at design time and may need to <strong>protect itself</strong> for unexpected context data. This is usually adressed with defensive programming style (check every object, don&#8217;t expect certain contexts, e.g. a request, etc.) or with explicitely checking for design time (i.e. testing <em>Component.Site.DesignMode</em>)</li>
<li>Regular code that is (perhaps primarily) intended to be <strong>used at design time </strong>(yet still may play a role at runtime). <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.componentmodel.typeconverter.aspx">TypeConverters</a> are a perfect example since they are used at design time to check inputs within the properties pane and also to provide the values shown in the drop down list of the property (e.g. for properties of an enumeration type).</li>
<li>Code that uses the<strong> design time services</strong> offered by the environment (i.e. the .NET Framework based design time support). This code can run only in design time and plays no role at runtime. The design time services are available with calls to <em>GetService</em> (offered by various objects within the design time model).</li>
<li>Code that also uses the <strong>Visual Studio automation model</strong>. While the design time services offer only limited support, the automation model (based on COM and also available to VBA) open up the whole Visual Studio as playground, including access to the solution structure.</li>
</ol>
<p>Let&#8217;s look into these levels with some concrete examples:</p>
<p><strong>1. Regular code not running at designtime </strong></p>
<p>Done. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>2. Regular code running at designtime </strong></p>
<p>Have look at the following label class, intended to show the current request URL:</p>
<blockquote><p>[ToolboxData(<font color="#800000">"&lt;{0}:UrlLabel runat=server /&gt;"</font>)]<br />
<font color="#0000ff">public</font> <font color="#0000ff">class</font> UrlLabel : Label<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">string</font> CurrentUrl<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> <font color="#0000ff">this</font>.Page.Request.Url.AbsoluteUri; }<br />
    }<br />
    <br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> <font color="#0000ff">string</font> Text<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> CurrentUrl; }<br />
    }<br />
}</p></blockquote>
<p>This innocent looking code will work properly at runtime, yet at design time it looks like this:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2006/11/urllabel.png" /></p>
<p>The reason is that the accessed objects in the property are not what they are expected to be. The page may be there but in case you don&#8217;t know, the actual page class is the base class of the class used at runtime. And of course the request object is <em>null</em>, since there <em>is </em>no request. Here&#8217;s a version of the property that adresses these issues:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">string</font> CurrentUrl<br />
{<br />
    <font color="#0000ff">get</font><br />
    {<br />
        <font color="#0000ff">if</font> ((<font color="#0000ff">this</font>.Site != <font color="#0000ff">null</font>) &amp;&amp; <font color="#0000ff">this</font>.Site.DesignMode)<br />
            <font color="#0000ff">return</font> <font color="#800000">&#8220;http://www.designtime-is-fun.com&#8221;</font>;<br />
        <font color="#0000ff">return</font> <font color="#0000ff">this</font>.Page.Request.Url.AbsoluteUri;<br />
    }<br />
}</p></blockquote>
<p>This solved the problem at design time:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2006/11/urllabel2.png" /></p>
<p>At runtime, both versions look the same:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2006/11/urllabel_r.png" /></p>
<p>Better?</p>
<p><strong>3. Regular code that supports design time</strong></p>
<p>There&#8217;s plenty of areas to support the design time experience. The most commonly used things are attributes on classes and properties and <em>TypeConverter</em>s. <em>TypeConverter</em>s are used at design time to check the values typed in the properties pane and also to provide the content of a drop down list provided there. Of course they stilll have value at runtime, e.g. to interpret configuration data.</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> NamesTypeConverter : TypeConverter<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> <font color="#0000ff">bool</font> GetStandardValuesSupported<br />
        (ITypeDescriptorContext context)<br />
    {<br />
        <font color="#0000ff">return</font> <font color="#0000ff">true</font>;<br />
    }<br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> <font color="#0000ff">bool</font> GetStandardValuesExclusive<br />
        (ITypeDescriptorContext context)<br />
    {<br />
        <font color="#0000ff">return</font> <font color="#0000ff">false</font>;<br />
    }<br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> StandardValuesCollection GetStandardValues<br />
        (ITypeDescriptorContext context)<br />
    {<br />
        StandardValuesCollection values =<br />
            <font color="#0000ff">new</font> StandardValuesCollection(<font color="#0000ff">new</font> <font color="#0000ff">string</font>[] { <font color="#800000">&#8220;Alex&#8221;</font>, <font color="#800000">&#8220;John&#8221;</font>, <font color="#800000">&#8220;Steve&#8221;</font>, <font color="#800000">&#8220;Zoe&#8221;</font> });<br />
        <font color="#0000ff">return</font> values;<br />
    }<br />
}</p>
<p>[ToolboxData(<font color="#800000">"&lt;{0}:NameLabel runat=server /&gt;"</font>)]<br />
<font color="#0000ff">public</font> <font color="#0000ff">class</font> NameLabel : Label<br />
{<br />
    <font color="#0000ff">string</font> _owner= <font color="#800000">&#8220;&lt;no owner&gt;&#8221;</font>;<br />
    <br />
    [TypeConverter(<font color="#0000ff">typeof</font>(NamesTypeConverter))]<br />
    <font color="#0000ff">public</font> <font color="#0000ff">string</font> Owner<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> _owner; }<br />
        <font color="#0000ff">set</font> { _owner = <font color="#0000ff">value</font>; }<br />
    }<br />
    <br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> <font color="#0000ff">string</font> Text<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> Owner; }<br />
    }<br />
}</p></blockquote>
<p>This will offer the following drop down list at design time:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2006/11/namelabel.png" /></p>
<p>Gee, a string property and still a drop down list with several predefined choices!</p>
<p><strong>4. Code using design time services </strong></p>
<p>Sooner or later one needs information from the design time environment or would like to react on some events (e.g. the addition af a new control at design time). Unfortunately the area of design time services is also the area where the documentation begins to get <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.componentmodel.design(VS.80).aspx">sparse</a>. Some areas are well documented, others are not. Especially the background story definitely lacks some information.</p>
<p>This <em>TypeConverter </em>offers a list of IDs of textboxes and is used by a label that simply shows the content of that textbox.</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> TextBoxIDsTypeConverter : TypeConverter<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> <font color="#0000ff">bool</font> GetStandardValuesSupported<br />
        (ITypeDescriptorContext context)<br />
    {<br />
        <font color="#0000ff">return</font> <font color="#0000ff">true</font>;<br />
    }<br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> <font color="#0000ff">bool</font> GetStandardValuesExclusive<br />
        (ITypeDescriptorContext context)<br />
    {<br />
        <font color="#0000ff">return</font> <font color="#0000ff">true</font>;<br />
    }<br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> StandardValuesCollection GetStandardValues<br />
        (ITypeDescriptorContext context)<br />
    {<br />
        <font color="#0000ff">if</font> (context == <font color="#0000ff">null</font>)<br />
            <font color="#0000ff">return</font> <font color="#0000ff">null</font>;<br />
        <br />
        IDesignerHost host =<br />
            (IDesignerHost)context.GetService(<font color="#0000ff">typeof</font>(IDesignerHost));<br />
        Control parent = host.RootComponent <font color="#0000ff">as</font> Control;<br />
        List&lt;string&gt; list= <font color="#0000ff">new</font> List&lt;string&gt;();<br />
        <font color="#0000ff">foreach</font> (Control control <font color="#0000ff">in</font> parent.Controls)<br />
        {<br />
            <font color="#0000ff">if</font> (control <font color="#0000ff">is</font> TextBox)<br />
                list.Add(control.ID);<br />
        }<br />
        list.Sort();<br />
        StandardValuesCollection values =<br />
            <font color="#0000ff">new</font> StandardValuesCollection(list);<br />
        <font color="#0000ff">return</font> values;<br />
    }<br />
}</p>
<p>[ToolboxData(<font color="#800000">"&lt;{0}:TextboxLabel runat=server /&gt;"</font>)]<br />
<font color="#0000ff">public</font> <font color="#0000ff">class</font> TextboxLabel : Label<br />
{<br />
    <font color="#0000ff">string</font> _textbox= <font color="#800000">&#8220;textbox_id&#8221;</font>;<br />
    <br />
    [TypeConverter(<font color="#0000ff">typeof</font>(TextBoxIDsTypeConverter))]<br />
    <font color="#0000ff">public</font> <font color="#0000ff">string</font> Textbox<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> _textbox; }<br />
        <font color="#0000ff">set</font> { _textbox = <font color="#0000ff">value</font>; }<br />
    }<br />
    <br />
    <font color="#0000ff">public</font> <font color="#0000ff">string</font> TextboxText<br />
    {<br />
        <font color="#0000ff">get</font><br />
        {<br />
            <font color="#0000ff">if</font> ((<font color="#0000ff">this</font>.Site != <font color="#0000ff">null</font>) &amp;&amp; <font color="#0000ff">this</font>.Site.DesignMode)<br />
                <font color="#0000ff">return</font> <font color="#800000">&#8220;&lt;textbox text&gt;&#8221;</font>;<br />
            TextBox t = (TextBox)<font color="#0000ff">this</font>.Page.FindControl(_textbox);<br />
            <font color="#0000ff">if</font> (t==<font color="#0000ff">null</font>)<br />
                <font color="#0000ff">return</font> <font color="#800000">&#8220;&lt;textbox &#8220;</font>+_textbox+<font color="#800000">&#8221; not found&gt;&#8221;</font>;<br />
            <font color="#0000ff">return</font> t.Text;<br />
        }<br />
    }<br />
    <br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> <font color="#0000ff">string</font> Text<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> TextboxText; }<br />
    }<br />
}</p></blockquote>
<p>This will offer a list of textboxes on the same page:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2006/11/testboxids.png" /></p>
<p>It even works at runtime, like the following snapshot taken after a postback shows:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2006/11/testboxids_r.png" /></p>
<p>We are beginning to build up relationships.</p>
<p><strong>5. Code using the Visual Studio automation model </strong></p>
<p>The design time services are somewhat limited in what they offer. For example there is no service that tells one what file he is working on. Within the design time model this information is not even available. But it is available outside, within the Visual Studio automation model. It&#8217;s hardly documented (unless you peek at the Visual Studio SDK documentation) but all you have to do is to ask for the <em>DTE </em>interface which recides in the <em>EnvDTE </em>assembly.</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> TextfileTypeConverter : TypeConverter<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> <font color="#0000ff">bool</font> GetStandardValuesSupported<br />
        (ITypeDescriptorContext context)<br />
    {<br />
        <font color="#0000ff">return</font> <font color="#0000ff">true</font>;<br />
    }<br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> <font color="#0000ff">bool</font> GetStandardValuesExclusive<br />
        (ITypeDescriptorContext context)<br />
    {<br />
        <font color="#0000ff">return</font> <font color="#0000ff">false</font>;<br />
    }<br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> StandardValuesCollection GetStandardValues<br />
        (ITypeDescriptorContext context)<br />
    {<br />
        <font color="#0000ff">if</font> (context == <font color="#0000ff">null</font>)<br />
            <font color="#0000ff">return</font> <font color="#0000ff">null</font>;<br />
        <br />
        DTE dte = (DTE)context.GetService(<font color="#0000ff">typeof</font>(DTE));<br />
        Project p = ((<font color="#0000ff">object</font>[])dte.ActiveSolutionProjects)[0] <font color="#0000ff">as</font> Project;<br />
        <font color="#0000ff">string</font> filename = Path.Combine(p.FileName, <font color="#800000">&#8220;prefixes.txt&#8221;</font>);<br />
        <font color="#0000ff">string</font>[] lines = File.ReadAllLines(filename);<br />
        <br />
        StandardValuesCollection values =<br />
            <font color="#0000ff">new</font> StandardValuesCollection(lines);<br />
        <font color="#0000ff">return</font> values;<br />
    }<br />
}</p>
<p>[ToolboxData(<font color="#800000">"&lt;{0}:PrefixedLabel runat=server /&gt;"</font>)]<br />
<font color="#0000ff">public</font> <font color="#0000ff">class</font> PrefixedLabel : Label<br />
{<br />
    <font color="#0000ff">string</font> _prefix= <font color="#800000">&#8220;PREFIX:&#8221;</font>;<br />
    <br />
    [TypeConverter(<font color="#0000ff">typeof</font>(TextfileTypeConverter))]<br />
    <font color="#0000ff">public</font> <font color="#0000ff">string</font> Prefix<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> _prefix; }<br />
        <font color="#0000ff">set</font> { _prefix = <font color="#0000ff">value</font>; }<br />
    }<br />
    <br />
    <font color="#0000ff">public</font> <font color="#0000ff">override</font> <font color="#0000ff">string</font> Text<br />
    {<br />
        <font color="#0000ff">get</font> { <font color="#0000ff">return</font> _prefix + <font color="#0000ff">base</font>.Text; }<br />
        <font color="#0000ff">set</font><br />
        {<br />
            <font color="#0000ff">if</font> (<font color="#0000ff">value</font>.StartsWith(_prefix))<br />
                <font color="#0000ff">value</font> = <font color="#0000ff">value</font>.Substring(_prefix.Length);<br />
            <font color="#0000ff">base</font>.Text = <font color="#0000ff">value</font>;<br />
        }<br />
    }<br />
}</p></blockquote>
<p>Given a textfile named <em>prefixes.txt </em>in the web project with the respective content it will look like this:</p>
<p><img src="http://ajdotnet.files.wordpress.com/2006/11/prefixed.png" /></p>
<p>Great, we cannot only provide a list of choices, we can even edit this list by means of a simple text file.</p>
<p>So, now you are free to do what you want. Your code is in control and you can reach wherever you want. However you still need the Visual Studio to call your code and unless you knock it down it will eventually have to return (or be brought back). The next level that does not suffer from those limitations will be any kind of Visual Studio AddIn. But that&#8217;s another story.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/11/11/reach-out-at-design-time/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/11/11/reach-out-at-design-time/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/64/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/64/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=64&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/11/11/reach-out-at-design-time/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/11/urllabel.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2006/11/urllabel2.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2006/11/urllabel_r.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2006/11/namelabel.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2006/11/testboxids.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2006/11/testboxids_r.png" medium="image" />

		<media:content url="http://ajdotnet.files.wordpress.com/2006/11/prefixed.png" medium="image" />

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/11/11/reach-out-at-design-time/" medium="image" />
	</item>
		<item>
		<title>Logging? Efficiently please!</title>
		<link>http://ajdotnet.wordpress.com/2006/11/03/logging-efficiently-please/</link>
		<comments>http://ajdotnet.wordpress.com/2006/11/03/logging-efficiently-please/#comments</comments>
		<pubDate>Fri, 03 Nov 2006 19:58:30 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/11/03/logging-efficiently-please/</guid>
		<description><![CDATA[Logging is important. It allows post mortem analysis of your code. Be it for error diagnosis, to get an impression of the runtime characteristics, to trail some users work. Logging is but one option if it comes to detecting concurrency issues or in production where it is no option to attach a debugger. Logging in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=63&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Logging is important. It allows post mortem analysis of your code. Be it for error diagnosis, to get an impression of the runtime characteristics, to trail some users work. Logging is but one option if it comes to detecting concurrency issues or in production where it is no option to attach a debugger. Logging in production of course requires the logging features to be present in release builds, yet they should have minimal performance impact if logging is switched off.</p>
<p>Logging is also no simple thing to do, for there are so many things to consider: Trace level, granularity, extensibility, where to log, how to configure, … . So it is prudent to check if someone has already done this work. There are actually several options, for example:</p>
<ul>
<li>The builtin tracing of the .NET Framework and ASP.NET tracing</li>
<li>The &#8220;<a target="_blank" href="http://msdn.microsoft.com/practices/topics/manage/default.aspx?pull=/library/en-us/dnpag2/html/logging.asp">Logging and Instrumentation Application Block</a>&#8220;, successor of the &#8220;Enterprise Instrumentation Framework (EIF)&#8221;, from the <a target="_blank" href="http://msdn.microsoft.com/practices/">patterns &amp; practices</a> group at Microsoft.</li>
<li><a target="_blank" href="http://logging.apache.org/log4net">log4net</a> (.NET port of the <a target="_blank" href="http://logging.apache.org/log4j/">log4j</a> framework for java)</li>
<li>probably some others&#8230;</li>
</ul>
<p><strong>Using log4net </strong></p>
<p>What do you use for logging? Log4net? Me to. Log4net is mature, easy to use, highly configurable, supports different log styles and log stores for the information, and it is kind of a standard. It is what I called in a <a href="http://ajdotnet.wordpress.com/2006/10/28/frameworks-dont-let-em-frame-you/">previous post</a> a &#8220;good framework&#8221;.</p>
<p>Logging with log4net is as easy as the following example, taken form the <a target="_blank" href="http://logging.apache.org/log4net/release/manual/configuration.html">log4net manual</a>:</p>
<blockquote><p><font color="#0000ff">using</font> log4net;</p>
<p><font color="#0000ff">namespace</font> Com.Foo<br />
{<br />
    <font color="#0000ff">public</font> <font color="#0000ff">class</font> Bar<br />
    {<br />
        <font color="#0000ff">private</font> <font color="#0000ff">static</font> <font color="#0000ff">readonly</font> ILog log = LogManager.GetLogger(<font color="#0000ff">typeof</font>(Bar));<br />
        <br />
        <font color="#0000ff">public</font> <font color="#0000ff">void</font> DoIt()<br />
        {<br />
            log.Debug(<font color="#800000">&#8220;Did it again!&#8221;</font>);<br />
        }<br />
    }<br />
}</p></blockquote>
<p>They also adress the issue of performance:</p>
<blockquote><p>&#8220;The log4net package is designed so that log statements can remain in shipped code without incurring a high performance cost. It follows that the speed of logging (or rather not logging) is crucial. &#8221; (<a target="_blank" href="http://logging.apache.org/log4net/release/features.html">log4net features</a>)</p></blockquote>
<p>And they provide a respective example in the <a target="_blank" href="http://logging.apache.org/log4net/release/faq.html">log4net faq</a>:</p>
<blockquote><p>What is the fastest way of (not) logging?<br />
For some logger log, writing,</p>
<p>log.Debug(&#8220;Entry number: &#8221; + i + &#8221; is &#8221; + entry[i]);</p>
<p>incurs the cost of constructing the message parameter, that is converting both integer i and entry[i] to a string, and concatenating intermediate strings. This, regardless of whether the message will be logged or not.</p>
<p>If you are worried about speed, then write</p>
<p>if(log.IsDebugEnabled)<br />
{<br />
    log.Debug(&#8220;Entry number: &#8221; + i + &#8221; is &#8221; + entry[i]);<br />
}</p>
<p>This way you will not incur the cost of parameter construction if debugging is disabled for logger log. […] </p></blockquote>
<p>Easy to use and performance aware, right? Well, would I be asking that question if the answer where a confident &#8220;yes&#8221;?</p>
<p><strong>A better way of using log4net</strong></p>
<p>Whenever I began looking at performance characteristics in a project, logging in this naive way (sorry, no offense intended) was one of the first things to show up. Many projects react with simply removing logging from release builds altogether, carelessly giving away a powerfull tool &#8211; sometimes the only one &#8211; to diagnose their application in production.</p>
<p>The general issues with the proposed &#8220;speed optimized&#8221; version above are:</p>
<ol>
<li>it is twice as much code lines per log statement (4 times if you count the curly braces)</li>
<li>it is a recommendation, not a mandatory &#8211; not to mention enforced &#8211; way of logging</li>
<li>it optimizes the usage of log4net, yet it falls short in properly observing the performance recommendations for .NET</li>
</ol>
<blockquote><p><em>Sidenote: </em>It is a recomendation in .NET to avoid concatenating several string using the + operator. Rather one should use <em>String.Concat </em>or (with growing degree of complexity) <em>String.Format </em>or the <em>StringBuilder </em>class.</p>
<p>Actually this is not he only project ported from java to .NET that needs another step of &#8220;.NETification&#8221; after the first migration is done. I encountered similar issues in <a target="_blank" href="http://www.springframework.net/">Spring.NET</a> and their somewhat naive usage of reflection. <a target="_blank" href="http://www.nunit.org/">NUnit</a> for example has undergone this step: &#8220;It is written entirely in C# and has been completely redesigned to take advantage of many .NET language features, for example custom attributes and other reflection related capabilities. &#8220;</p></blockquote>
<p>To look a bit deeper at my concerns and come up with a solution, let&#8217;s look at a slightly more complex example. Within a page class I would like to log the current request, user and possibly some error. Following the log4net documentation the code would look like this:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> MyPage : Page<br />
{<br />
    <font color="#0000ff">private</font> <font color="#0000ff">static</font> <font color="#0000ff">readonly</font> ILog log = LogManager.GetLogger(<font color="#0000ff">typeof</font>(Bar));<br />
    <br />
    <font color="#0000ff">override</font> <font color="#0000ff">protected</font> <font color="#0000ff">void</font> OnInit(EventArgs e)<br />
    {<br />
        <font color="#0000ff">if</font> ((log!=<font color="#0000ff">null</font>)) &amp;&amp; log.IsDebugEnabled)<br />
        {<br />
            log.Debug( <font color="#800000">&#8220;Url: &#8220;</font> + HttpContext.Current.Request.RawUrl +<br />
                <font color="#800000">&#8221; User: &#8220;</font> +Thread.CurrentPrincipal.Identity.Name);<br />
        }<br />
        <br />
        <font color="#0000ff">try</font><br />
        {<br />
            <font color="#0000ff">base</font>.OnInit(e);<br />
        }<br />
        <font color="#0000ff">catch</font> (Exception ex)<br />
        {<br />
            <font color="#0000ff">if</font> (log!=<font color="#0000ff">null</font>) <br />
                log.Error( <font color="#800000">&#8220;Exception in Page.OnInit&#8221;</font>, ex);<br />
            <font color="#0000ff">throw</font>;<br />
        }<br />
    }<br />
}</p></blockquote>
<p>Note that I did additional checks for <em>null</em>. The log4net documentation does not state that <em>GetLogger </em>will always return a none-null value. Following defensive programming style I like to make sure a future version of log4net will not break my code.</p>
<p>Because logging is such a frequent thing to do I resent every line of code beyond the logging call itself. And I expect the framework to take whatever I have to log rather than having me shape the data for it. In more detail:</p>
<ol>
<li>I don&#8217;t like the lingering <em>log </em>member. The first logging attempt will take the additional effort to remember the details of logging, go to the top of the souce file, add that member, go back to the original location in the file, and only then one will be able to finally log the data. (Am I being lazy? Sure I am. Laziness is one of the best qualities a good developer should have!)</li>
<li>I don&#8217;t like to check the trace level. Why do <em>I </em>have to do this just because of performance? There&#8217;s a framework. It should do that and it should do it right in the first place.</li>
<li>I don&#8217;t like this form of string concatenation. I would like the comfort of a format string. Yes, I could call <em>String.Format</em>. But this surely is a performance issue and again, there&#8217;s a framework to do that for me.</li>
</ol>
<p>In accordance with my &#8220;write the client code first&#8221; approach (<a href="http://ajdotnet.wordpress.com/2006/10/28/frameworks-dont-let-em-frame-you/">previous post</a>), here is what I would expect to do:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> MyPage : Page<br />
{<br />
    <font color="#0000ff">override</font> <font color="#0000ff">protected</font> <font color="#0000ff">void</font> OnInit(EventArgs e)<br />
    {<br />
        LogHelper.DebugFormat(<font color="#0000ff">this</font>, <font color="#800000">&#8220;Url: {0}; User: {1}&#8221;</font>,<br />
            HttpContext.Current.Request.RawUrl, Thread.CurrentPrincipal.Identity.Name);<br />
        <br />
        <font color="#0000ff">try</font><br />
        {<br />
            <font color="#0000ff">base</font>.OnInit(e);<br />
        }<br />
        <font color="#0000ff">catch</font> (Exception ex)<br />
        {<br />
            LogHelper.Error(<font color="#0000ff">this</font>, ex, <font color="#800000">&#8220;Exception in Page.OnInit&#8221;</font>);<br />
            <font color="#0000ff">throw</font>;<br />
        }<br />
    }<br />
}</p></blockquote>
<p>Looks better? You bet. However in order to work the <em>LogHelper </em>class is needed, one that also meets my expectations. One that looks a little like this:</p>
<blockquote><p><font color="#0000ff">public</font> <font color="#0000ff">class</font> LogHelper<br />
{<br />
    [Conditional(<font color="#800000">"TRACE"</font>)]<br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> DebugFormat(<font color="#0000ff">object</font> context, <font color="#0000ff">string</font> format, <font color="#0000ff">params</font> <font color="#0000ff">object</font>[] args)<br />
    {<br />
        ILog log = LogManager.GetLogger(context.GetType());<br />
        <font color="#0000ff">if</font> ((log==<font color="#0000ff">null</font>)) || !log.IsDebugEnabled)<br />
            <font color="#0000ff">return</font>;<br />
        <font color="#0000ff">string</font> msg= <font color="#0000ff">string</font>.Format(format, args);<br />
        log.Debug(msg);<br />
    }<br />
    <br />
    [Conditional(<font color="#800000">"TRACE"</font>)]<br />
    <font color="#0000ff">public</font> <font color="#0000ff">static</font> Error(<font color="#0000ff">object</font> context, Exception ex, <font color="#0000ff">string</font> msg)<br />
    {<br />
        ILog log = LogManager.GetLogger(context.GetType());<br />
        <font color="#0000ff">if</font> ((log==<font color="#0000ff">null</font>)) || !log.IsErrorEnabled)<br />
            <font color="#0000ff">return</font>;<br />
        log.Error(msg, ex);<br />
    }<br />
    <br />
    [...]<br />
}</p></blockquote>
<p>Of course <em>LogHelper </em>should provide a bunch of other overloads:</p>
<ul>
<li>overloads that take a string or type as context, to be called by static members</li>
<li>overloads that take single messages as well as a parameter lists for string concatenations</li>
<li>overloads for efficient string formating</li>
<li>overloads for type safety</li>
<li>trace level checks for special cases</li>
<li>there could be methods that are only available in debug mode</li>
<li>&#8230;</li>
</ul>
<p>So, what has been gained by this?</p>
<ol>
<li>Wherever I want to log something, I can do it right away. The only price for calling a static method rather than an instance is an additional parameter <em>context </em>to pick the logger instance.</li>
<li>Due to the different overloads I can pass the information as I have it, relieving me of the work to prepare it for the logger.</li>
<li>The different overloads also lay the foundation for doing the trace level check within the helper class, before the cost of preparing the data (e.g. calling <em>String.Format</em>) has been taken.</li>
</ol>
<p>In other words: I have to write considerably less code (logging code down by 50% and preparational code eliminated altogether). The code automatically observes the log4net recommendation for fast (not) logging and it also observes the .NET recommendation for efficient code. And last not least, it provides a multitude of logging methods tailored to my particular needs (something that is no viable option for an interface).</p>
<p>But wait, there&#8217;s even more! There are other logging services that can be adressed far easier in one central location. E.g.:</p>
<ul>
<li>Some of the helper methods could add code to enrich the information. Especially error logs could be amended with current request, user, appdomain name, session id, … .</li>
<li>Some people do like method entrance/exit traces to get detailed information about the flow of control. There could be special methods tailored to that need and <strike>perhaps</strike> a special switch to distincly control it. (That switch is for me, to switch that feature off! <img src='http://s2.wp.com/wp-includes/images/smilies/icon_twisted.gif' alt=':twisted:' class='wp-smiley' />  ) </li>
<li>There&#8217;s allways the need to trace some data in more deepth. There could be helper methods that trace the complete current request information, the contents of the ASP.NET cache or session, the contents of a collection, arbitrary objects (reflecting all members), stack trace, …</li>
<li>The class could register itself automatically for system events (such as error events) and thus trace application or page livecycles.</li>
<li>Log4net has a problem when several instances are initialized with the same configuration and trying to write to the same files. (Which will happen in any ASP.NET application due to app domain recyclings, not to mention web garden scenarios). This can be adressed in the helper once and for all.</li>
<li>&#8230;</li>
</ul>
<p>See, log4net is good, but there is still room for a framework upon it. OK, that&#8217;s a very elaborate posting for something as simple as logging. Take it as a real world example of some of the principles outlined in the <a href="http://ajdotnet.wordpress.com/2006/10/28/frameworks-dont-let-em-frame-you/">previous post</a> (notably #1, but #3 and #0 as well).</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/11/03/logging-efficiently-please/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/11/03/logging-efficiently-please/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/63/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/63/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=63&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/11/03/logging-efficiently-please/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/11/03/logging-efficiently-please/" medium="image" />
	</item>
		<item>
		<title>Frameworks &#8211; don&#8217;t let &#8216;em frame you!</title>
		<link>http://ajdotnet.wordpress.com/2006/10/28/frameworks-dont-let-em-frame-you/</link>
		<comments>http://ajdotnet.wordpress.com/2006/10/28/frameworks-dont-let-em-frame-you/#comments</comments>
		<pubDate>Sat, 28 Oct 2006 13:36:16 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Developers]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/10/28/frameworks-dont-let-em-frame-you/</guid>
		<description><![CDATA[Why is it that so many people want to write frameworks (rather than using them)? Is it the &#8220;Hey, I&#8217;ve just written a method that makes sense in another application! Why not make it a framework? That&#8217;s so much more fun!&#8220;-effect? Or the &#8220;We have a bunch of applications that we need to migrate. Let&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=62&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Why is it that so many people want to write frameworks (rather than using them)? Is it the &#8220;<em>Hey, I&#8217;ve just written a method that makes sense in another application! Why not make it a framework? That&#8217;s so much more fun!</em>&#8220;-effect? Or the &#8220;<em>We have a bunch of applications that we need to migrate. Let&#8217;s begin with a framework to ensure they are build consistently</em>&#8220;-demand? Does &#8220;<em>not invented here</em>&#8221; still play a role?</p>
<p>Well, any of these and other motivations probably plays its role and is more or less wrong or right, depending on the situation. I&#8217;m not going to judge this in general. But there is another question that should in all honesty be asked: <em>Why are there so many bad frameworks out there? </em>I.e. frameworks that do not meet the requirements?</p>
<blockquote><p>Note that &#8220;bad frameworks&#8221; does not imply &#8220;bad code&#8221;. The framework code may be at the edge of geniality, yet if the requirement was reuse and noone actually did reuse it, then it missed the requirement. If it was meant to hide complexity and ease the usage of certain things but all it did was replacing one complex task with another, then it failed. Even if it met all requirements, yet it caused overly complex and non-maintainable client code, I would regard it as failure.</p></blockquote>
<p>Sadly many bad frameworks are written by good developers for their best. <em>I </em>have written bad frameworks, no kidding! (Of course I don&#8217;t do that anymore… <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  .)</p>
<p>The main reason for this phenomenon may be due to one single fact that is too often overlooked: Just as frameworks differ from applications, framework development differs from application development. And the single most differentiating point between applications and frameworks is the user base. The users of a framework are<em> other developers</em>. In the same way a usual application supports the end user (think of usability, consistency, appearance, etc.) a framework has to support the developer.</p>
<blockquote><p>In his article &#8220;<a target="_blank" href="http://www.theserverside.net/news/thread.tss?thread_id=42597">Framing the framework conversation</a>&#8221; Jack Vaughan lays his hands right into the open wound: &#8220;<em>Application frameworks have been around for a while now, but accepted best practices in application framework building still seem to be something of a new thing.</em>&#8220;</p>
<p>Jack also says &#8220;<em>One worst practice to avoid in framework creation is to look at the application framework in the same way as a typical IT application.</em>&#8221; And later on &#8220;<em>An obvious but sometimes overlooked point: Developers are the people that will be “using” this framework software.</em>&#8220;</p>
<p>Just my point, right?</p></blockquote>
<p>Enough bashing, let&#8217;s get a bit more constructive. I have also written some very good frameworks (again, &#8220;good frameworks&#8221; simply stands for &#8220;frameworks that met the requirements&#8221;), and here are some golden rules I learned from experience:</p>
<p>1. Focus on the &#8220;user interface&#8221;, not on the functionality<br />
2. Robustness is of utmost importance<br />
3. Align the framework with existing environments and standards</p>
<p>Just as Asimov was not content with with his &#8220;<a target="_blank" href="http://en.wikipedia.org/wiki/Three_Laws_of_Robotics">Three Laws of Robotics</a>&#8221; and <a target="_blank" href="http://en.wikipedia.org/wiki/Three_Laws_of_Robotics#Zeroth_Law_added">prepended law #0</a> I like to add the following:</p>
<p>0. Know when <em>not</em> to write framework code.</p>
<p>Of course I&#8217;m not going to raise the natural radiation level to render mother earth uninhabitable. Promise.</p>
<p>In more detail:</p>
<p><strong>1. Focus on the &#8220;user interface&#8221;, not on the functionality</strong></p>
<p>When you begin developing a framework, start with writing the client(!) code, including any configuration, as if this framework already existed.</p>
<p>This way you will not only specify the functions provided by the framework, you will specify the interface the framework shall provide. This covers not only the functional demands, but the &#8220;ergonics&#8221; in using it. In other words, you&#8217;ll have a fairly complete specification of the user interface of your framework, i.e. the API, configuration file schema, and even encountered behaviour (such as exceptions).</p>
<p>This approach makes sure the framework can be leveraged with as little effort as possible. This also implicitely includes what should <em>not </em>be necessary to use the framework. E.g. some module concerned with exception handling might have to register the necessary eventhandler itself rather than expecting the user to do this, or worse yet, expecting him to cover his code with try/catch.</p>
<p>Focusing primarily on the functionality, the framework will probably fullfill the requirements as well. Yet in order to use it the user will have to write a lot more unnecessary and tedious code. Perhaps he will even have to deal with internal details, thus contributing to the breaking changes of your next version.</p>
<p><strong>2. Robustness is of utmost importance</strong></p>
<p>Framework users have much more options to stress framework code than endusers have with applications. Thus framework code needs to be much more robust than common application code. You never know under what conditions and in what contexts your framework code will run. If some error occurs, don&#8217;t expect &#8220;sympathy of a fellow developer&#8221;, people using a framework are as demanding and unforgiving as any other user.</p>
<p>Things you should think of include:</p>
<ul>
<li>Extensive checks of all information comming into the framework: call parameters, configuration data, connection objects, various contexts (request, transactions, security, &#8230;), &#8230;</li>
<li>Possibly special configuration checks during initialization. e.g. if the configuration points to a directory (or any other resource that is uncertain to exist or subject to security restrictions), try accessing that directory right away; if it contains a type for dynamic object creation, create it now.</li>
<li>Use reasonable default values to avoid effort on the users side. The less work the user has to do, the more pleased he will be &#8211; not to mention the less chances for mistakes.</li>
<li>Provide meaningfull error messages. Don&#8217;t tell the user an error happend (he&#8217;ll know that anyway <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ), tell him how to solve it. A <em>NullReferenceException </em>doesn&#8217;t help at all to find the problem, some kind of configuration exception with the setting name and a hint why it caused an error does.</li>
</ul>
<p><strong>3. Align the framework with existing environments and standards </strong></p>
<p>Work <em>with </em>the .NET Framework and Visual Studio. Leverage and enhance them. Use similar patterns and conventions. Behave like a good citizen who is just trying to help.</p>
<p>This way you will realize the most synergy effects for the users:</p>
<ul>
<li>You build on already present concepts and knowledge (which also streamlines your documentation)</li>
<li>You achieve better reuse effects if you can plug in an already existing infrastructure</li>
<li>You will participate in future enhancements of the platform</li>
</ul>
<p>If you started developing parallel or even contradictory concepts for things already there you would allways have to to justify yourself, cope with improper usage, and generally bad acceptance among your user base. (You would be seen as an anarchist rather than a good citizen.)</p>
<p>Personally I adhere to this rule as long as possible, even if my own solution appears to be better. I would even drop framework features if the new version of the environment suddenly provides something similar. Which is an ideal transition to the next point&#8230;</p>
<p><strong>0. Know when <em>not</em> to write framework code.</strong></p>
<p>There are different reasons for not writing framework code, yet the most important one is: The feature is already available somewhere else.</p>
<p>If Microsoft has done it, use it. If there is a serious community project, use it. If someone in another department did something similar, go drink a coffee with that guy.<br />
Face it: Any big company that sells a product is far better at developing, documenting, maintaining this product. Any community will constantly contribute to and reassess framework features, as well as use and test it in very diverse contexts. Who thinks he can cope with that on his own, especially in the long run?</p>
<p>Of course they might fail. So what? They are less likely to fail than you and they are ar far better target to blame if they do.</p>
<p><strong>At the end of the day&#8230;</strong></p>
<p>&#8230; your framework will still have to deliver some functionality. But following these guideliness should make your users happy for the features, rather than frustrated because of the stunts needed to access them.</p>
<p>Some additional hints:</p>
<ul>
<li>The article &#8220;<a target="_blank" href="http://www.theserverside.net/news/thread.tss?thread_id=42597">Framing the framework conversation</a>&#8220;, Jack Vaughan, inspired this post when he confirmed some lingering thoughs I had. It also has some additional links and hints.</li>
<li>Although I haven&#8217;t read it (yet) a collegue of mine (whom I hold in high regard) recommends &#8220;<a target="_blank" href="http://www.amazon.com/gp/product/0321246756/103-5097735-6215848?v=glance&amp;n=283155">Framework Design Guidelines</a>&#8221; and the blog of one of the authors &#8220;<a target="_blank" href="http://blogs.msdn.com/kcwalina">Krzysztof Cwalina</a>&#8220;.</li>
<li>Any book on wellknown patterns or code quality will help, e.g. the classic book &#8220;<a target="_blank" href="http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/sr=8-1/qid=1161852021/ref=sr_1_1/002-9795087-4900015?ie=UTF8&amp;s=books">Design Patterns: Elements of Reusable Object-Oriented Software</a>&#8221; or (one of my favourite books) &#8220;<a target="_blank" href="http://www.amazon.com/Code-Complete-Second-Steve-McConnell/dp/0735619670/sr=1-1/qid=1161852088/ref=pd_bbs_sr_1/002-9795087-4900015?ie=UTF8&amp;s=books">Code Complete</a>&#8220;.</li>
</ul>
<p>Disclaimer: While Jacks article inspired this post and some fellow collegues unwillingly contributed to it <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  , it is solely based on my own experience. Blame me for any mistakes and for not honoring some people&#8217;s efforts. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':grin:' class='wp-smiley' /> </p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/10/28/frameworks-dont-let-em-frame-you/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/10/28/frameworks-dont-let-em-frame-you/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/62/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/62/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/62/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=62&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/10/28/frameworks-dont-let-em-frame-you/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/10/28/frameworks-dont-let-em-frame-you/" medium="image" />
	</item>
		<item>
		<title>WebService? What do you mean, &quot;WebService&quot;?</title>
		<link>http://ajdotnet.wordpress.com/2006/10/22/webservice-what-do-you-mean-webservice/</link>
		<comments>http://ajdotnet.wordpress.com/2006/10/22/webservice-what-do-you-mean-webservice/#comments</comments>
		<pubDate>Sun, 22 Oct 2006 13:27:33 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/10/22/webservice-what-do-you-mean-webservice/</guid>
		<description><![CDATA[When people (make that &#8220;developers&#8221;) start talking about WebServices I immediatelly get cautious. Once they use phrases like &#8220;other clients&#8221;, &#8220;probably different plattform&#8221;, and &#8220;serialization&#8221; in the same sentence I get that weary feeling, like I just eat something bad. Ironically if I ask what they actually mean when they talk about &#8220;WebService&#8221; I am [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=61&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When people (make that &#8220;developers&#8221;) start talking about WebServices I immediatelly get cautious. Once they use phrases like &#8220;other clients&#8221;, &#8220;probably different plattform&#8221;, and &#8220;serialization&#8221; in the same sentence I get that weary feeling, like I just eat something bad. Ironically if I ask what they actually mean when they talk about &#8220;WebService&#8221; <em>I</em> am the one being looked at as if I have been out of business for the past 5 years.</p>
<p>Well, I cannot blame them. Actually I blame Microsoft. And IBM. Bea. <em>They</em> made it far to easy to create something they called WebService directly from code (i.e. SOAP wrappers on objects). Then they invented SOA and talked about something entirely different which they also named WebService. It is not as if they don&#8217;t try, actually they try very hard to tell people the difference. In fact there are bright people within those companies who do nothing else. Yet this sometimes strucks me as damage control; damage caused by carelessly giving two very different things the same name &#8211; or rather by sticking with the name when WebServices evolved into something completely different.</p>
<blockquote><p>Just as a side note: Did you notice I didn&#8217;t mention SUN? <em>They </em>are not to blame. They jumped on the train when it was already on its way and even then they did it reluctantly.</p></blockquote>
<p>Here are the differences I am refering to:<br />
There is a <strong>technology stack </strong>(namely HTTP, SOAP, and WSDL, possibly augmented with WS-* standards) commonly named &#8220;Web Service&#8221; on one hand. And on the other hand we have the <strong>architectural concept </strong>of services &#8211; nowadays allways in the context of a SOA -, which is usually also named &#8220;WebService&#8221; because WebServices are the predominant/canonical implementation technology for this concept. And because WebServices <em>are </em>the predominant implementation technology people often confuse the concept and the technology. Thus, when they use the <em>technology </em>they asume that the bennefits of the <em>service </em>come for free. (That is &#8220;service&#8221; in the SOA sense &#8211; unfortunately &#8220;service&#8221; is also a term that has very diverse meanings).</p>
<p>In order to clearly distinguish both kinds I usually use the terms &#8220;<em>internal/private WebService</em>&#8221; (the technology focused ones) and &#8220;<em>external/public WebService</em>&#8221; (following the service concept). The (somewhat idealized) definition of these two kinds of WebService goes like this:</p>
<p><strong>Internal/private WebServices </strong>are used within a logical application as a means for distribution.<br />
Both sides (client and server) are under control of the development team, both are deployed in unison, both have the same notion about the data model. Actually the fact that a WebService (or rather HTTP/SOAP) is used is just an implementation detail. One could also think of any other kind of remote method call technology (Remoting, DCOM, RMI, FTP, &#8230;) without affecting the application architecture.<br />
These WebServices are meant to be <em>never</em> called from outside the application.</p>
<p><strong>External/public WebService </strong>are published by an application to be used by other independend consumers &#8211; consumers you may not even know. These WebServices constitute another UI layer (rather than the interface of a layer). They require contracting, security, versioning, logging, fault tolerance, etc.. In particular this includes developing a separate data model for the interface. This model has to be versionable, stable, aligned with the service calls, and devoid of any implementation details. What you should not do is simply publish the internal data model. Apart from inflicting implementation details on the consumer, the least thing that will happen is that you can&#8217;t change anything afterwards without breaking your consumers. In other words: If you did that, you would have built the handcuffs, tied them to your own hands, threw away the key, and jumped in the water. Even good swimmers will drown in this situation. Publishing your internal data structures will get you into trouble. Trust me on this, I can show the scars.</p>
<p>Needless to say that internal WebServices are far easier to implement than external ones. The pitfall created by the similar term is that in my experience most WebServices are implemented as internal WebServices, yet sooner or later someone will use them externaly, expecting the quality and the features of an external WebService. Also quite often certain people (deliberately?) ignore the difference &#8211; even if you tell them. Internal WebServices are so much cheaper and a WebService is a WebService, no matter what this bitcounting bonehead (me!) says.</p>
<p>The way I try to avoid this situation consists of one single rule: I observe this clear distinction during design, development, and especially when talking about these things. I use the term WebService for the external kind and put emphasis on the service characteristics. Also I mark them accordingly with price tags &#8211; and sorry, nothing on sale today. For internal WebServices I try to avoid that term altogether, rather I use something like &#8220;SOAP interface&#8221;.</p>
<p>Of course there&#8217;s a gray area and sometimes 3 is an even number, yet following this rule will avoid a lot of problems afterwards.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/10/22/webservice-what-do-you-mean-webservice/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/10/22/webservice-what-do-you-mean-webservice/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/61/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/61/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=61&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/10/22/webservice-what-do-you-mean-webservice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/10/22/webservice-what-do-you-mean-webservice/" medium="image" />
	</item>
		<item>
		<title>Cache as cache can!</title>
		<link>http://ajdotnet.wordpress.com/2006/10/18/cache-as-cache-can/</link>
		<comments>http://ajdotnet.wordpress.com/2006/10/18/cache-as-cache-can/#comments</comments>
		<pubDate>Wed, 18 Oct 2006 17:51:28 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/10/18/cache-as-cache-can/</guid>
		<description><![CDATA[Hi again, Caching. Probably the optimization startegy that is employed most often. Caching is good. Caching immediately speeds up the code. This guy seems like taking a long time? Go, cache it! Cache like crazy. Well, not quite. Caching is bad. Caching introduces memory pressure. Caching forces you to maintain cache integrity and if not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=60&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi again,</p>
<p>Caching. Probably the optimization startegy that is employed most often.<br />
Caching is good. Caching immediately speeds up the code. This guy seems like taking a long time? Go, cache it! Cache like crazy. Well, not quite.<br />
Caching is bad. Caching introduces memory pressure. Caching forces you to maintain cache integrity and if not done correctly and exhaustive it will cause arkward data inconsistencies. And it isn&#8217;t worth the effort anyway, since when the guy comes back and asks for the same data (if at all), the cached data will be long outdated. Well, not quite either.</p>
<p>So what&#8217;s the matter with caching?<br />
Caching is a tool and like every tool it has to be handled correctly. Using a hammer to iron your shirt might look like it worked, yet it will surely smash the buttons. (Which you&#8217;ll notice when this shirt is the last clean one you have and you need it for the job interview because you got fired for some foul caching strategy you implemented in the flagship software of your previous employer… <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ).</p>
<p>Here&#8217;s the problem:<br />
Caching is easy. Real easy. Putting a hastable in place or using the ASP.NET cache functionality is no big deal &#8211; and the code <em>will </em>be faster, if only at first glance. So it&#8217;s actually quite tempting to put caching in place.</p>
<p>But like a good drink, caching has its potential adverse effects, especially if applied improperly, such as:</p>
<ul>
<li>The application is eating up more and more memory because your homegrown caching using a static hastable will grow steadily.</li>
<li>The web application will support considerably less concurrent users due to memory preasure.</li>
<li>The web application will become slower because it invokes the garbage collector or does app domain recyclings more often.</li>
<li>In some extreme cases you will even see <em>OutOfMemoryException</em>s. (Try running BizTalk under heavy load if you&#8217;ve never seen one of these guys.)</li>
<li>You&#8217;ll get inconsistent data because not all code lines manipulating the data have been updated to also remove/update the outdated cache entry.</li>
<li>Best case: Your application just isn&#8217;t faster because noone actually used the cached data. Well, startup probably takes even longer.</li>
<li>Oh boy, did you forget to synchronize access to the cache?</li>
<li>…</li>
</ul>
<p>And here&#8217;s the deal:<br />
Blindly caching is bad. Sensible caching is still a powerfull tool. Caching is an optimization strategie and should be treated as such. Measure first, find the bottlenecks, decide upon the optimization strategy (yes, caching is not the only one) and <em>then </em>possibly apply caching.<br />
Lemma: You can&#8217;t do this right from the beginning, you need a functional complete version of your application. Thus caching should be a tabu until you reach a first functional iteration in development. And since caching is that easy be adamant about <em>not</em> caching until you reach that state!</p>
<p>Note that there may be caching allready in place (e.g. within the database) so allways measure subsequent data requests as well. Also don&#8217;t measure the performance alone, measure potential cache hits and misses before implementing caching. After all, putting something in a cache only makes sense if it is requested again afterwards with reasonable frequency.</p>
<p>If you have identified a longer list of possible candidates, don&#8217;t go and cache them all. Look for the spots that provide the most revenue. Remember, caching introduces memory pressure.</p>
<p><strong>Here are some additional general hints:</strong></p>
<ul>
<li>Begin with a <strong>well-defined caching strategy </strong>that clearly states what is to be cached, when, and where. Otherwise you will have a client that caches what came from an HTML fragment cache that contains business data cached at the UI layer, which in turn resulted from database data cached in the business layer that came from the database cache. Caching already cached data is particullarly bad, so you should decide carefully at which layer caching should be applied.</li>
<li><strong>Homegrown caching </strong>(e.g. a hastable) should be used sparingly. It is ok for stable data (e.g. reflection data) that cannot change afterwards. But make sure the cache does not grow infinitely and don&#8217;t forget to use a reader/writer lock.</li>
<li>Use a <strong>real cache implementation </strong>(e.g.<em> System.Web.Caching.Cache</em>) where possible, one that lets the cached data expire. Leverage expiration strategies (e.g. absolute or sliding expiration) depending on the measured hit and miss statistics.</li>
<li>Make sure your caching strategy isn&#8217;t invalidated by <strong>load balancing strategies</strong>. The cache hit rate can only degrade in a web farm.</li>
<li>As a corollary: Don&#8217;t expect certain data to be in the cache.</li>
</ul>
<p>Your caching strategy should answer a few questions and help other people in the project to understand why caching is used in one place but not in the other. It should include criterias for:</p>
<ul>
<li>choosing caching candidates</li>
<li>selecting caching locations</li>
<li>deciding upon cache time and scope</li>
</ul>
<p>Let&#8217;s see what the options for these topics are:</p>
<p><strong>Good caching candidates:</strong></p>
<p>Not all data is a good candidate for caching. Good candidates usually fullfill (most of) these criterias:</p>
<ul>
<li>Aquiring the information takes a considerable amount of time.</li>
<li>Caching the information does not use precious resources (i.e. too much memory, open connections, additional processing time due to de/serialization, &#8230;)</li>
<li>The probability that this information is requested several times afterwards within a reasonable time span is high.</li>
<li>The probability that this information is changed &#8211; especially concurrently &#8211; (and thus the cache invalidated) is low.</li>
<li>Physical layer transistions: Whenever the transistion has to cross process boundaries, networks with bandwidth constraints, data transformation, security checks, etc., the probability to gain performance by avoiding the transition is high.</li>
</ul>
<p><strong>Good caching locations:</strong></p>
<p>In order to avoid double caching you need to decide where to cache and where not. Good locations include:</p>
<ul>
<li>Layer transitions: They are quite good candidates since layers (should) provide a clean and well-defined interface. You may be able to introduce a lightweight caching layer between two layers, thus removing all caching logic from the layers themselves. This works particular good if you already use factory patterns to access the next layer.</li>
<li>Singleton classes: If you have channeled access to certain information through some kind of class (proxy, helper, singleton, &#8230;) this class provides the very spot to employ caching. Within this class you can control cache access, cache invalidation, etc.. The user of this class doesn&#8217;t even need to know the data is cached.</li>
</ul>
<p><strong>Caching time and expiration:</strong></p>
<p>Most data becomes outdated or unused after some time. It is sensible to decide when to throw the data away.</p>
<ul>
<li>Inifinitely stable data: Data that can&#8217;t change during runtime (e.g. reflection data, machine information, or configuration data within the web.config) could be cached infinitely (i.e. as long as the app domain lives). However you should make sure that this data does not grow infinitely in size and remains a good caching candidate over time.</li>
<li>Data subject to occasional nonsignificant changes: Some data may change rarely and if it does, the change does not have to be applied immediately. A typical example is changes to passwords or configurations that become effective within the next 15 minutes. This data is a good candidate for caching with absolute expiration and requires no effort to maintain cache consistency. The changing part however (e.g. some administration screens) need to be able to bypass the cache to get access to the current values.</li>
<li>Data subject to occasional significant changes: If changes happen only rarely but need to be applied immediately (e.g. when changing some key tables) there is the option to deliberately throw away the whole cache data rather than going at length to maintain cache integrity.</li>
<li>Data subject to frequent changes: If the data shall be cached but it is likely that it might be changed during cache time you&#8217;ve got the worst possible case. You need to maintain cache integrity, i.e. every operation affecting the data needs to update the cache accordingly (i.e. update the cached data or simply remove it).</li>
<li>Data subject to concurrent changes: If data may be changed in the database or backendsystem concurrently by other users you cannot avoid going to the database with each data request. However there are still some options:
<ul>
<li>If the data is needed more than once during one web request (e.g. several parts in a web page of a CRM system need the current customer), you may employ a page cache (thus one data request per web request is made rather than one for each part). This cache is quite simple as it does not have to deal with expiration (it dies with the page), concurrency, and only rarely with cache consistency.</li>
<li>It may be the case that the database supports some kind of &#8220;the data hasn&#8217;t changed&#8221; feedback which is considerably faster than asking for the data itself. In this case you have the means to cache the data and still maintain cache integrity.</li>
<li>It may also be the case that the database or backend system supports some kind of event that tells you some data has changed. The ASP.NET caching supports <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.web.caching.aspx">cache dependencies</a> to do just that, supporting dependencies on files, other cache items, and notably <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.web.caching.sqlcachedependency.aspx">SQL Server 2005</a>.</li>
</ul>
</li>
</ul>
<p><strong>Caching scope:</strong></p>
<p>Depending on the scope of the data you have different options for the location of the cache store:</p>
<ul>
<li>Caching on the client: Infinitely stable data is best cached at the client. This includes static files (images, scriptfiles, static HTML files, &#8230;) in web applications (which is only some configuration in IIS) but also stable key tables and business data for smart client applications.</li>
<li>Caching for the whole application: Stable data that cannot be sent to the client and data that is user independent can be cached in the global application cache without user reference. Key tables are a perfect example.</li>
<li>Caching for the single user: Data that is user dependent can still be cached. Examples would be user rights calculated based on his roles, personalization information, etc.. One may use the global cache with user-dependent cache key or the user session for this data.</li>
<li>Request cache: Data that is used several times during a request but otherwise needs to be up-to-date can very well be cached during the processing of a request. A simple hashtable within the page may be enough.</li>
</ul>
<p><strong>Special cases:</strong></p>
<p>There are some special cases in ASP.NET applications that I mention for completeness:</p>
<ul>
<li>Caching of view state: View state in ASP.NET pages may become quite big, grid controls are especially heavy-weighted in this respect. This is an issue for low speed connections. You can mitigate the problem with HTTP compression, yet storing the view state on the server rather than sending it to the client may prove to be more effcient. ASP.NET 2.0 already <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/system.web.ui.sessionpagestatepersister.aspx">supports</a> that.</li>
<li>Caching of session state: Session state should be held out-of-proc to avoid problems with app domain restarts or web farms. However, accessing the state data requires inter process communication, serialization, and optionally database access. As long as you only do reads (usually the majority of the calls) you could cache the session data (provided you don&#8217;t have load balancing in place). It&#8217;s a rare situation but if you have heavy-weighted or complex session data you may bennefit from this.</li>
</ul>
<p>Finally done. I cannot believe it. This is probably the final post about performance for quite some time. What was intended as one little innocent postling became a grown-up, mature familly. Perhaps they&#8217;ll reproduce in the future but for now the offspring has to grow up and prosper. Hopefully in one of your projects, I would be glad.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/10/18/cache-as-cache-can/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/10/18/cache-as-cache-can/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/60/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/60/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=60&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/10/18/cache-as-cache-can/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/10/18/cache-as-cache-can/" medium="image" />
	</item>
		<item>
		<title>Optimize it!</title>
		<link>http://ajdotnet.wordpress.com/2006/10/10/optimize-it/</link>
		<comments>http://ajdotnet.wordpress.com/2006/10/10/optimize-it/#comments</comments>
		<pubDate>Tue, 10 Oct 2006 18:37:52 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/10/10/optimize-it/</guid>
		<description><![CDATA[Hi there, back for some more talk about performance? The last posts (&#8220;Performance is King…&#8221;) were primarily about preparing for performance. If you follow this advice you will hopefully know how to detect performance problems and how to react. But at some point in time you will actually have to do somethinig about performance, in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=59&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi there,</p>
<p>back for some more talk about performance?</p>
<p>The last posts (<a href="http://ajdotnet.wordpress.com/2006/10/03/performance-is-king-3/">&#8220;Performance is King…&#8221;</a>) were primarily about <em>preparing </em>for performance. If you follow this advice you will hopefully know how to detect performance problems and how to react. But at some point in time you will actually have <em>to do </em>somethinig about performance, in one word: optimize. This means get your hands dirty, do some measurement, dig into the code, and eventually put some code in place that is meant to speed up runtime performance. I may have some advice for this end of the performance topic as well…</p>
<p><strong>First some links:</strong></p>
<ul>
<li>If you are really performance aware, then reading &#8220;<a target="_blank" href="http://blogs.msdn.com/ricom">Rico Mariani’s Performance Tidbits</a>&#8221; is mandatory.</li>
<li>Especially on the issue of reflection (and the cost of certain method calls) there is a good article on msdn: <a target="_blank" href="http://msdn.microsoft.com/msdnmag/issues/05/07/Reflection/default.aspx">Reflection &#8212; Dodge Common Performance Pitfalls to Craft Speedy Applications</a>.</li>
</ul>
<p><strong>Next the obligatory advice: </strong>It may not come as big surprise: <em><u>No premature optimization!</u></em></p>
<p>Now, this is a sentence that has been used that often, it may have lost ist meaning due to abrasion. I therefore strongly recommend to read that sentence again, this time as if for the first time. Also read the essay &#8220;<a target="_blank" href="http://www.acm.org/ubiquity/views/v7i24_fallacy.html">The Fallacy of Premature Optimization</a>&#8221; to really understand what it means &#8211; and (perhaps more importantly) what not.</p>
<p>My own attitude towards premature optimization is: If you start with a sound design (that does not pose performance risks in itself) the <a target="_blank" href="http://en.wikipedia.org/wiki/KISS_principle">KISS principle</a> in coding is the best preparation for upcoming demands (including optimizations). Optimization on the other hand usually complicates the code. I therefore refrain from optimizations as long as I don&#8217;t have a fully functional application that can be diagnosed as a whole.<br />
Usually the first profiling shows a mixture of things I expected to be slow, things I would not have expected, as well as the notable absence of things I would have expected to show up. And usually the things with the highest potential for optimization are related to how different parts of the application work together, things I could not even have optimized beforehand. (q.e.d.)</p>
<p><strong>One obvious (but sometimes forgotten) hint: </strong><em><u>Performance optimization comes at a price!</u></em></p>
<p>Generally optimized code tends to be <em>more</em> code; code being more complex, code with bugs, code to maintain, code to document. Code that is usually less resuable, less robust against context or use case changes, etc.. It is also code that takes time to execute; if the chosen optimization strategy doesn&#8217;t catch on the performance will be hurt rather than helped.</p>
<p>A typical optimization scenario is trading memory for processing time (i.e. any kind of caching or data redundancy). Memory consumption hurts scaleability. Data redundancy poses the risk of data inconsistencies. Another scenario is introduction of asynchronous/parallel processing. This may cause concurrency issues and race conditions.  Any optimization strategy has its pitfalls.</p>
<p>As consequence you should always measure performance and scalability before and after the optimization and decide carefully whether it&#8217;s worth the price. In my opinion a tiny fraction of improvement usually isn&#8217;t worth the increased complexity in in all but the most performance critical applications.</p>
<p><strong>Choose the right optimization strategie:</strong></p>
<p>If you run into a performance problem there is usually more than one option to solve it. The ability to choose one or the other (or a combination) is benefitial as it allows you to react differently depeding on the current situation (i.e. temporarily throw in hardware in production and deploy the optimized version with the next regular release &#8211; whether you give the hardware back is another question <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ).</p>
<p>I know you know your job and I know that the list below is probably not exhaustive. Anyway, I&#8217;ll try to name some typical optimization strategies; it may help to have a list of possible options.</p>
<ul>
<li>Infrastructure
<ul>
<li><strong>Scale up:</strong> just add more processors, memory, or (in the case of a certain developer) another monitor <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  .</li>
<li><strong>Scale out/load balancing: </strong>adding more machines improves performance as well as fault tolerance &#8211; but only if the server side application architecture actually is scalable and can leverage this new machine.</li>
<li><strong>Use dedicated/specialized hardware:</strong> This includes RAID systems for I/O intensive applications (read: database servers), storage systems such as EMC centera (for huge amounts of bulk data), hardware based encryption, etc.. In one project we even used hardware based XSD validation and XSLT processing.</li>
</ul>
</li>
<li>Design/Architecture:
<ul>
<li><strong>Streaming:</strong> a typical approach when processing large files (especially XML files). This will not only improve performance but especially scalability.</li>
<li><strong>Asynchronous workload distribution: </strong>instead of doing a lengthy operation when the user is waiting, just put it in a queue and tell the user you&#8217;re done. Do the real work later or on other machines.</li>
<li><strong>Changes in user experience </strong>(visual feedback, abuse wait times already there): this is not actually optimization, yet it may solve the same problems. Just tell the user you are busy. And if the user has already accepted to wait for some time, why not do some additional stuff?</li>
</ul>
</li>
<li>Data Access
<ul>
<li><strong>Caching: </strong>Caching can be applied in all application layers from client to backend. Caching is usefull if aquiring the data takes noteable time. This can be caused by the providing piece of code (say with databases or reflection) or by the way to get there (e.g. network bandwidth, marshaling costs, etc.).<br />
Less obvious is the fact that certain things done in (to?) databases can be seen as caching: indexes, materialized views in oracle, non-normalized tables (i.e. data redundancy). This things may also be done with in-memory data structures.</li>
<li><strong>Reuse costly resources: </strong>the most common example is databases connection sharing, web browsers do something similar with HTTP connections. Thread pools and garbage collection also fall into that category.</li>
<li><strong>Batch/bulk processing, call aggregation: </strong>whenever setup and tear down time take a notable amount of time compared with the actual processing of one item, processing more than one item at a time immediately pays back. During a mass update put chunks of updates in a transaction (rather than each row in its own), also combining remote calls (e.g. with Web Services) will improve performance (actually corse grained remote calls may be seen as batched-up fine grained calls)</li>
</ul>
</li>
<li>Initialization
<ul>
<li><strong>Lazy initialization: </strong>If initialization is costly do it as late as possible &#8211; and perhaps not at all. Lazy initialization distributes performance and improves startup time. The risk to take is domino effects (that compensate the aspired gain) and undetermined initialization sequences.</li>
<li><strong>Proactive initialization: </strong>Application startup takes time. Why not take a little more time and have the application run afterwards? This is especially usefull for server applications. It also accounts for more stability since defered initialization also means defered error detection.</li>
</ul>
</li>
<li>Source Code Optimizations
<ul>
<li><strong>Choose the right algorithms and data structures</strong>.</li>
<li><strong>Know the costs of certain methods and keywords. </strong>&#8220;foreach&#8221; introduces more overhead than &#8220;for&#8221; does. &#8220;string.Format&#8221; is quite costly (interestingly it is often used for tracing which is turned of most of the time). Reflection is costly in itself. Other methods may hiddenly affect performance if they cause assemblies to be loaded or code to be generated (e.g. regular expressions or XPath).</li>
</ul>
</li>
</ul>
<p>As I said, this list is not exhaustive. However, please let me know if I missed something particular important.</p>
<p>Now I&#8217;ve provided you with some additional advice and a bunch of options. If you are the type that can&#8217;t decide in a restaurant when presented with a particular long menu I&#8217;ll have done you a bad service. If you welcome the breadth of choice you could hopefully pick up something new.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/10/10/optimize-it/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/10/10/optimize-it/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/59/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/59/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=59&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/10/10/optimize-it/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/10/10/optimize-it/" medium="image" />
	</item>
		<item>
		<title>&#8220;Fatherly Advice To New Programmers&#8221; (Chuck Jazdzewski)</title>
		<link>http://ajdotnet.wordpress.com/2006/10/07/fatherly-advice-to-new-programmers-chuck-jazdzewski/</link>
		<comments>http://ajdotnet.wordpress.com/2006/10/07/fatherly-advice-to-new-programmers-chuck-jazdzewski/#comments</comments>
		<pubDate>Sat, 07 Oct 2006 14:38:18 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Software Developers]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/10/07/fatherly-advice-to-new-programmers-chuck-jazdzewski/</guid>
		<description><![CDATA[Hi, I just stumbled over the post Fatherly Advice To New Programmers (Chuck Jazdzewski). He summarizes quite comprehensively what I think should be the attitude of any developer towards our profession. The advice to &#8220;grown up programmers&#8221; would be: Share your experience just like Chuck did. That&#8217;s all for now folks, AJ.NET<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=58&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>I just stumbled over the post <a target="_blank" href="http://www.removingalldoubt.com/commentview.aspx/a32977e2-cb7d-42ea-9d25-5e539423affd">Fatherly Advice To New Programmers</a> (Chuck Jazdzewski). He summarizes quite comprehensively what I think should be the attitude of any developer towards our profession.</p>
<p>The advice to &#8220;grown up programmers&#8221; would be: Share your experience just like Chuck did.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/58/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/58/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/58/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=58&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/10/07/fatherly-advice-to-new-programmers-chuck-jazdzewski/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Performance is King&#8230; (3)</title>
		<link>http://ajdotnet.wordpress.com/2006/10/03/performance-is-king-3/</link>
		<comments>http://ajdotnet.wordpress.com/2006/10/03/performance-is-king-3/#comments</comments>
		<pubDate>Tue, 03 Oct 2006 18:15:58 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/10/03/performave-is-king-3/</guid>
		<description><![CDATA[&#8230; but somtimes the jester rules. This is part three of our little series, see here for part one and part two. OK, five done, three to go: If someone complains about performance problems: 6. Don&#8217;t deny or fingerpoint. Don&#8217;t ignore these concerns, even if unsubstantiated or inappropriate There is a fact to realize and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=57&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8230; but somtimes the jester rules.</p>
<p>This is part three of our little series, see here for <a href="http://ajdotnet.wordpress.com/2006/09/28/performance-is-king/">part one</a> and <a href="http://ajdotnet.wordpress.com/2006/10/01/performance-is-king-2/">part two</a>.</p>
<p>OK, five done, three to go:</p>
<p><em>If someone complains about performance problems: </em></p>
<p><strong>6. Don&#8217;t deny or fingerpoint. Don&#8217;t ignore these concerns, even if unsubstantiated or inappropriate </strong></p>
<p>There is a fact to realize and accept: If you are working on the UI layer of an application, you are likely to be the &#8220;face to the customer&#8221;. The UI surfaces all features and their characteristics to the user, so the customer will tell <em>you</em> that loading that page takes way to long. Not the database guy. Not the infrastructure people. <em>You!</em></p>
<p>If the problem is in the UI, there&#8217;s no point in denying. If it&#8217;s in the adjacent layers, help the people responsible for those areas &#8211; but also try to compensate (in case the other guy can&#8217;t handle the problem).</p>
<p>The key takeaways of this point should be:<br />
1. Work with the other guys to solve the problem, not against them.<br />
2. At the same time try to mitigate/compensate any shortcommings of the called layer/systems.</p>
<p>What you should <em>not </em>do is: Don&#8217;t ignore the customers concerns, even if they are not appropriate (e.g. because the application being tested was an early development build). At least take note of the pain and actively address it later. The customer usually is not interested in who actually caused the problem (even &#8211; or rather especially &#8211; if it was himself). But it will be you who solved it.</p>
<p><strong>7. Understand the problem. </strong></p>
<p>Is the problem really a performance problem? Or is the customer actuallay aware that the current action takes time and he is just asking for some kind of feedback (e.g. some kind of progress dialog).</p>
<p>Is the customer acting within the specification?<br />
The other day we had a specification for some email distribution function. About 20 emails average. It was perfectly valid to send these emails synchronously and provide instant feedback on success and failure. Then came this power user out of nowhere, sending 5000 emails at once. And in his wake the other real world users, sending 1000 average. Another example would be to use a grid component that does sorting and other gimicks via scripting on the client side &#8211; and users that request a result set of 300,000 rows.<br />
These are perfect examples of performance problems that actually are specification issues. They cannot be adressed with profilers, they need design changes.</p>
<p>Key takeaway: Unless you know exactly what the actual demand is, any action taken is futile. The range of possible actions might include classical optimization, design changes, strip down the feature, or even teaching the customer.</p>
<p><em>After initial deployment: </em></p>
<p><strong>8. Harden your application. </strong></p>
<p>Eventually your first version will be delivered and the first group of users will begin working, hopefully satisfied. Before starting to work on the next features, take the chance to harden your application against future demands. The number of users will increase, as well as the amount of data in your system. Thus, the fact that your system can handle the current workload accounts for nothing.</p>
<p>Do extensive load testing, especially under stress and abuse conditions (i.e. pull the network cable of the database server). Do this with complex data, real life data, mass data, data out of the specification, and under load test conditions. Verify that the system remains stable under reoccuring error conditions. Have some fun with abuse tests. (Did you know that Porsche tests his cars offroad?)</p>
<p>This way you will learn how much workload your application can handle and how robust it is against unexpected circumstances.</p>
<p>Ouff, finally done. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> </p>
<p>Now, just for the fun of it, reread this list (including the previous post) and think about what these things will accomplish that is <em>not </em>performance related. Right, nothing of this is purely performance related, some things even barely (in other words, you should be doing them anyway). In other words: Preparing for performance this way will have positive effects on the quality of your application in very different ways, far exceeding simple call time improvement.</p>
<p>PS: This post concludes this little series about preparing for performance in a project. I may have to say something about actually optimizing (you know, the time when you get to use profilers&#8230;), yet this was not my intention for now.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/10/03/performance-is-king-3/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/10/03/performance-is-king-3/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/57/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/57/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=57&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/10/03/performance-is-king-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/10/03/performance-is-king-3/" medium="image" />
	</item>
		<item>
		<title>The bear has arrived&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2006/10/03/the-bear-has-arrived/</link>
		<comments>http://ajdotnet.wordpress.com/2006/10/03/the-bear-has-arrived/#comments</comments>
		<pubDate>Tue, 03 Oct 2006 17:59:57 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/10/03/the-bear-has-arrived/</guid>
		<description><![CDATA[Hi, I just added the bear pictures to the Blackcomb and Whistler post. Our neighbours had just prepared their breakfast (greetings to the folks from NZ, GB and Scotland) when a black bear came along and took the invitation&#8230; . Most people from my group (including me) just came back from the washrooms and had no [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=56&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>I just added the bear pictures to the <a href="http://ajdotnet.wordpress.com/2006/09/26/blackcomb-and-whistler/">Blackcomb and Whistler</a> post.</p>
<p>Our neighbours had just prepared their breakfast (greetings to the folks from NZ, GB and Scotland) when a black bear came along and took the invitation&#8230; . Most people from my group (including me) just came back from the washrooms and had no chance to get to their cameras. And the two who had the opportunity to shoot pictures obviously have been a little shaky. Quite understandable, at one occasion the bear was two or three meters away, coming in my direction 8-O.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET </strong></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/56/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/56/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/56/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=56&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/10/03/the-bear-has-arrived/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Performance is King&#8230; (2)</title>
		<link>http://ajdotnet.wordpress.com/2006/10/01/performance-is-king-2/</link>
		<comments>http://ajdotnet.wordpress.com/2006/10/01/performance-is-king-2/#comments</comments>
		<pubDate>Sun, 01 Oct 2006 14:13:34 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/10/01/performance-is-king-2/</guid>
		<description><![CDATA[&#8230; but Kings need advisers. Welcome back. (This is part two of this little series.) Now, lets look at some of the points (i.e. the &#8220;During design and development&#8221; part) mentioned in the previous post more closely: During design and development: 1. Keep performance in mind. Check your design under performance condiderations. This should be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=53&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8230; but Kings need advisers.</p>
<p>Welcome back. (This is part two of this little series.)<br />
Now, lets look at some of the points (i.e. the &#8220;During design and development&#8221; part) mentioned in the <a href="http://ajdotnet.wordpress.com/2006/09/28/performance-is-king/">previous post</a> more closely:</p>
<p><em>During design and development: </em></p>
<p><strong>1. Keep performance in mind. Check your design under performance condiderations. </strong></p>
<p>This should be an easy one, most experienced developers and architects do this without thinking of it. The things I&#8217;m refering to are like</p>
<ul>
<li>If the user has a search screen, make sure you think about large search results.</li>
<li>If the user shall trigger some repeated activity (e.g. send emails to a list of recipients), make sure the list is guaranteed to be small or the processing is done asynchronously.</li>
<li>Allways be wary about the number of calls into outside systems (database, WebServices, etc.) and know about response times and error conditions of those systems.</li>
<li>Use coarse grained calls for out-of-proc-calls</li>
<li>…</li>
</ul>
<p>That kind of stuff.</p>
<p>Well, as I said, this <em>should </em>be an easy one, but there&#8217;s a pitfall: You have to <em>know </em>about actuall demands your application has to fullfill. Do you have a quantity structure for the expected data? Do you know how many rows to process (and whether you can do it asynchronously)? How stable is the WebService you are about to call?<br />
This kind of information is rarely readily available and asking the business people usually doesn&#8217;t help either. You&#8217;ll have to develop a feeling for areas prone to such surprises. A little risk management doesn&#8217;t hurt either.</p>
<p><strong>2. Put measurement points in your code to understand the performance distribution.</strong></p>
<p>There should be measure points across all relevant parts, in all layers of your application. This is as simple as having a begin trace and an end trace around some lengthy processing or call to the next layer with the time spent between the two.<br />
Trace the time spent in rendering, databinding, calling into the database, calling into web services, and other foreign code, special functions (e.g. heavy usage of reflection), etc.. Following the control flow of an incomming request, you should know how much time is spend in what part of your application or during outside calls.</p>
<p>During initial performance tests (latest) look at this measurement data. Is the distribution feasible? (Most of the time should usually be spend in the database.) Are the absolute numbers more or less acceptable? (If yes, don&#8217;t optimize!) Do this with real life data (regarding amount and complexity).</p>
<p>This should have two effects:<br />
1. You will know whether you have a performance problem before the customer knows. Congratulations.<br />
2. If someone complains about performance you will be able to assess that statement and answer with confidence.</p>
<p>Note: This is not enough, but in my experience you are lucky to even have the time to do that. If on the other hand you are working at developers garden of eden, you might also work on the things I listed under #8.</p>
<p><strong>3. Encapsulate areas prone to performance issues </strong></p>
<p>If your calls to a certain WebService (or a database, or doing reflection, accessing session state, or whatever it is that potentially may take up more time than acceptable) are spread across your code, what are you going to do if this really becomes a performance bottleneck? Encapsulate those things in a helper or proxy class and you will be able to implement asynchronicity or caching if the need arises.</p>
<p>This is good coding style anyway, as you will be able to enforce usage patterns, track calling code, add performance counters, add type safe wrappers, provide helpers, etc..</p>
<p><strong>4. Make sure you have good test data </strong></p>
<p>Too many developers make the mistake of testing their code with data used during development. Get real live data and be prepared for some surprises. Get random and deliberately wrong data and see how your code fares under rough conditions. Ask someone else to prepare test data to avoid &#8220;blinders effects&#8221;. Most important: Get mass data to see how your code scales with the data amount.</p>
<blockquote><p>I once worked in a project where they had decided to put all data related business logic into the database &#8220;where it belongs&#8221;. They implemented the logic with 3 test data rows (perfectly valid) and went to the test phase without doing more (perfectly futile). The testers had about 100 rows in the database (not very much at all and still not nearly the amount that was expected in production). The initial query took a around 14 minutes. One hundred rows is hardly &#8220;mass data&#8221;, right?</p></blockquote>
<p>And don&#8217;t simply lean back if you have test or QA guys in your project whose job it is to do just that. Usually they know how to write test plans but very little about your code and the resulting test points. Help them helping you.</p>
<p><strong>5. Plan for initial performance tests </strong></p>
<p>You may call it by its name in the project plan or you may hide it as bug fixing time, code review, or code documentation. You may do it as part of a final testing phase or as part of the developers testing for single development tasks. You may assign this task to a certain developer or have everyone doing it for his own code. Like ordinary testing, this really does not matter as long as you actually do it. (I&#8217;m not saying this does not have an effect on the efficiency of the testing. I&#8217;m saying that with many real world projects it is not a question of how effective your testing is but whether you do <em>organized</em> testing at all.)<br />
Just don&#8217;t make the mistake to use it as time buffer if your project runs out of time (as quite often happens to testing).</p>
<p>Personally I would rather kick a part of the common testing than performance testing. In my experience performance analysis leads to a very efficient form of code review (as it trails along the control flow) and you will probably find more slips and bugs this way than with any other testing.</p>
<p>I have also had good experiences with doing these performance tests more than once within an iteration. Ususally initial versions of new functionalities, reworks of core code, or the realization that the last performace analysis is some time ago will be a good reason.</p>
<p>And I thought shorter posts would be easier… . Anyway, the next post should conclude this little series. Hopefully.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET </strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/10/01/performance-is-king-2/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/10/01/performance-is-king-2/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/53/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/53/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=53&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/10/01/performance-is-king-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/10/01/performance-is-king-2/" medium="image" />
	</item>
		<item>
		<title>Performance is King&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2006/09/28/performance-is-king/</link>
		<comments>http://ajdotnet.wordpress.com/2006/09/28/performance-is-king/#comments</comments>
		<pubDate>Thu, 28 Sep 2006 18:38:49 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/09/28/performance-is-king/</guid>
		<description><![CDATA[&#8230; but Kings are not infallible. Recently I was asked to look into a project because someone presumed the application may have performance problems. Despite the fact that the application was barely functional and they had virtually no real life test data they were worried enough to call me in. This proves again that performance [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=52&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8230; but Kings are not infallible.</p>
<p>Recently I was asked to look into a project because someone presumed the application may have performance problems. Despite the fact that the application was barely functional and they had virtually no real life test data they were worried enough to call me in. This proves again that performance is always a key concern of … well, everybody.</p>
<p>I have been working on very different projects with very different performance demands (ranging from an archive service that needs to be able to handle up to 20 mio messages during business hours, to load balanced web applications, to windows client applications that can use up the whole machine for their purpose). And yet, if it comes to performance they have more in common than one would think.</p>
<p>So, what do you do if a customer complains about poor performance? How do you prepare for this situation? More often than not the answer is like &#8220;well, we haven&#8217;t been looking into the performance yet…&#8221;.<br />
Avoiding that pitfall is easier than one might think, and it doesn&#8217;t even take that much effort. Actually most of the concrete suggestions below are not just performance related but also help in other areas.</p>
<p><strong>Here&#8217;s some lessons learned that might help: </strong></p>
<p><em>During design and development:<br />
</em>1. Keep performance in mind. Check your design under performance condiderations.<br />
2. Put measurement points in your code to understand the &#8220;performance distribution&#8221; (i.e. how much time is spend in which part of the code).<br />
3. Encapsulate areas prone to performance issues.<br />
4. Make sure you have good test data (complex data, usual data, real life data, mass data, invalid data out of the specification).<br />
5. Plan for initial performance tests.</p>
<p><em>If someone complains about performance problems:<br />
</em>6. Don&#8217;t deny or fingerpoint. Don&#8217;t ignore these concerns, even if unsubstantiated or inappropriate<br />
7. Understand the problem.</p>
<p><em>After initial deployment:<br />
</em>8. Harden your application.</p>
<p>Now, theses posts tend to get longer and longer, I&#8217;ll therefore split this topic into several parts. Mean, ey? Just like in TV with the advertisment break just before the murder is being resolved <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . Anyway, I can&#8217;t help it, so please bear with me and stay tuned. The next posts will dig into each single point.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET </strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/09/28/performance-is-king/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/09/28/performance-is-king/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/52/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/52/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=52&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/09/28/performance-is-king/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/09/28/performance-is-king/" medium="image" />
	</item>
		<item>
		<title>Blackcomb and Whistler (and finally the baer&#8230;)</title>
		<link>http://ajdotnet.wordpress.com/2006/09/26/blackcomb-and-whistler/</link>
		<comments>http://ajdotnet.wordpress.com/2006/09/26/blackcomb-and-whistler/#comments</comments>
		<pubDate>Tue, 26 Sep 2006 16:58:28 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/09/26/blackcomb-and-whistler/</guid>
		<description><![CDATA[Hi there, I&#8217;m back from vacation. Usually I try to keep this blog strictly technology related, yet no rule without exception . I&#8217;ve been in Canada &#8211; great country &#8211; on a camping and hiking trip (Calgary, Banff, Jasper, Mt Robson, Wells Grey, Vancouver Island, Vancouver). Great weather (rain where it belongs - in the rain [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=46&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi there,</p>
<p>I&#8217;m back from vacation. Usually I try to keep this blog strictly technology related, yet no rule without exception <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>I&#8217;ve been in Canada &#8211; great country &#8211; on a camping and hiking trip (Calgary, Banff, Jasper, Mt Robson, Wells Grey, Vancouver Island, Vancouver). Great weather (rain where it belongs - in the rain forrest, snow in the rockies a week after we left, and close to no mosquitoes).</p>
<p>Oh, and by the way, there was a stopover in <a target="_blank" href="http://www.whistler.ca">Whistler</a>. For those who didn&#8217;t know yet: These are pictures of the real Blackcomb and Whistler:</p>
<p><img width="400" src="http://ajdotnet.files.wordpress.com/2006/09/blackcomb.JPG?w=400&#038;h=300" alt="Blackcomb" height="300" /><br />
<strong>Blackcomb</strong></p>
<p align="center"><img width="400" src="http://ajdotnet.files.wordpress.com/2006/09/whistlerm.JPG?w=400&#038;h=300" alt="Whistler (the mountain)" height="300" /><br />
<strong>Whistler (the mountain)</strong></p>
<p align="right"><img width="400" src="http://ajdotnet.files.wordpress.com/2006/09/whistlerc.JPG?w=400&#038;h=300" alt="Whistler (the city)" height="300" /><br />
<strong>Whistler (the city)</strong></p>
<p>Together they constitute Canadas largest <a target="_blank" href="http://www.whistlerblackcomb.com">skiing region</a> (North Americas second largest, frequented by Microsofties which is probably why they used it as <a target="_blank" href="http://www.microsoft.com/presspass/press/2000/Oct00/Whistler1PR.mspx">code names</a>), as well as mountain biking during summer and a fine bear breakfast campground as you can see here:</p>
<p><img width="400" src="http://ajdotnet.files.wordpress.com/2006/10/baer.jpg?w=400&#038;h=300" alt="A bear at Whistler campground, having breakfast" height="300" />  <img width="400" src="http://ajdotnet.files.wordpress.com/2006/10/baer2.JPG?w=400&#038;h=300" alt="A bear at Whistler campground, comming after me..." height="300" style="width:400px;height:300px;" /><br />
<strong>Bear Breakfast</strong></p>
<p>Me, I don&#8217;t care very much for such resorts, yet eating at the <a target="_blank" href="http://www.mongoliegrill.com">Mongolie Grill</a> was <a target="_blank" href="http://www.igougo.com/travelcontent/journalEntryDining.aspx?JournalID=28830&amp;EntryID=18794&amp;n=Mongolie%20Grill&amp;t=Healthy%20Dining">cool</a>:</p>
<p align="center"><img width="400" src="http://ajdotnet.files.wordpress.com/2006/09/mongoliegrill.JPG?w=400&#038;h=300" alt="Mongolie Grill" height="300" /><br />
<strong>Mongolie Grill</strong></p>
<p>Today skiers, mountain biking enthusiasts, bears, and IT people know the names Blackcomb and Whistler (quite an unusual mixture if you ask me). But this will probably change in 2010 when the <a target="_blank" href="http://www.whistler.ca/Vancouver_2010/Whistler_Venues/index.php">Winter Olympics</a> will be held there.</p>
<p>OK, that&#8217;s it. The next post will be more technology related (promise, I&#8217;m allready working on it).</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET </strong></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/46/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/46/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/46/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=46&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/09/26/blackcomb-and-whistler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/09/blackcomb.JPG" medium="image">
			<media:title type="html">Blackcomb</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/09/whistlerm.JPG" medium="image">
			<media:title type="html">Whistler (the mountain)</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/09/whistlerc.JPG" medium="image">
			<media:title type="html">Whistler (the city)</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/10/baer.jpg" medium="image">
			<media:title type="html">A bear at Whistler campground, having breakfast</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/10/baer2.JPG" medium="image">
			<media:title type="html">A bear at Whistler campground, comming after me...</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/09/mongoliegrill.JPG" medium="image">
			<media:title type="html">Mongolie Grill</media:title>
		</media:content>
	</item>
		<item>
		<title>Long Live Console Applications!</title>
		<link>http://ajdotnet.wordpress.com/2006/08/31/long-live-console-applications/</link>
		<comments>http://ajdotnet.wordpress.com/2006/08/31/long-live-console-applications/#comments</comments>
		<pubDate>Thu, 31 Aug 2006 16:07:35 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/08/31/long-live-console-applications/</guid>
		<description><![CDATA[There are some things every decent developer has to have done (well, at least with some C++ background): write his own collection/tree classes write his own string class write his own console class With the advent of standard classes (e.g. stl, MFC, or others in the C++ world, the java library and .NET base class [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=44&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are some things every decent developer has to have done (well, at least with some C++ background):</p>
<ol>
<li>write his own collection/tree classes</li>
<li>write his own string class</li>
<li>write his own console class</li>
</ol>
<p>With the advent of standard classes (e.g. stl, MFC, or others in the C++ world, the java library and .NET base class library in the post-C++ world) writing ones own hasttable or string class does not really make sense anymore (perhaps appart from academic interest or educational purposes). With console applications the situation is somewhat different because as of yet there is no standard or widespread library. Yet the demands for any non-trivial console application are reoccuring, boilerplate and tedious to do again and again and again.</p>
<p>What are console applications usefull for in the first place?</p>
<ul>
<li>Console applications are a necessity if to be used in batch files. And batch files are a necessity if one wants to automate tasks. Automate tasks on the other hand is the dayly business of administrators and with <a target="_blank" href="http://www.martinfowler.com/articles/continuousIntegration.html">continuous intergration</a> it has become the daily business of developers as well.</li>
<li>Console applications are the better services. If you thought of writing a service or some other kind of background application just to trigger some action at certain times or time intervals think again. The windows scheduler (or cron or whatever) already handles scheduling quite flexible. A console application registered with such as system will do the trick at cheaper cost, less effort, and provide more freedom in usage.</li>
<li>For experienced users the console usually offers more flexibility and is more efficient to use than GUI interfaces.</li>
</ul>
<p>Additionally, virtally any &#8220;enterprise application&#8221; actually is a familiy of applications, not only consisting of the main applications. Usually there are installation tasks, cleanup jobs, data import and export, nightly processing, diagnostics and maintenance tasks, and whatever else to do. Some of these tasks may be better done within a special environment (such as SQL jobs) but on the other hand, how do you have a SQL procedure participate in your applications error tracing?</p>
<p>There may be a time when build tasks (MSBuild, (N)ant, etc.) or libraries tailored for Monad (newly christened <a target="_blank" href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx">PowerShell</a>) will become a standard. But this time is not due tomorrow and probably not next year. Until then I have to admit I&#8217;m a fan of console applications. (Call it DOS nostalgia if you like. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ).</p>
<p>Speaking of PowerShell, the new command line shell Microsoft proposes, it may be just arround the corner. Betas are available (even a first RC) and are very promising. There is also some work done to maximize reuse of functionality between PowerShell, the new management console (MMC 3.0), and WMI. And all Microsoft server products will entually provide PowerShell support. As Bob Muglia (Microsofts Senior Vice President, Windows Server) said <a target="_blank" href="http://www.microsoft.com/presspass/exec/bobmuglia/09-15PDC2005.mspx">on the last PDC</a>: &#8220;<em>We are going to undergo a project over the next few years to get a full set of Monad commands across all of Windows Server, and across all of our server applications. […]</em>&#8220;. The PowerShell will probably also define the way to go for other companies developing for the Microsoft plattform.</p>
<p>And the good news: A properly designed commandline application is ideally prepared for PowerShell. The various combinations of command line arguments will just become different overloads/functions of the commandlet. No service application or job can do that.</p>
<p><strong>Bits&amp;Bytes</strong></p>
<p>As it has become my custom (share both, bits <em>and</em> opinion) I have decided to share my own little console framework. (After the intro you wouldn&#8217;t have suspected I have one, would you <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ?). It&#8217;s provided as is and it&#8217;s free, just mention my name and perhaps tell me of your extensions.</p>
<p>The framework is tailored for ease of use with applications that have more or less complex argument lists. You wouldn&#8217;t need it with trivial EXEs with a trivial fixed argument set and no useability demand (although I would argue that such applications do not exist). It also does not aim to fullfill academic pretensions, i.e. I refrained from trying to develop the last-framework-you-need that is fully metadata driven, aiming to solve all problems and doing it with 72 UML designed classes far to complex for the usual task at hand. I like the 80% approach and usually it fullfills 100% of my demands.</p>
<p>In this case the demands where primarily:</p>
<ul>
<li>Handle command line parsing</li>
<li>Handle user feedback (including logo and help messages)</li>
<li>Play a little with colored output (which is now readily supported with .NET 2.0)</li>
</ul>
<p>Here&#8217;s a short sample that should give you an idea of how to use it:</p>
<ul>
<li>Provide a ressource file with messages:</li>
</ul>
<blockquote><p><font size="-1" face="Courier"><font color="#0000ff">&lt;?</font><font color="#800000">xml</font> <font color="#ff0000">version</font><font color="#0000ff">=</font><font color="#0000ff">″1.0″</font> <font color="#ff0000">encoding</font><font color="#0000ff">=</font><font color="#0000ff">″utf-8″</font> <font color="#0000ff">?&gt;</font><br />
    <font color="#0000ff">&lt;</font><font color="#800000">root</font><font color="#0000ff">&gt;<br />
        </font><font color="#0000ff">&lt;</font><font color="#800000">data</font> <font color="#ff0000">name</font><font color="#0000ff">=</font><font color="#0000ff">″Logo″</font><font color="#0000ff">&gt;<br />
</font><font color="#0000ff">            &lt;</font><font color="#800000">value</font><font color="#0000ff">&gt;</font><font color="#000000">XCopy test application based on AJ.Console.ConsoleApp (c) by Alexander Jung &#8211; mailto:info@Alexander-Jung.NET</font><font color="#0000ff">&lt;/</font><font color="#800000">value</font><font color="#0000ff">&gt;</font><br />
        <font color="#0000ff">&lt;/</font><font color="#800000">data</font><font color="#0000ff">&gt;</font> <br />
        <font color="#0000ff">&lt;</font><font color="#800000">data</font> <font color="#ff0000">name</font><font color="#0000ff">=</font><font color="#0000ff">″Syntax″</font><font color="#0000ff">&gt;</font><br />
            <font color="#0000ff">&lt;</font><font color="#800000">value</font><font color="#0000ff">&gt;</font><font color="#000000">SYTNAX: XCopy.exe Source [Target] [/A | /M] [/EXCLUDE file1 [file2] [file3]. . . ]</font><font color="#0000ff">&lt;/</font><font color="#800000">value</font><font color="#0000ff">&gt;</font> <br />
        <font color="#0000ff">&lt;/</font><font color="#800000">data</font><font color="#0000ff">&gt;</font> <br />
        <font color="#0000ff">&lt;</font><font color="#800000">data</font> <font color="#ff0000">name</font><font color="#0000ff">=</font><font color="#0000ff">″Help″</font><font color="#0000ff">&gt;</font><br />
            <font color="#0000ff">&lt;</font><font color="#800000">value</font><font color="#0000ff">&gt;</font> <font color="#000000">This is just a simulation, no harm is done <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </font><font color="#0000ff">&lt;/</font><font color="#800000">value</font><font color="#0000ff">&gt;</font> <br />
        <font color="#0000ff">&lt;/</font><font color="#800000">data</font><font color="#0000ff">&gt;</font> <br />
<font color="#0000ff">&lt;/</font><font color="#800000">root</font><font color="#0000ff">&gt;</font> </font></p></blockquote>
<ul>
<li>Derive from a given base class and overwrite three methods (argument parsing, switch parsing and processing):</li>
</ul>
<blockquote><p><font size="-1" face="Courier"><font color="#0000ff">class</font> XCopyApp: ConsoleApp<br />
{<br />
    [STAThread]<br />
    <font color="#0000ff">static</font> <font color="#0000ff">int</font> Main(<font color="#0000ff">string</font>[] args)<br />
    {<br />
        XCopyApp app= <font color="#0000ff">new</font> XCopyApp();<br />
        <font color="#0000ff">return</font> app.Run(args);<br />
    }<br />
    <br />
    <font color="#0000ff">protected</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> ApplyArguments(<font color="#0000ff">string</font>[] values)<br />
    {<br />
        <font color="#008000"><em>// on argument is mandatory, the second optional </em></font><br />
        EnsureLength(values, 1, 2, <font color="#0000ff">null</font>);<br />
    }<br />
    <br />
    <font color="#0000ff">protected</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> ApplySwitch(<font color="#0000ff">string</font> name, <font color="#0000ff">string</font>[] values)<br />
    {<br />
        <font color="#0000ff">switch</font> (name.ToLower())<br />
        {<br />
            <font color="#0000ff">case</font> <font color="#800000">″/a″</font>:<br />
            <font color="#0000ff">case</font> <font color="#800000">″/m″</font>:<br />
                <font color="#008000"><em>// no additional arguments </em></font><br />
                EnsureLength(values, 0, 0, name);<br />
                <font color="#0000ff">break</font>;<br />
            <font color="#0000ff">case</font> <font color="#800000">″/exclude″</font>:<br />
                <font color="#008000"><em>// at least one additional argument </em></font><br />
                EnsureLength(values, 1, <font color="#0000ff">int</font>.MaxValue, name);<br />
                <font color="#0000ff">break</font>;<br />
            <font color="#0000ff">default</font>:<br />
                <font color="#008000"><em>// we don&#8217;t like what we don&#8217;t know </em></font><br />
                ThrowUnknownSwitch(name);<br />
                <font color="#0000ff">break</font>;<br />
        }<br />
    } </font><font size="-1" face="Courier">    <font color="#0000ff">protected</font> <font color="#0000ff">override</font> <font color="#0000ff">void</font> Process()<br />
    {<br />
        <font color="#008000"><em>// just print out some of the arguments intention </em></font><br />
        <font color="#0000ff">string</font>[] args= GetArguments();<br />
        WriteLine(<font color="#800000">″about to copy the following files: ″</font>+args[0]);<br />
        <font color="#0000ff">if</font> (args.Length&gt;1)<br />
            WriteLine(<font color="#800000">″target is: <font color="#800000">″</font></font>+args[1]);<br />
        <font color="#0000ff">if</font> (HasSwitch(<font color="#800000">″/a″</font>) || HasSwitch(<font color="#800000">″/A″</font>))<br />
            WriteLine(<font color="#800000">″only if archive bit is set, leaves the bit as is.″</font>);<br />
        <font color="#0000ff">if</font> (HasSwitch(<font color="#800000">″/m″</font>) || HasSwitch(<font color="#800000">″/M″</font>))<br />
            WriteLine(<font color="#800000">″only if archive bit is set, clears the bit afterwards.″</font>);<br />
    }<br />
}</p>
<p></font></p></blockquote>
<ul>
<li>And the output looks like (yet more colorfull):</li>
</ul>
<blockquote>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>[D:ProjektePrivAJ.ConsoleXCopybinDebug]xcopy
XCopy test application based on AJ.Console.ConsoleApp
(c) by Alexander Jung - mailto:info@Alexander-Jung.NET
Invalid number of argument: arguments needs at least 1 value(s).
Use /? for further information.            

[D:ProjektePrivAJConsoleXCopybinDebug]XCopy.exe /?
XCopy test application based on AJ.Console.ConsoleApp
(c) by Alexander Jung - mailto:info@Alexander-Jung.NET
SYTNAX: XCopy.exe Source [Target] [/A | /M]
                    [/EXCLUDE file1 [file2] [file3]...]
System parameter:
    @parameterfile      read arguments from file
    !logfile            write log file
    /?|/h[help]         show help
    /v[erbose]          verbose output
    /q[uiet]            no output
    /nologo             no logo            

This is just a simulation, no harm is done <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />             

[D:ProjektePrivAJ.ConsoleXCopybinDebug]xcopy *.* x: /M /nologo
about to copy the following files: *.*
target is: x:
only if archive bit is set, clears the bit afterwards.</pre>
</td>
</tr>
</table>
</blockquote>
<p>And finally the <a target="_blank" href="http://ajdotnet.files.wordpress.com/2006/08/ajconsole_zip.txt">code</a> (downlad and rename to *.zip).</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/44/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/44/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=44&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/08/31/long-live-console-applications/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Do You Value Design Time Support?</title>
		<link>http://ajdotnet.wordpress.com/2006/08/28/do-you-value-design-time-support/</link>
		<comments>http://ajdotnet.wordpress.com/2006/08/28/do-you-value-design-time-support/#comments</comments>
		<pubDate>Mon, 28 Aug 2006 05:26:50 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/08/28/do-you-value-design-time-support/</guid>
		<description><![CDATA[Good design time support for your components may seem like a nice exercise but otherwiese unnecessary and generally not worth the money (especially if it&#8217;s the customers money). After all, design time support plays no role at runtime when the real ROI is realized, right? I think it comes as no big surprise if I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=37&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Good design time support for your components may seem like a nice exercise but otherwiese unnecessary and generally not worth the money (especially if it&#8217;s the customers money). After all, design time support plays no role at runtime when the real ROI is realized, right?</p>
<p>I think it comes as no big surprise if I tell you: I don&#8217;t agree. <strong>Design time support elevates quality! </strong>It guides you through complex tasks by wizards (would you type in all the parameters for a complex data source control?), it may provide default settings (effectively speeding up the input), it offers selections of valid values (effectively reducing typos), it validates parametrizations (before inconsistencies cause runtime errors), and last not least it instantly visualizes the information that is important.</p>
<p>Thus, good design time support reduces complexity, speeds up the development process, eliminates bugs. It even steepens the learing curve for new team members. To put it short: <strong>Good design time support saves money! </strong></p>
<p>Well, design time support still needs investment. Granted, Visual Studio already offers a great deal of design time support (the principle holds true for any other IDE as well). Visual designers for windows forms, ASP.NET, XSD, etc., the property grid with its implanted comboboxes and dialogs, various wizards (e.g. the already mentioned wizards to set up data sources), etc.. But there is still room for improvement, most obviously for your own components but for existing ones as well.</p>
<p>The extension points ASP.NET and Visual Studio offer are manyfold:</p>
<ul>
<li>Your derived control could overwrite standard methods (like <em>Render()</em>) and change its behaviour at design time.</li>
<li><em><a target="_blank" href="https://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcomponentmodeltypeconverterclasstopic.asp">TypeConverter</a></em>s can be used to restrict the range of valid property values and to show selection lists or dialogs from the property grid.</li>
<li><a target="_blank" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcomponentmodeldesigncomponentdesignerclasstopic.asp">Designers</a> can be used to plug into the Visual Studio designer infrastructure and change and extend the design time experience of controls in several ways (see <a target="_blank" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/custdsgnrdotnet.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/custdsgnrdotnet.asp</a>).</li>
<li>You can directly access the Visual Studio <a target="_blank" href="http://msdn2.microsoft.com/en-us/library/ms171822.aspx">design time services</a>. </li>
<li>Various interfaces have design time meaning as well as runtime purpose, e.g. <em>ICustomTypeDescriptor</em>, <em>ITypedList</em>, <em>IDataSourceSchema</em>, etc..</li>
<li>You could write your own root designers for whole files (definitelly a more complex task to to).</li>
<li>You could use Domain Specific Language Tools: <a target="_blank" href="http://msdn.microsoft.com/vstudio/DSLTools/">http://msdn.microsoft.com/vstudio/DSLTools/</a>.</li>
<li>You could host designers in your own application (see <a target="_blank" href="http://msdn.microsoft.com/msdnmag/issues/06/03/DesignerHosting/default.aspx">http://msdn.microsoft.com/msdnmag/issues/06/03/DesignerHosting/default.aspx</a>).</li>
</ul>
<p>See, there&#8217;s a multitude of opportunities for improvement. A word of warning, though: the Visual Studio design time infrastructure is quite complex. Unfortunatelly it lacks a bit of documentation in certain areas (this has become better with Visual Studio 2005 but there is still a lot room for improvements &#8211; or perhaps a book of 1000 pages or more, no kidding).</p>
<p><strong>Concrete example:</strong></p>
<p>Since I allways try to mix bits&amp;bytes with higher level assessments and opinions I guess I&#8217;ll have to provide some code, right? OK, let&#8217;s have a look at our old friend the data source. Consider the following page within the Visual Studio designer:</p>
<blockquote><p><img src="http://ajdotnet.files.wordpress.com/2006/08/plain0.png" alt="naive placing of data source controls" /></p></blockquote>
<p>A perfectly valid page &#8211; and yet it&#8217;s totally irrelevant for real world pages. The data source controls are arranged directly beneath the controls bound to them, thus they spoil the HTML design. So once you start using the designer as HTML <em>designer </em>the first thing you will do is to move them out of the way. (You could tell Visual Studio to hide them, yet who would do that?) I placed them at the bottom in a panel control (set to invisible and marked with background color):</p>
<blockquote><p><img src="http://ajdotnet.files.wordpress.com/2006/08/plain1.png" alt="moving data source controls out of the way" /></p></blockquote>
<p>Next: Real world pages occasionally use one or two data controls more than shown here. Say about 12 to 20. (That&#8217;s not exaggerated. Think of a company page in a CRM system with state, country, region, primary contact, assigned sales person, primary address, assigned industry type and subtype, … . And that&#8217;s only the data area.) By the way, that drop down list over there&#8230;, could you please tell me which data source control was again filtered by its selected value? Hey, just click on the data sources, one by one, and have a look at the properties…</p>
<blockquote><p><img src="http://ajdotnet.files.wordpress.com/2006/08/plain1prop.png" alt="propetry dialog for a data source control" /></p></blockquote>
<p>Too bad. The property dialog doesn&#8217;t tell you, just go to the respective dialog. About 12 to 20 times… .</p>
<p>I guess you get the idea. Now close your eyes, lay back and imagine a peacefull world, without environmental pollution, and a dsign time appearance that instantly tells you what you want to know.</p>
<p>Well, mankind being what it is I cannot help with peace and pollution, but here&#8217;s my solution for the page: Derive your own class from the data source control class of your choice and attach a designer class. This designer class will be asked by the Visual Studio designer for a design time HTML representation of the control:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>[Designer(typeof(MySqlDataSourceDesigner))]
public class MySqlDataSource : SqlDataSource
{
    public MySqlDataSource()
    {
    }
}        

public class MySqlDataSourceDesigner : SqlDataSourceDesigner
{
    public override string GetDesignTimeHtml()
    {
        return DesignerHelper.CreateDesignTimeHtml(control);
    }
}</pre>
</td>
</tr>
</table>
<p>Given the right implementation the outcome will satisfy the initial demand:</p>
<blockquote><p><img src="http://ajdotnet.files.wordpress.com/2006/08/enhanced.png" alt="enhanced design time rendering for data source controls" /></p></blockquote>
<p>No magic, all well documented, you just have to do it.</p>
<p>Let&#8217;s get that straight: Nothing has been won by this code in terms of functionality. (Don&#8217;t get carried away with this in front of your customer, he probably won&#8217;t understand the value of something that doesn&#8217;t add functionality.) What has been gained is instant information. I have all the relevant information right bevor my eye and can even highlight special things (as demonstrated with the ID in red). Add warning or error feedback and no parametrization error will stay unnoticed anymore.</p>
<p>OK, that&#8217;s all for… What? … I forgot something? … What source? … Ah, that source. But only on your word that you won&#8217;t hold me accountable for any bugs! Here it is: <font color="#000000"><a target="_blank" href="http://ajdotnet.files.wordpress.com/2006/08/designtimesupport1_zip.txt">DesignTimeSupport1.zip</a> (download and rename to *.zip).</font></p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/08/28/do-you-value-design-time-support/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/08/28/do-you-value-design-time-support/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/37/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/37/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=37&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/08/28/do-you-value-design-time-support/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/08/plain0.png" medium="image">
			<media:title type="html">naive placing of data source controls</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/08/plain1.png" medium="image">
			<media:title type="html">moving data source controls out of the way</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/08/plain1prop.png" medium="image">
			<media:title type="html">propetry dialog for a data source control</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/08/enhanced.png" medium="image">
			<media:title type="html">enhanced design time rendering for data source controls</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/08/28/do-you-value-design-time-support/" medium="image" />
	</item>
		<item>
		<title>Visual Studio Team Edition for Database professionals</title>
		<link>http://ajdotnet.wordpress.com/2006/08/19/visual-studio-team-edition-for-database-professionals/</link>
		<comments>http://ajdotnet.wordpress.com/2006/08/19/visual-studio-team-edition-for-database-professionals/#comments</comments>
		<pubDate>Sat, 19 Aug 2006 15:00:48 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajdotnet.wordpress.com/2006/08/19/visual-studio-team-edition-for-database-professionals/</guid>
		<description><![CDATA[In a post earlier this year Karl complained that database IDEs have not seen the same evolution of new features (like build systems, refactoring, etc.) that developer IDEs (like Visual Studio or Eclipse) enjoyed. This week I was at a Microsoft talk where I was reminded of this post. They showed the current CTP version of the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=36&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In a post earlier this year Karl <a target="_blank" href="http://www.orcasoracle.org/2006/05/29/oh-these-boring-database-ides/">complained</a> that database IDEs have not seen the same evolution of new features (like build systems, refactoring, etc.) that developer IDEs (like Visual Studio or Eclipse) enjoyed.</p>
<p>This week I was at a Microsoft talk where I was reminded of this post. They showed the current CTP version of the newly announced &#8220;<em>Visual Studio Team Edition for Database Professionals</em>&#8220;. See <a target="_blank" href="http://msdn.microsoft.com/vstudio/teamsystem/dbpro/">http://msdn.microsoft.com/vstudio/teamsystem/dbpro/</a> for more information; follow the &#8220;Announcing!&#8221; link and you&#8217;ll get some more details and also some screenshots.</p>
<p>The outstanding features of the VS/DP (my own littele abreviation, since the full name is a little bulky) included:</p>
<ul>
<li>tight intergration with/in VS2005  </li>
<li>integration with other Team System features such as bug tracking and SCM</li>
<li>Reengeneering of existing DBs or SQL scripts</li>
<li>Refactoring for DB objecs (e.g. renaming a table changes references within SPs, etc.)</li>
<li>compare two DB instances (e.g. development vs. production), schema as well as data, and generate update scripts (full or incremental)</li>
<li>automatically generate unit tests for SPs</li>
<li>automatically generate test data (configurable, honoring DB constrains and relationships, even based on a quantitative analysis of a production database)</li>
</ul>
<p>As I said, this is currently a CTP and the final protduct shall be available &#8220;by the end of the year&#8221; (or so the MS consultant said).</p>
<p>The good part is that this will get the database developers &#8220;closer&#8221; to the rest of the team, i.e. more seamlessly intergrated. This is in accordance with the whole Team System approach that already got project management aspects as well as architects and testing on the boat, with web and windows designers jsut around the corner by means of <a target="_blank" href="http://www.microsoft.com/products/expression/en/default.mspx">Expression</a>.</p>
<p>Now comes the upsetting part (especially for you Karl, sorry): VS/DP will support SQL Server 2000 and 2005. Period. No mentioning of other databases either on the web site or from the MS consultant I talked to.</p>
<p>Now, I wouldn&#8217;t expect Microsoft to support Oracle or DB2 out of the box, why should they after all. But for enterprise development those two DBMSs are often the predominant database systems - no sense in arguing about that. Since Microsoft claims to have a very open system with Team System, perhaps the other big players (or some ISV) will come up with similar integration for non-MS databases. </p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/08/19/visual-studio-team-edition-for-database-professionals/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/08/19/visual-studio-team-edition-for-database-professionals/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/36/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/36/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=36&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/08/19/visual-studio-team-edition-for-database-professionals/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/08/19/visual-studio-team-edition-for-database-professionals/" medium="image" />
	</item>
		<item>
		<title>MCPD &#8211; Enterprise Application Developer</title>
		<link>http://ajdotnet.wordpress.com/2006/08/18/mcpd-enterprise-application-developer/</link>
		<comments>http://ajdotnet.wordpress.com/2006/08/18/mcpd-enterprise-application-developer/#comments</comments>
		<pubDate>Fri, 18 Aug 2006 05:26:18 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Software Developers]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/08/18/mcpd-enterprise-application-developer/</guid>
		<description><![CDATA[Note: Read also my update about MCPD/EA 3.5&#8230; I just completed my MCPD &#8211; Enterprise Application Developer. … Oh tanks, that&#8217;s very kind of you… . For those who don&#8217;t know yet: Microsoft has reorganized their certification scheme. There is no more MCAD and MCSD. Those are still valid certifactions, yet they only cover the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=32&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://ajdotnet.files.wordpress.com/2006/08/mcpd.gif?w=328&#038;h=79" alt="MCPD - Enterprise Application Developer (logo)" width="328" height="79" align="right" /></p>
<blockquote><p>Note: Read also my <a href="http://ajdotnet.wordpress.com/2010/06/03/mcpd-enterprise-application-developer-3-5/" target="_blank">update</a> about MCPD/EA 3.5&#8230;</p></blockquote>
<p>I just completed my MCPD &#8211; Enterprise Application Developer. … Oh tanks, that&#8217;s very kind of you… <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<p>For those who don&#8217;t know yet: Microsoft has reorganized their certification scheme. There is no more MCAD and MCSD. Those are still valid certifactions, yet they only cover the world until .NET 1.1. Starting from .NET 2.0 there is three new (higher level) certifications:</p>
<p>Successor to <strong>MCAD</strong>:</p>
<ul>
<li>(Microsoft Certified) Professional Developer: Web Developer (a.k.a. <strong>MCPD - Web Developer</strong>)</li>
<li>(Microsoft Certified) Professional Developer: Windows Developer (a.k.a. <strong>MCPD &#8211; Windows Developer</strong>)</li>
</ul>
<p>Sucessor to <strong>MCSD</strong>:</p>
<ul>
<li>(Microsoft Certified) Professional Developer: Enterprise Applications Developer (a.k.a. <strong>MCPD &#8211; Enterprise Applications Developer</strong>)</li>
</ul>
<p>There&#8217;s also <strong>MCTS</strong> (Microsoft Certified Technology Specialist) certifications (below MCPD), but I&#8217;m not going into details about that or the specific examns for each certification. You can find that under <a href="http://www.microsoft.com/learning/mcp/certifications.asp" target="_blank">http://www.microsoft.com/learning/mcp/certifications.asp</a>. But some broader information may still be usefull:</p>
<p>As you can guess, with the change from .NET 1.1 to .NET 2.0 the workload of the respective examns has increased considerably to cover the new features. But there is also a none-obvious fact that further adds to the workload: The security stuff that has been a separate examn or MCSD (and could even be substituted with a SQL Server or other examn) is now part of the common examns. Ever wondered about the security options for ClickOnce? Or the credentials settings of WSE 3.0 (yes, WSE now is part of the distributed development examn)? Well, you better start reading. On the other hand, MS has factored the common stuff (like language questions or how to query a database) into a seperate examn called <em>Application Development Foundation</em>.</p>
<p>For those already owning the MCSD you don&#8217;t have to start again and take on 5 new examns, rather there is two upgrade examns available. But beware! The workload is notable:</p>
<ul>
<li>Upgrade part1 (<a href="http://www.microsoft.com/learning/exams/70-553.asp" target="_blank">http://www.microsoft.com/learning/exams/70-553.asp</a>): Covers development foundation, windows, and web development (and will earn you the Technology Specialist title for the later two topics).</li>
<li>Upgrade part2 (<a href="http://www.microsoft.com/learning/exams/70-554.asp" target="_blank">http://www.microsoft.com/learning/exams/70-554.asp</a>): Covers distributed development, as well as the &#8220;Designing and Developing&#8221; part (and will earn you the Technology Specialist title for the later topic and finally the MCPD/EAD).</li>
</ul>
<p>What else as MS changed? Well, most obviously the naming of the certifications &#8211; which is something I&#8217;m not very satisfied with: MCAD and MCSD where clearly distinguishable, even for non-IT people (e.g. the manager deciding upon you salary). Now we have MCTS and MCPD. MCTS is less than MCAD and MCPD is a mixture of two tin versions (MCAD successors) and a gold plated version (MCSD successor). Actually, given the increased ground to cover I would even rate the MCPD/EAD higher than the MCSD. Consequently I would have prefered a title that clearly states that this is the top certification. Perhaps I&#8217;m just being vain, but the certification accounts for something &#8211; and it should clearly tell that.</p>
<p><span style="color:#008000;">Thats all for now folks,<br />
<strong>AJ.NET</strong></span><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/08/18/mcpd-enterprise-application-developer/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/08/18/mcpd-enterprise-application-developer/" border="0" alt="" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/32/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/32/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=32&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/08/18/mcpd-enterprise-application-developer/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/08/mcpd.gif" medium="image">
			<media:title type="html">MCPD - Enterprise Application Developer (logo)</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/08/18/mcpd-enterprise-application-developer/" medium="image" />
	</item>
		<item>
		<title>What do your read?</title>
		<link>http://ajdotnet.wordpress.com/2006/08/17/what-do-your-read/</link>
		<comments>http://ajdotnet.wordpress.com/2006/08/17/what-do-your-read/#comments</comments>
		<pubDate>Thu, 17 Aug 2006 05:50:29 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Software Developers]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/08/17/what-do-your-read/</guid>
		<description><![CDATA[The other day I was surprised to learn that two fellows I work with didn&#8217;t know the Microsoft MSDN Magazine. Experienced C#/.NET developers! I was shocked ! One of the most valueable information sources for serious Windows/.NET/WinFX/(any other Microsoft technology) developer and people I hold in high regard don&#8217;t know about it. How could they [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=30&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The other day I was surprised to learn that two fellows I work with<em> didn&#8217;t know the Microsoft MSDN Magazine</em>. Experienced C#/.NET developers! I was shocked <img src='http://s1.wp.com/wp-includes/images/smilies/icon_eek.gif' alt=':shock:' class='wp-smiley' /> ! One of the most valueable information sources for serious Windows/.NET/WinFX/(any other Microsoft technology) developer and people I hold in high regard don&#8217;t know about it. How could they survive? It turned out that one of them at least new the predecessors (System Journal) and accidentially stumbled over the german MSDN Magazin &#8211; which I didn&#8217;t know either. But bad enough, though. They also didn&#8217;t know some of the valuable blogs that are available, so I thought perhaps I should share a list of my &#8220;most valuable information sources&#8221; <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':grin:' class='wp-smiley' />  …Please keep in mind that I keep this list purely .NET related.</p>
<p><strong>English magazines:</strong></p>
<ul>
<li>Highly recommended: &#8220;<strong>msdn magazine</strong>&#8221; is available online <a target="_blank" href="http://msdn.microsoft.com/msdnmag/">http://msdn.microsoft.com/msdnmag/</a> and offline (paperware). This is the medium Microsoft uses to for in-depth articles of current and future technologies. The authors are from the &#8220;Who is Who?&#8221; list in the Microsoft developer community (usually MS employees or people with close MS connections). The online stuff goes back to 1996 so it may even suit IT archeologists <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</li>
</ul>
<p><strong>Blogs:</strong></p>
<ul>
<li><a target="_blank" href="http://blogs.msdn.com/aaron_margosis">http://blogs.msdn.com/aaron_margosis</a>: Aaron talks about LUA (&#8220;Least-privileged User Account&#8221;) and other security stuff</li>
<li><a target="_blank" href="http://blogs.msdn.com/brada">http://blogs.msdn.com/brada</a>: Brad talks about Atlas, WinFX, and .NET (not exactly new stuff but valuable directions and comments); he also gives good PM tips (&#8220;PM&#8221; like project manager…).</li>
<li><a target="_blank" href="http://blogs.msdn.com/cbrumme">http://blogs.msdn.com/cbrumme</a>: Chris knows about CLR internals (GC, AppDomains, etc.). Unfortuantely he got a little lazy lately&#8230; .</li>
<li><a target="_blank" href="http://blogs.msdn.com/ricom">http://blogs.msdn.com/ricom</a>: Ricos blog is named &#8220;Rico Mariani&#8217;s Performance Tidbits&#8221; <em>Der Name ist Programm!</em> as we say in german. He may be THE performance guru at Microsoft.</li>
<li><a target="_blank" href="http://weblogs.asp.net/cazzu">http://weblogs.asp.net/cazzu</a>: Noteable XML with .NET and Ajax, but other stuff as well. Daniel also contributes to the Mvp.Xml project (<a target="_blank" href="http://www.xmlmvp.org/">http://www.xmlmvp.org/</a>).</li>
<li><a target="_blank" href="http://weblogs.asp.net/scottgu">http://weblogs.asp.net/scottgu</a>: All about ASP.NET and adjacent topics (Atlas, LINQ, …). If I had sorted this blog list by relevance rather than alphabetically, this blog would be the first one.</li>
</ul>
<p><strong>German magazines (call it &#8220;regional information&#8221;):</strong></p>
<ul>
<li>The <strong>dotnetpro</strong> <a target="_blank" href="http://www.dotnetpro.de/">http://www.dotnetpro.de/</a> is probably the best german magazine (and not just because I published some articles there <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> , <a target="_blank" href="http://www.dotnetpro.de/articles/author1006.aspx">http://www.dotnetpro.de/articles/author1006.aspx</a>), yet it is only available as subscription, not in stores.</li>
<li>There is a german translation of the <strong>msdn magazine</strong> (<a target="_blank" href="http://msdnmag.de/">http://msdnmag.de/</a>). For some time this was a section within the dot.net magazine but it just became a magazine of its own. I don&#8217;t know yet if this is a full translation or just a selction of articles. (&#8220;Das Abonnement des MSDN Magazin – Deutsche Ausgabe umfasst 6 Ausgaben, die aus 12 Ausgaben der US-Version des MSDN Magazine zusammengestellt sind.&#8221;)</li>
</ul>
<p>There may be other blogs (OK, there <em>are </em>other blogs), but they didn&#8217;t attract me yet. May it be because they didn&#8217;t live up to my expectations, because they adressed the wrong topics, or simply because I overlooked them (shame on me). Anyway, this list is my personal reading list and I hope I could point you to the information source you needed but missed yet. Perhaps you can share your reading tips with me.</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/30/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/30/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=30&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/08/17/what-do-your-read/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Why I like working for SDX</title>
		<link>http://ajdotnet.wordpress.com/2006/08/11/why-i-like-working-for-sdx/</link>
		<comments>http://ajdotnet.wordpress.com/2006/08/11/why-i-like-working-for-sdx/#comments</comments>
		<pubDate>Fri, 11 Aug 2006 16:16:41 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[SDX]]></category>
		<category><![CDATA[Software Developers]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/08/11/why-i-like-working-for-sdx/</guid>
		<description><![CDATA[Time and again I&#8217;m asked why I like working for SDX. The short answer is: &#8220;Working with bright people!&#8221; The longer answer: Working with people that challenge you and that you can challenge &#8211; to accomplish something better. Working with people with whom you can quarrel about one thing and drink a coffee afterwards, joking [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=29&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://ajdotnet.files.wordpress.com/2006/08/sdx.jpg?w=135&#038;h=40" alt="www.sdx-ag.de" width="135" height="40" align="right" />Time and again I&#8217;m asked why I like working for <a href="http://www.sdx-ag.de/" target="_blank">SDX</a>. The short answer is: &#8220;Working with bright people!&#8221;</p>
<p>The longer answer:</p>
<ul>
<li>Working with people that challenge you and that you can challenge &#8211; to accomplish something better.</li>
<li>Working with people with whom you can quarrel about one thing and drink a coffee afterwards, joking about something different.</li>
<li>It&#8217;s the mixture of professionalism, determination, motivation, and fun. The fact that you can rely on your collegues to be honest with you (even if it hurts).</li>
<li>Having the opportunity to work with new technologies, evaluating them, and finally use them. The opportunity to question old ideas and develop new ones. To accomplish something new, to drive progress, for the individual, for the current project, for the customer, and for SDX.</li>
<li>And the fact that all this does not stop with bits and bytes, rather it is a common attitude reaching from dev people to sales to marketing.</li>
</ul>
<p>There is of course the fact that at SDX we work leading edge on SOA and .NET. This may be the thing that makes SDX attractive (for customers as well as for new collegues), yet in my opinion this is just a consequence of the things said before.</p>
<p>PS: I lied in the first sentence. Time and again I&#8217;m asked <em>whether I would like to work for XY</em>. Well, things may change, so keep asking <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>PPS: This post was not sponsored, nor did anyone ask for it <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<p>PPPS: If you like what you just read, if you are from Germany (Rhein-Main-Area), and if you would like to give SDX a try, just visit <a href="http://www.sdx-ag.de/jobs/jobs.htm" target="_blank">http://www.sdx-ag.de/jobs/jobs.htm</a>.</p>
<p>PPPPS: Too bad, I should have thought earlier of sponsorship… <img src='http://s1.wp.com/wp-includes/images/smilies/icon_confused.gif' alt=':?' class='wp-smiley' /> </p>
<p><span style="color:#008000;">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=29&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/08/11/why-i-like-working-for-sdx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://ajdotnet.files.wordpress.com/2006/08/sdx.jpg" medium="image">
			<media:title type="html">www.sdx-ag.de</media:title>
		</media:content>
	</item>
		<item>
		<title>Generics. Boon and Bane&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2006/08/10/generics-boon-and-bane/</link>
		<comments>http://ajdotnet.wordpress.com/2006/08/10/generics-boon-and-bane/#comments</comments>
		<pubDate>Thu, 10 Aug 2006 18:37:30 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/08/10/generics-boon-and-bane/</guid>
		<description><![CDATA[As a developer I like certain things: I like type safety. Type safe access relieves me of &#8220;mind compiling&#8221; and puts the burden on the compiler (where it belongs). It also makes the code cleaner as it makes type casts unnecessary. I like shortcuts. Whenever I have to type the same 3 lines of code [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=26&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As a developer I like certain things:</p>
<ol>
<li><strong>I like type safety.</strong> Type safe access relieves me of &#8220;mind compiling&#8221; and puts the burden on the compiler (where it belongs). It also makes the code cleaner as it makes type casts unnecessary.</li>
<li><strong>I like shortcuts.</strong> Whenever I have to type the same 3 lines of code more than 2 times I&#8217;ll likely <span>come up with </span>a helper method. It&#8217;s easier to use, it documents the intention, it is less error prone, and it offers the opportunity to add additional checks. And after some time I will usually end up with several overloads.</li>
</ol>
<p>Statement #1 led me to use generics. Rather than having code look like this:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>Hashtable ht = new Hashtable();

ht["A"] = "first letter";

ht["Z"] = "last letter";string infoA = (string)ht["A"];

string infoB = (string)ht["B"]; // returns null</pre>
</td>
</tr>
</table>
<p>I can now write that:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>Dictionary&lt;string, string&gt; dict = new Dictionary&lt;string, string&gt;();

dict["A"] = "first letter";

dict["Z"] = "last letter";string infoA = dict["A"];

string infoB = dict["B"]; // ???</pre>
</td>
</tr>
</table>
<p>Well. Then I discovered that the last line no longer returns null, rather it throws a <em>KeyNotFoundException</em>&#8230; <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
<p>Hey, Microsoft isnt&#8217;t shy of this little change in semantics. They even advertise it:<em> &#8220;The following code example uses the Item property (the indexer in C#) to retrieve values, demonstrating that a KeyNotFoundException is thrown when a requested key is not present, and showing that the value associated with a key can be replaced. &#8220;</em> (<a target="_blank" href="http://msdn2.microsoft.com/en-us/library/9tee9ht2.aspx">http://msdn2.microsoft.com/en-us/library/9tee9ht2.aspx</a>)</p>
<p>To overcome this little obstacle, I would have to write something like this:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>string infoC = null;

try

{

    infoC = dict["C"];

}

catch

{

}</pre>
</td>
</tr>
</table>
<p>&#8230; or better this:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>string infoD = null;

dict.TryGetValue("D", out infoD); // return value ignored</pre>
</td>
</tr>
</table>
<p>&#8230; which both violates my initial statement #2. And a helper method for just one generic incarnation simply wouldn&#8217;t do.</p>
<p>But we have generics. And why should the old C++ template tricks not work with generics as well? So I came up with a little generic helper class:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>public class DictAdapter&lt;TKey, TValue&gt;

    where TValue: class

{

    public static TValue GetValue(Dictionary&lt;TKey, TValue&gt; dict, TKey key)

    {

        TValue value = null;

        if (!dict.TryGetValue(key, out value))

            return null;

        return value;

    }</pre>
<pre>Dictionary&lt;TKey, TValue&gt; _dict;</pre>
<pre>public DictAdapter(Dictionary&lt;TKey, TValue&gt; dict)

    {

        _dict = dict;

    }</pre>
<pre>public TValue GetValue(TKey key)

    {

        TValue value = null;

        if (!_dict.TryGetValue(key, out value))

            return null;

        return value;

    }</pre>
<pre>public TValue this[TKey key]

    {

        get { return Value(key); }

    }

}</pre>
</td>
</tr>
</table>
<p>Using this class I can get the dictionary value as before with on static method call, providing the dictionary and the key. If I have more than one of these calls I can create a temporay variable that holds the dictionary reference and simplify subsequent calls. With an object instance I can even leverage an indexer:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>// static call

string infoE = DictAdapter&lt;string, string&gt;.Value(dict, "E");// temp. instance

DictAdapter&lt;string, string&gt; gv = new DictAdapter&lt;string, string&gt;(dict);

string infoF = gv.GetValue("F"); // returns null

string infoZ = gv.GetValue("Z");</pre>
<pre>// indexer call

string infoG = gv["G"];</pre>
</td>
</tr>
</table>
<p>Great, the lazy part of me is satisfied. But there is always the overly critical part in me, the part that cannot be convinced so easily&#8230;</p>
<p><strong>Critical Point of View</strong></p>
<p>Think of it: The strategy works just as it did in C++. And it is likely to produce the same problems.</p>
<p>Look at the last code snippet.</p>
<ul>
<li>Do you understand immediately what every single line does?</li>
<li>If you know that the generic dictionary throws an exception if it does not contain the key, would you instantly guess that <em>DictAdapter</em> does not, thus effectively changing behaviour and semantics?</li>
<li>Would the call to <em>TryGetValue</em> no be more comprehensible, even at the cost of more and ugly code?</li>
</ul>
<p>If you look closely at these questions and validate them against the effects intended with statement #2 (especially be more comprehensible and less error prone) this little class may as well be considered a failure.</p>
<p>Even if these questions would not arise, this little helper may be a problem <span>in and of </span>itself. It has happend with C++ code: When people started to realize the bennefit of these little helpers the result was often a bunch of helper classes, each one ususally written by one developer and never properly advertised, causing another developer to write similar helpers with slighly different behaviour, resulting in code fragments that looked the same but had subtle differences, especially under error conditions, and noone was ever able to maintain this mess properly, until eventually a huge code cleanup effort had to be undertaken, usually resulting in removing all of these classes and sometimes &#8211; but only rarely &#8211; in a clean and usefull set of new helpers, until someone realized the bennefit of these little helpers&#8230;. (take a breath, this was a very long sentence!).</p>
<p>Of course today we know better! Given our experience with C++ we will look for the helper classes that have broad usage scenarios (<strong>so we won&#8217;t see a flood of classes</strong>). We will use generics as type adapters to provide type safe access but otherwise mimic the behaviour of existing classes (<strong>so we will have obvious semantic and clearly defined responsibilities</strong>). We will refrain from unexpectedly hiding or changing semantics (<strong>so the code using the helpers will be self-documenting and in accordance with our expectations</strong>). And we will collect all those classes at the proper namespaces (<strong>so they will become public knowledge and we will instantly recognize overlapping behaviours with other classes in this namespace</strong>).<br />
Additionally Microsoft has wisely decided to ommit some of the more suspect features of templates (e.g. constants as arguments or setting the base class as template argument), <strong>so we won&#8217;t become overly &#8220;inventive&#8221;</strong>.</p>
<p>But beware! It takes some disciplin to avoid the chaos. And since it requires the disciplin of every developer involved, my experience tells me that this is a battle that one is more likely to lose than win. (Hey, all it takes is a bright new right-out-of-the-<a target="_blank" href="http://thedailywtf.com/forums/thread/82911.aspx">university</a>-and-I-know-everything jump start developer, the kind that did not yet validate theoretical academic knowledge against reality and common sense. Huh, he&#8217;s here &#8211; and he also knows of <a target="_blank" href="http://msdn.microsoft.com/netframework/future/linq/">LINQ</a>&#8230; <img src='http://s1.wp.com/wp-includes/images/smilies/icon_eek.gif' alt=':shock:' class='wp-smiley' /> .</p>
<p><font color="#008000">That&#8217;s all for now folks,<br />
<strong>AJ.NET</strong></font><br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/08/10/generics-boon-and-bane/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/08/10/generics-boon-and-bane/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=26&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/08/10/generics-boon-and-bane/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/08/10/generics-boon-and-bane/" medium="image" />
	</item>
		<item>
		<title>What are ObjectDataSources good for?</title>
		<link>http://ajdotnet.wordpress.com/2006/08/03/what-are-objectdatasources-good-for/</link>
		<comments>http://ajdotnet.wordpress.com/2006/08/03/what-are-objectdatasources-good-for/#comments</comments>
		<pubDate>Thu, 03 Aug 2006 10:53:07 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/08/03/what-are-objectdatasources-good-for/</guid>
		<description><![CDATA[DataSources in general and ObjectDataSources in particular are a new feature within ASP.NET 2.0. At first glance ObjectDataSources raise the expectation that this is a means to support layered architectures that feature a cleanly separated business layer (consisting of business services that exchange business data &#8211; either plain class structures or data sets). But this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=24&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>DataSources </em>in general and <em>ObjectDataSource</em>s in particular are a new feature within ASP.NET 2.0.<br />
At first glance <em>ObjectDataSources </em>raise the expectation that this is a means to support layered architectures that feature a cleanly separated business layer (consisting of business services that exchange business data &#8211; either plain class structures or data sets). But this hope dies very fast.<br />
At second glance they appear to support layered architectures that feature data objects (classes that represent the domain specific data model and implement a part of the business interfaces &#8211; all in one package). This hope lives longer before it, too, diminishes.<br />
Finally one has to accept that they support about the same conceptual features that a <em>SqlDataSource </em>with <em>DataSet</em>s supports: A view into the data that works best if it is closely tied to the current page.</p>
<p>Once you have accepted that you can start thinking about what <em>ObjectDataSources</em> actually can do for you &#8211; which is more than this introduction may suggest.</p>
<p>To understand what <em>ObjectDataSource</em>s can and cannot do, let&#8217;s start with understanding <em>SqlDataSource</em>s. On a page you may have a <em>SqlDataSource</em> configured to provide data for your grid view. Thus it would contain a SELECT statement asking for the columns you would like to show and upon databinding of the grid it would issue that statement against the database. Another <em>SqlDataSource</em> an the same page may be configured to select a distinct row, e.g. the one selected within the gridview, to be used by a form view (i.e. providing a master/detail page). This data source would contain a SELECT statement asking for the columns you would like to show/edit (perhaps different columns than in the grid view) and adding a WHERE clause for the id. It also would contain respective UPDATE, INSERT, and DELETE statements. The word &#8220;contain&#8221; in this context means &#8220;buried into the page&#8221;, as in this excerpt:</p>
<p><font color="#0000ff">&lt;<font color="#800000">asp</font><font color="#0000ff">:</font><font color="#800000">SqlDataSource </font><font color="#ff0000">ID</font><font color="#0000ff">=&#8221;SqlDataSource2&#8243; </font><font color="#ff0000">runat</font><font color="#0000ff">=&#8221;server&#8221; </font><font color="#ff0000">ConnectionString</font><font color="#0000ff">=&#8221;&lt;%$ ConnectionStrings:ConnectionString %&gt;</font><font color="#0000ff">&#8220;<br />
</font><font color="#ff0000">        SelectCommand</font><font color="#0000ff">=&#8221;SELECT * FROM [Authors] WHERE ([Id] = @Id)&#8221;<br />
</font><font color="#ff0000">        UpdateCommand</font><font color="#0000ff">=&#8221;UPDATE [Authors] SET [fname] = @fname, [lname] = @lname, [phone] = @phone </font><font color="#0000ff">WHERE [Id] = @Id&#8221;&gt;<br />
</font><font color="#0000ff">    &lt;</font><font color="#800000">SelectParameters</font><font color="#0000ff">&gt;<br />
</font><font color="#0000ff">        &lt;</font><font color="#800000">asp</font><font color="#0000ff">:</font><font color="#800000">ControlParameter </font><font color="#ff0000">ControlID</font><font color="#0000ff">=&#8221;GridView1&#8243; </font><font color="#ff0000">Name</font><font color="#0000ff">=&#8221;Id&#8221; </font><font color="#ff0000">PropertyName</font><font color="#0000ff">=&#8221;SelectedValue&#8221; </font><font color="#ff0000">Type</font><font color="#0000ff">=&#8221;Object&#8221; </font><font color="#0000ff">/&gt;<br />
</font><font color="#0000ff">    &lt;/</font><font color="#800000">SelectParameters</font><font color="#0000ff">&gt;<br />
</font><font color="#0000ff">    &lt;</font><font color="#800000">UpdateParameters</font><font color="#0000ff">&gt;<br />
</font><font color="#0000ff">        &lt;</font><font color="#800000">asp</font><font color="#0000ff">:</font><font color="#800000">Parameter </font><font color="#ff0000">Name</font><font color="#0000ff">=&#8221;fname&#8221; </font><font color="#ff0000">Type</font><font color="#0000ff">=&#8221;String&#8221; </font><font color="#0000ff">/&gt;<br />
</font><font color="#0000ff">        &lt;</font><font color="#800000">asp</font><font color="#0000ff">:</font><font color="#800000">Parameter </font><font color="#ff0000">Name</font><font color="#0000ff">=&#8221;lname&#8221; </font><font color="#ff0000">Type</font><font color="#0000ff">=&#8221;String&#8221; </font><font color="#0000ff">/&gt;<br />
</font><font color="#0000ff">        &lt;</font><font color="#800000">asp</font><font color="#0000ff">:</font><font color="#800000">Parameter </font><font color="#ff0000">Name</font><font color="#0000ff">=&#8221;phone&#8221; </font><font color="#ff0000">Type</font><font color="#0000ff">=&#8221;String&#8221; </font><font color="#0000ff">/&gt;<br />
</font><font color="#0000ff">        &lt;</font><font color="#800000">asp</font><font color="#0000ff">:</font><font color="#800000">Parameter </font><font color="#ff0000">Name</font><font color="#0000ff">=&#8221;Id&#8221; </font><font color="#ff0000">Type</font><font color="#0000ff">=&#8221;Object&#8221; </font><font color="#0000ff">/&gt;<br />
</font><font color="#0000ff">    &lt;/</font><font color="#800000">UpdateParameters</font><font color="#0000ff">&gt;<br />
</font>    [...]<br />
</font><font color="#0000ff">&lt;/<font color="#800000">asp</font><font color="#0000ff">:</font><font color="#800000">SqlDataSource</font><font color="#0000ff">&gt;</font></font></p>
<p>Let&#8217;s make that clear: Every databound control (grid view and form view in our example) has its own private datasource control. This means in particular:</p>
<ol>
<li>The datasource controls are independent of each other, going directly to the database. If one datasource control issues an UPDATE statement the other one will reflect those changes only if its SELECT comes after the UPDATE.</li>
<li>The datasource controls are tailored to the specific needs of the databound control, i.e. giving access to exacly the data that is shown/manipulated. E.g. if a datasource selected/updated a column &#8220;street&#8221;, yet this column is not bound within the form view, it will not be left as is on update, rather it will be overwritten with NULL (best case).</li>
</ol>
<p>And here is the point: <strong>The only relevant difference between <em>SqlDataSource</em>s and <em>ObjectDataSource</em>s is that <em>ObjectDataSource</em>s issue method calls rather than SQL statements.<br />
</strong>Now, this is crucial for the understanding and the implications are both good and bad.</p>
<ul>
<li>For one thing, calling a method means abstraction. Having SQL statements within the pages ties the database structures directly into your UI code. A method can hide some of these details.<br />
 <img src='http://s1.wp.com/wp-includes/images/smilies/icon_arrow.gif' alt=':arrow:' class='wp-smiley' />  <em>ObjectDataSource </em>is good!</li>
<li>C# classes are indivisible. While a SQL statement can explicitely state which columns to access, a class cannot be asked to please contain only a subset (i.e. a partition) of its properties. (Well, not unless we have <a target="_blank" href="http://msdn.microsoft.com/netframework/future/linq/">LINQ</a> support.) Thus we cannot use class instances for <em>insert </em>or <em>update</em> methods if we are only working on a partition of that object. In these cases we will have to provide methods like <em>UpdateMainData(Customer)</em>, <em>UpdateAddress(Customer)</em>, <em>UpdateContactData(Customer)</em>, &#8230; with the name implying the partition of the <em>Customer </em>data type (or conceptually equal methods with single field parameters rather than customer objects). Can you spell &#8220;maintenance&#8221;?<br />
 <img src='http://s1.wp.com/wp-includes/images/smilies/icon_arrow.gif' alt=':arrow:' class='wp-smiley' />  <em>ObjectDataSource </em>has its problems!</li>
<li><em>ObjectDataSources </em>create the configured data object class on demand, each datasource its own data object. Again, those data objects know nothing of each other, no change yet.<br />
 <img src='http://s1.wp.com/wp-includes/images/smilies/icon_arrow.gif' alt=':arrow:' class='wp-smiley' />  <em>ObjectDataSource </em>does not address all problems!</li>
<li>However, there is the possibility to subscribe to certain events and customize the behaviour. One could register for the <em>ObjectCreating</em> event and rather than creating a new data object return a reference to a previously created object. One could also register for the <em>Updating </em>event and implement logic that updates exactly the provided fields.<br />
 <img src='http://s1.wp.com/wp-includes/images/smilies/icon_arrow.gif' alt=':arrow:' class='wp-smiley' />  <em>ObjectDataSource </em>provides better oportunities to address arising problems!</li>
</ul>
<p>For small point&amp;click applications, <em>SqlDataSource </em>may be the way to go. It&#8217;s fast, it is supported by designers and wizards (always good for quality and maintenance), it avoids unnecessary coding overhead, it is pure ASP.NET and therefore the application code has a steep learnig curve. No need to bother with the additional overhead an <em>ObjectDataSource</em> introduces.</p>
<p>For not so small, non-trivial, or enterprise applications, e.g.</p>
<ul>
<li>consisting of many pages,</li>
<li>needing more sophisticated business logic,</li>
<li>having a business logic layer that is (in principle) independent of UI specifics,</li>
<li>having to comply with database access restrictions/policies,</li>
<li>requiring a more sophisticated UI, e.g. maintaining changes in state before they are explicitely saved,</li>
<li>being subject to versioning,</li>
<li>&#8230;</li>
</ul>
<p>&#8230; <em>SqlDataSource </em>is probably <strong>not</strong> the way to go. Rather it is prone to become a development problem and a maintenance nightmare.</p>
<p><em>ObjectDataSource</em> in its plain form may not be the way to go either. Yet it offers the extensibility to roll your own additional logic. The farther you deviate from vanilla web applications, the more work you have to do &#8211; but you can do it.</p>
<p>Ergo: Use the right tool for the job at hand and know how to handle the tool. <em>ObjectDataSource</em> is a good tool if you know when to use it, how to use it, and what not to expect.</p>
<p>That&#8217;s all for now folks,<br />
AJ.NET<br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/08/03/what-are-objectdatasources-good-for/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/08/03/what-are-objectdatasources-good-for/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=24&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/08/03/what-are-objectdatasources-good-for/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/08/03/what-are-objectdatasources-good-for/" medium="image" />
	</item>
		<item>
		<title>Is GetInterface() broken?</title>
		<link>http://ajdotnet.wordpress.com/2006/08/01/is-getinterface-broken/</link>
		<comments>http://ajdotnet.wordpress.com/2006/08/01/is-getinterface-broken/#comments</comments>
		<pubDate>Tue, 01 Aug 2006 16:41:11 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/08/01/is-getinterface-broken/</guid>
		<description><![CDATA[A previous post raised an interesting follow-up question. Suppose you wrote some fairly generic piece of code, like a serialization engine or &#8230; hey, why not an objectmapper? (Back to Gerhard, www.objectmapper.net ) In this case you would not only want to check whether a collection implements, say IList&#60;int&#62;, or IList&#60;Customer&#62;. You would want to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=23&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://ajdotnet.wordpress.com/2006/07/23/typeofarraygetinterfaces-changes-behaviour-in-net-20/">previous post</a> raised an interesting follow-up question. Suppose you wrote some fairly generic piece of code, like a serialization engine or &#8230; hey, why not an objectmapper? (Back to Gerhard, <a href="http://www.objectmapper.net">www.objectmapper.net</a> <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) In this case you would not only want to check whether a collection implements, say <em>IList&lt;int&gt;</em>, or <em>IList&lt;Customer&gt;</em>. You would want to support <em>any </em>kind of collection, therefore you would want to know whether it implements any <em>IList&lt;&gt;</em> derived interface. Right?</p>
<p>So, let&#8217;s do some type checking&#8230;</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>List&lt;int&gt; list = new List&lt;int&gt;(new int[] { 1, 4, 5 });                

bool isListOfInt = (list is List&lt;int&gt;);
bool isListOfT = (list is List&lt;&gt;); // compiler error</pre>
</td>
</tr>
</table>
<p>OK, the classical c# <em>is</em>/<em>as</em> does not work because the compiler refuses to accept the generic version. So we have to roll our own type check using reflection.</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>List&lt;int&gt; list = new List&lt;int&gt;(new int[] { 1, 4, 5 });
Type ilistType = typeof(IList&lt;&gt;); // IList&lt;&gt;
Type listType = list.GetType(); // List&lt;int&gt;                

Type listGenericType = listType.GetGenericTypeDefinition(); // List&lt;&gt;
bool isIListOfT = (listGenericType == ilistType);
    // false: List&lt;&gt; vs. IList&lt;&gt;</pre>
</td>
</tr>
</table>
<p>Note that <em>typeof </em>works fine with the generic <em>IList&lt;&gt; </em>type. But this first approach was a little naive as it compares the wrong generics: The interface generic <em>IList&lt;&gt; </em>and the list implementation generic <em>List&lt;&gt;</em>. Yet we are looking for the interface rather than a &#8220;concrete&#8221; list implementation. So we have to ask for an interface, yet, again, we do not know which interface to ask for, do we?<br />
It turns out that there is a way to ask for a interface that is based on a generic without actually telling what the generic type parameters are: It&#8217;s documented in a note in <em>Type.GetInterface(string)</em> (see <a href="http://msdn2.microsoft.com/en-us/library/ayfa0fcd.aspx">http://msdn2.microsoft.com/en-us/library/ayfa0fcd.aspx</a>) and it works by passing the name of the generic and the number of type parameters:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>List&lt;int&gt; list = new List&lt;int&gt;(new int[] { 1, 4, 5 });
Type ilistType = typeof(IList&lt;&gt;); // IList&lt;&gt;
Type listType = list.GetType(); // List&lt;int&gt;                

Type ilistOfX = listType.GetInterface("IList`1"); // IList&lt;int&gt;
Type ilistGenericType = ilistOfX.GetGenericTypeDefinition(); // IList&lt;&gt;
bool isIListOfT2 = (ilistGenericType == ilistType);
    // true: IList&lt;&gt; vs. IList&lt;&gt;</pre>
</td>
</tr>
</table>
<p>Finally we&#8217;re there. Wait&#8230; . The generic name. And the number of parameters&#8230;. . What if some genius wrote a class that implemented two incarnations of that generic interface&#8230;? Let&#8217;s see.</p>
<p>Just for the curious, academic pea counters, we&#8217;ll start with simply deriving the list class and see what happens to the code above:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>public class MyList : List&lt;int&gt;
{
    public MyList(int[] args)
        : base(args)
    {
    }
}                

MyList list = new MyList(new int[] { 1, 4, 5 });
Type ilistType = typeof(IList&lt;&gt;); // IList&lt;&gt;                

Type listType = list.GetType();     // MyList
Type listGenericType = listType.GetGenericTypeDefinition();
    // System.Exception {System.InvalidOperationException:
    // "Operation is not valid due to the current state of the object."</pre>
</td>
</tr>
</table>
<p>I know, this is based on the first snippet that didn&#8217;t work in the first place, so why should it now. But isn&#8217;t it peculiar how some innocent change causes quite a different error? Raising an exception rather than simply returning the wrong result?<br />
Anyway, back to the working stuff: To make a long story short the variation above still works (code ommited). Now let&#8217;s change the class definition again:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>public class MyList : List&lt;int&gt;, IList&lt;double&gt;
{
    public MyList(int[] args)
        : base(args)
    {
    }                

[...] // implementations omitted
}                

MyList list = new MyList(new int[] { 1, 4, 5 });
Type ilistType = typeof(IList&lt;&gt;); // IList&lt;&gt;                

Type listType = list.GetType(); // MyList
Type ilistOfX = listType.GetInterface("IList`1");
    // System.Reflection.AmbiguousMatchException</pre>
</td>
</tr>
</table>
<p>And you thought, we were done. Ts ts ts&#8230;</p>
<p>Since there is no <em>GetInterfaces() </em>method that takes a <em>string </em>as filter we&#8217;ll have to do everything by hand. Get all interfaces, loop, get generic, check&#8230; :</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>MyList list = new MyList(new int[] { 1, 4, 5 });
Type ilistType = typeof(IList&lt;&gt;); // IList                

Type listType = list.GetType();     // MyList
Type[] interfaces = listType.GetInterfaces();
bool isIListOfT = false;
Type genericType;
foreach (Type type in interfaces)
{
    if (!type.IsGenericType)
        continue;
    genericType = type.GetGenericTypeDefinition();
    if (genericType != ilistType)
        continue;
    isIListOfT = true;
    break;
}</pre>
</td>
</tr>
</table>
<p>Finally there. Welcome back, Mr. GetInterfaces, I saw you in a <a href="http://ajdotnet.wordpress.com/2006/07/23/typeofarraygetinterfaces-changes-behaviour-in-net-20/">previous post</a>, didn&#8217;t I? I know a relative of you, one Mr. GetInterface. He&#8217;s a little dangerous, don&#8217;t you think? I thought we could get along quite easily &#8211; but all of a sudden he attacked me from behind and bit me in the back. What do you mean, you knew that would happen? What muzzle? &#8230; Yes, usually he behaved quite good&#8230; Bad childhood? &#8230; no, I didn&#8217;t feed him &#8230;.</p>
<p>That&#8217;s all for now folks,<br />
AJ.NET<br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/08/01/is-getinterface-broken/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/08/01/is-getinterface-broken/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=23&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/08/01/is-getinterface-broken/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/08/01/is-getinterface-broken/" medium="image" />
	</item>
		<item>
		<title>Anatomy of a bug&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2006/07/28/anatomie-of-a-bug/</link>
		<comments>http://ajdotnet.wordpress.com/2006/07/28/anatomie-of-a-bug/#comments</comments>
		<pubDate>Fri, 28 Jul 2006 15:31:13 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/07/28/anatomie-of-a-bug/</guid>
		<description><![CDATA[I should probably write that post as long as the blame is fresh and still hurts… The Problem: We encounterd problems with our ASP.NET 1.1 application under load conditions (of course this happened in production… 8O). The application became &#8220;less stable&#8221; than it used to be. Using a load test tool we could easily reproduce [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=17&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I should probably write that post as long as the blame is fresh and still hurts… <img src='http://s1.wp.com/wp-includes/images/smilies/icon_redface.gif' alt=':oops:' class='wp-smiley' /> </p>
<p><strong>The Problem:<br />
</strong>We encounterd problems with our ASP.NET 1.1 application under load conditions (of course this happened in production… 8O). The application became &#8220;less stable&#8221; than it used to be. Using a load test tool we could easily reproduce the problems in our development environment. One simulated user works fine. Two users fine as well. 10 concurrent users and we encountered the firts problems, 50 and we had pages with 25% to 35% error rate.<br />
Note that we had load tested our application before, albeit only the major release before the current one. Unfortunately we had done quite some changes, so it was reasonable to asume that one of those changes was the root cause, and yet, the problem might have been there before (as it related to timing issues) and just didn&#8217;t manifest itself. But let&#8217;s look at some details first.</p>
<p><strong>The Situation:<br />
</strong>We user pages that contained user controls (employing our own template mechanism) which in turn contained components (<em>System.ComponentModel.Component</em>). These components provided the data to be shown at the page and they had to be initialized. In <em>Page.OnInit</em> we called the base class method (which should initialize the user controls and create the components) and afterwards our component initialization. Some snippets:</p>
<p>Code in <em>SomeUserControl</em>:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>private void InitializeComponent()
{
    this.components = new System.ComponentModel.Container();
    this.MyDataComponent = new DataComponent(this.components);
    this.MyDataComponent.Name = "MyDataComponent";
}</pre>
</td>
</tr>
</table>
<p>Code in our page class:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>protected override void OnInit(EventArgs e)
{
    base.OnInit (e);
    Controller.OnPageInit();
    // the controller calls ComponentManager.InitComponents()...
}</pre>
</td>
</tr>
</table>
<p>With one single user (i.e. thread) active at a time it worked smoothly. When we debugged the application under load test conditions some arkward exceptions occured that gave us the impression that the user controls were initializes asynchonoulsy.</p>
<p>1. the components beeing created in <em>InitializeComponent()  </em>were <em>null</em>. If we stopped in the debugger and set the instruction pointer back a few lines (or wrote a loop that just slept a few msec and tried to access the component until it actually got hold of it), the component would eventually appear.</p>
<p>Code in our page class:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>public ArrayList GetComponents()
{
    if (_components==null)
    {
        bool ret= FindComponents();
        int loopCount= 1;
        while(ret==false)
        {
            System.Threading.Thread.Sleep(10);
            ++loopCount;
            ret= FindComponents();
            if (loopCount&gt;100) // 10*100 = 1 sec.
                break;
        }
        else if (loopCount&gt;1)
            Trace.WriteLine(
                "Page needed several attempts to get components: "
                + loopCount);
    }
    return _components;
}</pre>
</td>
</tr>
</table>
<p>Usually we had 2, 3, 4, 5, 6 loops at most.</p>
<p>2. (different error condition after some changes): The <em>Name </em>property of the component (being set in <em>InitializeComponent()</em> ) is accessed during initialization. We checked the property in code and it had the default value (<em>&#8220;&lt;undefined&gt;&#8221;</em>). We stopped within the debugger and the value was correct.</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>string name= component.Name.ToLower();
if (name=="&lt;undefined&gt;")
    throw new Exception("&lt;undefined&gt;");
    // breakpoint on throw =&gt; debugger show correct name.</pre>
</td>
</tr>
</table>
<p>Ergo: The page/user control is obviously being initialized asynchronously, ASP.NET on the other hand guarantees that a page is processed by exactly one thread. We didn&#8217;t start any threads, so we had a contradiction. This obviously had to be a bug within the ASP.NET runtime…. . How likely could that be? Right. The probability would be close to 0. (If you don&#8217;t agree you may want to have a look at <a target="_blank" href="http://weblogs.asp.net/scottgu/archive/2004/10/28/249458.aspx">Testing ASP.NET 2.0 and Visual Web Developer</a>.)</p>
<p><strong>The Search<br />
</strong>We finally decided to strip down the project to isolate the root cause of our problem. To accomplish that we had quite some work to do. Our applications consists of a substantial number of pages, user controls, components, business interfaces, business objects, etc., and additionaly some sophisticated core funtionalities… . Eventually our application was down to one page with one user control and the bug still reproducable. Next in line was getting rid of the various libraries that we used. Bang! Spring.NET! (The factory framework we used: <a href="http://www.springframework.net/">http://www.springframework.net/</a>.)</p>
<p>Spring.NET? The call chain looked like <em>Page &#8211;&gt; Controller &#8211;&gt; ComponentManager</em>, with the component manager iterating over the components on the page. And the component manager was created using Spring.NET. And some further research revealed that there have been multi threading issues with Spring.NET, see <a href="http://forum.springframework.net/showthread.php?t=423&amp;highlight=thread">here</a> for example. So we had a bug in Spring.NET. Just a quick look at the documentation… yes, looks good…. yes…. err… you&#8217;re kidding, aren&#8217;t you…. Ahhrrggghhhh!<br />
Some time later (about 2 hours) we had recovered&#8230; <img src='http://s2.wp.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> </p>
<p><strong>The Cause<br />
</strong>Spring.NET uses a configuartion file in which the classes are registered for instantiation. One can also specify that a class shall only be instantiated once (i.e. as singletons), effectively returning the same object for each subsequent request. And - Heads up! - the default is <em>singleton=&#8221;<strong>true</strong>&#8220;</em>… . Nobody in our team would have guessed that.</p>
<p>The consequence was that all pages used the same component manager which used its back reference to the page (that was changed constantly) to process the components. This not only explained the exceptions, it also may have supplied the pages with data of another page of another user.</p>
<p>A simple addition of <em>singleton=&#8221;false&#8221;</em> in that config file solved our problem.</p>
<p><strong>The Conclusion<br />
</strong>So, what do we learn from all this?</p>
<p>1. <strong>Load test your application! </strong>You never know what your application will do under stress.<br />
2. Take this as a rule: The bug is not within the .NET Framework or one of the (widely used) libraries (or JRE if you happen to be from the other camp). <strong>The bug is in <em>your </em>code!</strong><br />
3. <strong>RTFM!</strong> Explicitely specify configuration values and don&#8217;t rely on default values &#8211; especially with libraries you use. What a feasible &#8220;default&#8221; is depends on subjective opinions and those can vary from developer to developer… (q.e.d.)</p>
<p>There&#8217;s also some positive experience (not for the first time): Any problem &#8211; no matter how intricate it appears to be &#8211; can be tracked down eventually &#8211; given enough time and the right people.</p>
<p>That all for now folks,<br />
AJ.NET</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=17&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/07/28/anatomie-of-a-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>typeof(Array).GetInterfaces() changes behaviour in .NET 2.0</title>
		<link>http://ajdotnet.wordpress.com/2006/07/23/typeofarraygetinterfaces-changes-behaviour-in-net-20/</link>
		<comments>http://ajdotnet.wordpress.com/2006/07/23/typeofarraygetinterfaces-changes-behaviour-in-net-20/#comments</comments>
		<pubDate>Sun, 23 Jul 2006 10:47:19 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/07/23/typeofarraygetinterfaces-changes-behaviour-in-net-20/</guid>
		<description><![CDATA[When we migrated an existing project from .NET 1.1 to .NET 2.0 Gerhard (who owns http://www.objectmapper.net/) noted that his mapper suddenly had problems. The cause was an interesting change in the CLR/CTS: Suppose you were using the interfaces an array exposes like that: int[] arrayOfInt = new int[]{1,4,5}; Type[] interfaces = arrayOfInt.GetType().GetInterfaces(); int i = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=16&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When we migrated an existing project from .NET 1.1 to .NET 2.0 Gerhard (who owns <a href="http://www.objectmapper.net/">http://www.objectmapper.net/</a>) noted that his mapper suddenly had problems. The cause was an interesting change in the CLR/CTS:</p>
<p>Suppose you were using the interfaces an array exposes like that:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>int[]  arrayOfInt = new int[]{1,4,5};

Type[] interfaces = arrayOfInt.GetType().GetInterfaces();

int    i          = interfaces.Length;  // number of supported interfacesobject o          = arrayOfInt;

int    b          = 0;  // counter for implemented interfaces

if (o is ICollection)

    ++b;

if (o is IList)

    ++b;

if (o is IEnumerable)

    ++b;</pre>
</td>
</tr>
</table>
<p>In .NET 1.1 the resulting value of <em>i </em>was 0. No interfaces supported by arrays, sorry. No, wait! <em>b</em> was 3! So it supports interfaces, but it doesn&#8217;t tell!</p>
<p>One may be inclined to call this a bug&#8230;. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Anyway, run the same code in .NET 2.0 and the result of <em>i</em> is 7. The interfaces returned are:</p>
<ul>
<li>{Name = &#8220;<strong>ICloneable</strong>&#8221; FullName = &#8220;System.ICloneable&#8221;}</li>
<li>{Name = &#8220;<strong>IList</strong>&#8221; FullName = &#8220;System.Collections.IList&#8221;}</li>
<li>{Name = &#8220;<strong>ICollection</strong>&#8221; FullName = &#8220;System.Collections.ICollection&#8221;}</li>
<li>{Name = &#8220;<strong>IEnumerable</strong>&#8221; FullName = &#8220;System.Collections.IEnumerable&#8221;}</li>
<li>{Name = &#8220;<strong>IList`1</strong>&#8221; FullName = &#8220;System.Collections.Generic.IList`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]&#8221;}</li>
<li>{Name = &#8220;<strong>ICollection`1</strong>&#8221; FullName = &#8220;System.Collections.Generic.ICollection`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]&#8221;}</li>
<li>{Name = &#8220;<strong>IEnumerable`1</strong>&#8221; FullName = &#8220;System.Collections.Generic.IEnumerable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]&#8221;} </li>
</ul>
<p>Noteworthy that it implements the old non-generic collection interfaces as well as the new generic ones.</p>
<p>That&#8217;s all for now folks,<br />
AJ.NET<br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/07/23/typeofarraygetinterfaces-changes-behaviour-in-net-20/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/07/23/typeofarraygetinterfaces-changes-behaviour-in-net-20/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=16&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/07/23/typeofarraygetinterfaces-changes-behaviour-in-net-20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/07/23/typeofarraygetinterfaces-changes-behaviour-in-net-20/" medium="image" />
	</item>
		<item>
		<title>Is memory shuffling the culprit?</title>
		<link>http://ajdotnet.wordpress.com/2006/07/19/is-memory-shuffling-the-culprit/</link>
		<comments>http://ajdotnet.wordpress.com/2006/07/19/is-memory-shuffling-the-culprit/#comments</comments>
		<pubDate>Wed, 19 Jul 2006 18:34:59 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/07/19/is-memory-shuffling-the-culprit/</guid>
		<description><![CDATA[In one project we encountered a performance problem with storing files in an Oracle database (and this post is in essence not relateded to Oracle or databases in general): It took around ~45 sec (2MB file) and ~100 sec (4MB file) to store the files as Blobs. The files were read into on big byte array and handed [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=15&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In one project we encountered a performance problem with storing files in an Oracle database (and this post is in essence <em>not </em>relateded to Oracle or databases in general): It took around ~45 sec (2MB file) and ~100 sec (4MB file) to store the files as Blobs. The files were read into on big byte array and handed over to ADO.NET. Naively thinking, even if this occupied the whole machine (i.e. scalability goodbye), in terms of performance this should probably be burstmode-fast. Obviously this was not the case and it turned out that the problem was caused somewhere in the ADO.NET data provider for Oracle. </p>
<p>Between Gerhard (with his object mapper) and Carl (being the Oracle specialist), I (being somewhat experienced with .NET) was involved in tracking the problem down.</p>
<p>My wild guess was that the data provider is just a layer above the oracle client lib (C-Lib), in which case it would move a memory block of 2 or 4 MB respectively via P/Invoke. This would include special GC handling (large object heap), pinning, marshaling, memcopy, physical memory allocations, page faults, etc.. From this assumption I deduced that quite a few of the possible issues would vanish if we moved several small memory blocks, say 4kB, instead. In other words a streaming or a chunking approach might help.</p>
<p>It was just a guess, yet Gerhard proved that it actually <em>did</em> solve the problem. If you are interested in the Oracle specifics I recommend reading <a target="_blank" href="http://jachman.wordpress.com/2006/04/26/slow-oracle-blob-upload-with-c-net-or-how-to-fasten-it/" title="Gerhards post">Gerhards post</a>&#8230; .</p>
<p>There&#8217;s actually two lessons to learn:</p>
<ol>
<li>P/Invoke and marshaling of large amounts of memory can be quite costly in terms of performance. Streaming/chunking ist much more efficient (and in case of server side applictions much more scaleable).</li>
<li>As anyone with some knowledge about logical reasing knows: <em>A false statement may lead to a correct conclusion</em>. So I cannot be sure about statement #1. It may be the false presumption that actually led to a working solution.</li>
</ol>
<p>Well, right now I&#8217;ll have to live with that unsatisfying situation. &#8220;Hier seh&#8217; ich nun, ich armer Tor, und bin so klug als wie zuvor&#8230;&#8221; (German saying, not translatable&#8230;)</p>
<p>Thats all for now folks,<br />
AJ.NET</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=15&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/07/19/is-memory-shuffling-the-culprit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET 2.0 DataBinding Examined</title>
		<link>http://ajdotnet.wordpress.com/2006/07/17/aspnet-20-databinding-examined/</link>
		<comments>http://ajdotnet.wordpress.com/2006/07/17/aspnet-20-databinding-examined/#comments</comments>
		<pubDate>Mon, 17 Jul 2006 19:54:19 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/07/17/aspnet-20-databinding-examined/</guid>
		<description><![CDATA[The databinding in ASP.NET is something I have been working on earlier (see http://www.alexander-jung.net/artikel/databinding/default.htm, partly available in english). So it was quite logical to check out the new ASP.NET 2.0 features. Databindung falls in two categories: Simple binding and complex binding. I&#8217;ll talk only about simple binding in this post, that&#8217;s more than enough ground [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=14&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The databinding in ASP.NET is something I have been working on earlier (see <a href="http://www.alexander-jung.net/artikel/databinding/default.htm">http://www.alexander-jung.net/artikel/databinding/default.htm</a>, partly available in english). So it was quite logical to check out the new ASP.NET 2.0 features.</p>
<p>Databindung falls in two categories: Simple binding and complex binding. I&#8217;ll talk only about simple binding in this post, that&#8217;s more than enough ground to cover anyway. Perhaps complex binding and datasources will be covered later (if I&#8217;ve got somethinig worthwile to say).</p>
<p>First the facts, then the assessment. Let&#8217;s start with ASP.NET 1.x to be able to see the differences&#8230;</p>
<p><strong>Simple binding </strong>is used to bind properties to data. This could be the text property of a label, the title property of an image, or any other simple property of any other server control. If you set the property of a control with ASP.NET 1.x and Visual Studio .NET 2003 the designer would generate code fragements like this:</p>
<p>Single control and within datagrid:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>&lt;asp:TextBox id=TextBox2 runat="server"

    Text='&lt;%# DataBinder.Eval(timer1, "Interval") %&gt;'/&gt;&lt;asp:TextBox id=TextBox3 runat="server"

    Text='&lt;%# DataBinder.Eval(Container, "DataItem.Name") %&gt;'/&gt;</pre>
</td>
</tr>
</table>
<p>The first argument to <em>DataBinder.Eval</em> is a component (in this case a timer which makes close to no sense in a web application…) or in case the control is contained in a list control (grid, repeater, …) it may be <em>Container</em> to denote the current row. Behind the scenes the ASP.NET runtime would generate code like this (stripped down for brevity):</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>private Control __BuildControl__control7()

{

    TextBox __ctrl;

    __ctrl = new TextBox();

    this.__control7 = __ctrl;

    __ctrl.ID = "TextBox3";

    __ctrl.DataBinding += new EventHandler(this.__DataBind__control7);

    return __ctrl;

}public void __DataBind__control7(object sender, EventArgs e)

{

    DataGridItem Container;

    TextBox target;

    target = ((TextBox)(sender));

    Container = ((DataGridItem)(target.BindingContainer));

    target.Text = Convert.ToString(DataBinder.Eval(Container, "DataItem.LegalName"));

}</pre>
</td>
</tr>
</table>
<p>As you can see, it&#8217;s all based on code generation and it only works one way. To get the data out of the textbox you need to roll up the sleves and prepare for some work.</p>
<p>Now let&#8217;s look at ASP.NET 2.0 with Visual Studio 2005:</p>
<p>With simple binding, one can no longer choose the artificial property &#8220;(DataBindings)&#8221; (there is a new one, named &#8220;(Expressions)&#8221;, but that&#8217;s not directly related to databinding in the sense we&#8217;re just covering). Rather one has to use the smart tag (the small little triangle at the upper right corner) &#8220;Edit DataBindings…&#8221;. This smart tag however is only available for controls that are contained in a <em>DataBoundControl</em>. For controls contained in list controls this is the case and therefore no difference. For single controls though one needs a new parent control, <em>FormView</em> in this case.<br />
Apart from this the output of the designer looks quite similar:</p>
<p>within formview:<br />
<font size="2" color="#0000ff">&lt;</font><font size="2" color="#800000">asp</font><font size="2" color="#0000ff">:</font><font size="2" color="#800000">TextBox</font><font size="2"> </font><font size="2" color="#ff0000">ID</font><font size="2" color="#0000ff">=&#8221;TextBox2&#8243;</font><font size="2"> </font><font size="2" color="#ff0000">runat</font><font size="2" color="#0000ff">=&#8221;server&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">Text</font><font size="2" color="#0000ff">=&#8217;</font><font size="2">&lt;%# Bind(&#8220;id&#8221;) %&gt;</font><font size="2" color="#0000ff">&#8216;</font><font size="2"> </font><font size="2" color="#ff0000">Enabled</font><font size="2" color="#0000ff">=&#8221;False&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">ReadOnly</font><font size="2" color="#0000ff">=&#8221;True&#8221;/&gt;<br />
</font>within gridview:<br />
<font size="2" color="#0000ff">&lt;</font><font size="2" color="#800000">asp</font><font size="2" color="#0000ff">:</font><font size="2" color="#800000">TextBox</font><font size="2"> </font><font size="2" color="#ff0000">ID</font><font size="2" color="#0000ff">=&#8221;TextBox3&#8243;</font><font size="2"> </font><font size="2" color="#ff0000">runat</font><font size="2" color="#0000ff">=&#8221;server&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">Text</font><font size="2" color="#0000ff">=&#8217;</font><font size="2">&lt;%# Bind(&#8220;name&#8221;) %&gt;</font><font size="2" color="#0000ff">&#8216;</font><font size="2"> </font><font size="2" color="#0000ff">/&gt; </font></p>
<p>There are some noteable differences: First (and of no consequence at all) is the shortened syntax. Second, there is two flavours: <em>Eval</em> and <em>Bind</em>. <em>Eval</em> is the same one way databinding as in 1.x, <em>Bind</em> supports two way databinding. The third difference is the setting of the enabled and readonly properties. This is due to the fact that formviews supports different templates (just like the grid). Now let&#8217;s look at the generated code:</p>
<table border="1" bgColor="#ffffcc" width="100%">
<tr>
<td>
<pre>private global::TextBox @__BuildControl__control13() {

    global::TextBox @__ctrl;

    @__ctrl = new global::TextBox();

    @__ctrl.TemplateControl = this;

    @__ctrl.ApplyStyleSheetSkin(this);

    @__ctrl.ID = "TextBox2";

    @__ctrl.Enabled = false;

    @__ctrl.ReadOnly = true;

    @__ctrl.DataBinding += new EventHandler(this.@__DataBinding__control13);

    return @__ctrl;

}public void @__DataBinding__control13(object sender, EventArgs e) {

    TextBox dataBindingExpressionBuilderTarget;

    FormView Container;

    dataBindingExpressionBuilderTarget = ((TextBox)(sender));

    Container = ((FormView)(dataBindingExpressionBuilderTarget.BindingContainer));

    if ((this.Page.GetDataItem() != null)) {

        dataBindingExpressionBuilderTarget.Text = Convert.ToString(this.Eval("id"),

            Globalization.CultureInfo.CurrentCulture);

    }

}

public IOrderedDictionary @__ExtractValues__control12(Control @__container) {

    OrderedDictionary @__table;

    TextBox TextBox2;

    TextBox2 = ((TextBox)(@__container.FindControl("TextBox2")));

    […] // other controls ommited

@__table = new OrderedDictionary();

    if ((TextBox2 != null)) {

        @__table["id"] = TextBox2.Text;

    }

    […] // other values ommited

    return @__table;

}</pre>
</td>
</tr>
</table>
<p>Now, the <em>Eval</em> part works essentially the same way it did in 1.x, registering a <em>DataBinding</em> event handler on the textbox and setting the value. Vice versa we have one method for the formview control that takes the values of all bound child controls and puts them into a dictionary. Again it&#8217;s fully based on code generation.</p>
<p><strong>Assessment:</strong></p>
<p>Now let&#8217;s see whether the new databinding lives up to the expectations. Well, there&#8217;s good news and bad news&#8230;</p>
<p><strong>The good part: </strong>Imagine a web site structured like a &#8220;classical web site&#8221; (i.e. one containing lists, simple input forms, etc.). With ASP.NET 2.0 one can implement that without leaving the designer (provided the data is readily available). It&#8217;s actually quite amazing how far you can get without having to type code. And due to the code generation approach it&#8217;s fast and efficient and any faults will show up during compile time. If you ask me, that&#8217;s better than ever.</p>
<p><strong>The bad part: </strong>Imagine a web site that is different in one or the other respect. It may have a UI that&#8217;s structured like a windows form with several user controls, each providing their own formview, yet they should work in unison. It may be that you shy away of the maintenance effort for several templates per formview and would prefer a meta data driven frontend. This could be controls that can render themselfs readonly rather than having to maintain two different templates. Or the data structures you use provide enough meta information to create validators dynamically.<br />
Now you&#8217;re struck. You simply don&#8217;t have the informations you need. The textbox never knows which field it is bound to, so how do you retrive the meta data you need? The formview behaves at if it where the only one working exclusively on one whole row/entity, so how do you synchronize multiple formviews, each working on a partition of an entity?<br />
The answer is: You can&#8217;t. Full stop.<br />
The consequence: Forget your good ideas &#8211; or roll your own databinding.</p>
<p><strong>Has Microsoft delivered something good?<br />
</strong>In terms of functionality I think they have done quite a good job, they could hardly have delivered more.</p>
<p><strong>Could Microsoft have done better?<br />
</strong>In terms of design and how to surface the features to the developer they don&#8217;t live up to my expectations. In fact I wouldn&#8217;t call the databinding mechanism a framework feature because it lacks framework quality, in this case extensibility points. This is even more annoying since I know the can do better. MFC used code generation (read preprocessor macros) and yet was extensible; ATL used templates and yet was extensible. Other areas in ASP.NET use interfaces, methods, provider patterns &#8211; all valid extension points. I <em>know </em>they could have done better.</p>
<p>That&#8217;s all for now folks,<br />
AJ.NET<br />
<a href="http://www.dotnetkicks.com/kick/?url=http://ajdotnet.wordpress.com/2006/07/17/aspnet-20-databinding-examined/"><img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/07/17/aspnet-20-databinding-examined/" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=14&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/07/17/aspnet-20-databinding-examined/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://ajdotnet.wordpress.com/2006/07/17/aspnet-20-databinding-examined/" medium="image" />
	</item>
		<item>
		<title>SOA Starting Point</title>
		<link>http://ajdotnet.wordpress.com/2006/07/17/soa-starting-point/</link>
		<comments>http://ajdotnet.wordpress.com/2006/07/17/soa-starting-point/#comments</comments>
		<pubDate>Mon, 17 Jul 2006 19:25:12 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[SOA]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/07/17/soa-starting-point/</guid>
		<description><![CDATA[As SOA (along with Web Services) is one of my favourite topics, I think it prudent to define a starting point with my first post. (Actually this is not exacly my first &#8220;post&#8221;, since I used to have some of the following information on my web site, yet I cleaned that part just recently.) I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=13&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As SOA (along with Web Services) is one of my favourite topics, I think it prudent to define a starting point with my first post. (Actually this is not exacly my first &#8220;post&#8221;, since I used to have some of the following information on my web site, yet I cleaned that part just recently.) I should point out that this post refers to conceptual things rather than implementation or other topics.</p>
<p>Now, the usual starting point would be to come up with a definition. Another one. Adding to the not so tiny number of already existing definitions&#8230; . No way!  If you need a definition I recommend Reger Sessions ObjectWatch Newsletter #45: <strong>&#8220;What is a Service-Oriented Architecture (SOA)?&#8221;</strong> (October 7, 2003, <a href="http://www.objectwatch.com/newsletters/issue_45.htm">http://www.objectwatch.com/newsletters/issue_45.htm</a>), which also does away with some misconceptions.</p>
<p>Anyway, the starting point for me lies a little earlier than the term &#8220;SOA&#8221;. It&#8217;s got to do with the &#8220;S&#8221; in SOA: Pat Hellands work on <strong>&#8220;Autonomous computing: Fiefdoms and Emissaries&#8221;</strong> (2002, Microsoft Webcast, <a href="http://microsoft.com/usa/Webcasts/ondemand/892.asp">http://microsoft.com/usa/Webcasts/ondemand/892.asp</a> &#8212; and I could not find it, the link is broken. I know that there are also PPTs from Pat about this topic, yet I couldn&#8217;t find any of them publicly available either. If anyone knows some links, please tell me!)<br />
The value of this work lies in doing away with classic (read clients/server like) patterns of data exchange.</p>
<p>Also dating earlier than the term &#8220;SOA&#8221; is another issue of Rogers newsletters: <strong>&#8220;The Software Fortress Model: A Next Generation Model for Describing Enterprise Software Architectures&#8221;</strong> (#36, 17.11.2001, <a href="http://www.objectwatch.com/newsletters/issue_36.htm">http://www.objectwatch.com/newsletters/issue_36.htm</a>). OK, I know, the link is also broken. But I sent Roger an email asking when/whether it will work again and he has also written a book about that topic [UPDATE]It took but a weekend and #36 was online again <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> . Thanks, Roger! [END UPDATE].<br />
The reason I think this a valuable work is that it defined the landscape of systems/services at the advent of SOA. Many of the issues with implementing a SOA can be understood better with the SFM in mind.</p>
<p>What a starting point. Based on information I cannot deliver <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> … . But it gets better.</p>
<p>Again it was Pat Helland who brought up <strong>Metropolis, &#8220;A metaphor for the evolution of information technology into the world of service-oriented architectures.&#8221; </strong>(04/2004, <a href="http://www.architecturejournal.net/2004/issue2/aj2metrop.aspx">http://www.architecturejournal.net/2004/issue2/aj2metrop.aspx</a>, there was more information on his personal web site, yet since he kind of went out of business, his site is down. What a pity.)<br />
Speaking of evolution, I see Metropolis as the evolution of Rogers SFM in a SOA world where the various services work together and become a living, almost kind of social, interacting eco system.</p>
<p>And back to Roger (it&#8217;s like ping pong, isn&#8217;t it <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ): He just published a white paper about <strong>&#8220;A Better Path to Enterprise Architectures&#8221;</strong> (04/2004, <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/sessfin00.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/sessfin00.asp</a>, or on his website). He also uses the &#8220;analogy of an enterprise architecture to a city plan&#8221;, but he takes it further and examins how to evolve the enterprise (rather than the single service) without loosing control.</p>
<p>Well, that&#8217;s it so far. These two guys have done tremendous work to describe the large, interdepended, and grossly complex eco systems that we as developers and architects have to deliver, maintain, evolve, and master. To my relief so far, the reality today is (mostly) still some iteratations behind these prospects. However &#8211; as Roger pointed out with his examples of failures &#8211; this may be the case because we (as an industry) couldn&#8217;t yet deliver this vision of eco systems.</p>
<p>That&#8217;s all for now folks,<br />
AJ.NET</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=13&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/07/17/soa-starting-point/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Intel&#8217;s Core 2 Extreme &amp; Core 2 Duo: The Empire Strikes Back</title>
		<link>http://ajdotnet.wordpress.com/2006/07/15/intels-core-2-extreme-core-2-duo-the-empire-strikes-back/</link>
		<comments>http://ajdotnet.wordpress.com/2006/07/15/intels-core-2-extreme-core-2-duo-the-empire-strikes-back/#comments</comments>
		<pubDate>Sat, 15 Jul 2006 09:18:56 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/07/15/intels-core-2-extreme-core-2-duo-the-empire-strikes-back/</guid>
		<description><![CDATA[Now, this is my first post, and it covers a quite uncommon topic for me for it relates to hardware (which is something I tend to find boring). Yet it struck me that yesterday I knew which OS my next machine will probably run (Vista &#8211; despite its DRM nuisance), but today I know which [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=12&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Now, this is my first post, and it covers a quite uncommon topic for me for it relates to hardware (which is something I tend to find boring). Yet it struck me that yesterday I knew which OS my next machine will probably run (Vista &#8211; despite its DRM nuisance), but today I know which processor (familly) will be at the heart of that machine.</p>
<p>The full article that came to my attention can be found <a target="_blank" href="http://www.anandtech.com/cpuchipsets/showdoc.aspx?i=2795">here</a>. The gist is that the new Core 2 processors obsolete Intels current Pentium D line and put AMD into the second league. Some quotes:</p>
<ul>
<li>Unfortunately AMD won&#8217;t have an architectural update of the Athlon 64 X2 until sometime in 2007 or 2008, thus its only response to Intel&#8217;s Core 2 lineup today is to also reduce pricing.</li>
<li>As you will soon see, Intel&#8217;s new Core 2 lineup has basically made all previous Intel processors worthless.</li>
<li>At the high end, the Core 2 Extreme X6800 was just under 36% faster than the Athlon 64 FX-62. In fact, even the $316 E6600 was around 18% faster than AMD&#8217;s fastest. To add even more insult to injury the slowest Core 2 Duo in the test, the 1.86GHz E6300 is barely slower than AMD&#8217;s fastest Athlon 64 X2.</li>
<li>The old Intel lineup of Pentium D processors is truly an embarrassment. Only the Extreme Edition 965 is remotely competitive and even then it can barely outperform the $183 E6300.</li>
<li>these power numbers heavily favor Intel.</li>
<li>Intel&#8217;s Core 2 Extreme X6800 didn&#8217;t lose a single benchmark in our comparison; not a single one. In many cases, the $183 Core 2 Duo E6300 actually outperformed Intel&#8217;s previous champ: the Pentium Extreme Edition 965. In one day, Intel has made its entire Pentium D lineup of processors obsolete. Intel&#8217;s Core 2 processors offer the sort of next-generation micro-architecture performance leap that we honestly haven&#8217;t seen from Intel since the introduction of the P6.</li>
</ul>
<p>There is essentially two things that thrill me:</p>
<ol>
<li>A huge step forward in terms of performance at the right time, i.e. at the advent of Vista (and nobody thinks this timing is anything but pure accidental <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> )</li>
<li>No more need to distinguish between desktop and laptop processors. More to the point, no need to choose between fast but power consuming heating chips or striped down versions.</li>
</ol>
<p>So, whoever is thinking of a new PC as his next christmas present, (s)he should tell Santa that it better had one of these new processors.</p>
<p>Bye,<br />
AJ.NET</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=12&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/07/15/intels-core-2-extreme-core-2-duo-the-empire-strikes-back/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
		<item>
		<title>Finally&#8230;</title>
		<link>http://ajdotnet.wordpress.com/2006/07/14/finally/</link>
		<comments>http://ajdotnet.wordpress.com/2006/07/14/finally/#comments</comments>
		<pubDate>Fri, 14 Jul 2006 15:00:23 +0000</pubDate>
		<dc:creator>ajdotnet</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">https://ajdotnet.wordpress.com/2006/07/14/finally/</guid>
		<description><![CDATA[.. I decided to inflict my 0,02€ on the world. Let&#8217;s see how far this gets and how long I am motivated to keep this blog up and running&#8230;.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=3&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>.. I decided to inflict my 0,02€ on the world. Let&#8217;s see how far this gets and how long I am motivated to keep this blog up and running&#8230;.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajdotnet.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajdotnet.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajdotnet.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajdotnet.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajdotnet.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajdotnet.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajdotnet.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajdotnet.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajdotnet.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajdotnet.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajdotnet.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajdotnet.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajdotnet.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajdotnet.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajdotnet.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajdotnet.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&amp;blog=305378&amp;post=3&amp;subd=ajdotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2006/07/14/finally/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/03b347f75b708670587fdbae73778116?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajdotnet</media:title>
		</media:content>
	</item>
	</channel>
</rss>
