<?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 &#187; .NET Framework</title>
	<atom:link href="http://ajdotnet.wordpress.com/category/net-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://ajdotnet.wordpress.com</link>
	<description>Thoughts and informations I think worthwhile to share...</description>
	<lastBuildDate>Sat, 28 Nov 2009 18:43:27 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='ajdotnet.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/e3d62c21bef499236be83d5bda37b578?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>AJ's blog &#187; .NET Framework</title>
		<link>http://ajdotnet.wordpress.com</link>
	</image>
			<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 he [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&blog=305378&post=632&subd=ajdotnet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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://s.wordpress.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>
  <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/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&blog=305378&post=632&subd=ajdotnet&ref=&feed=1" /></div>]]></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 AES is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&blog=305378&post=629&subd=ajdotnet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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://s.wordpress.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>
  <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/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&blog=305378&post=629&subd=ajdotnet&ref=&feed=1" /></div>]]></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 (pre-Kili  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&blog=305378&post=612&subd=ajdotnet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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://s.wordpress.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>
  <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/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&blog=305378&post=612&subd=ajdotnet&ref=&feed=1" /></div>]]></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>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 a web [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&blog=305378&post=587&subd=ajdotnet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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>
  <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/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&blog=305378&post=587&subd=ajdotnet&ref=&feed=1" /></div>]]></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>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 provide the service [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&blog=305378&post=469&subd=ajdotnet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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://s.wordpress.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>
  <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/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&blog=305378&post=469&subd=ajdotnet&ref=&feed=1" /></div>]]></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 them [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&blog=305378&post=456&subd=ajdotnet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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://s.wordpress.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>
  <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/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&blog=305378&post=456&subd=ajdotnet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/08/27/silverlight-bitspieces-part-4-view-model-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_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 doesn&#8217;t.)
The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&blog=305378&post=422&subd=ajdotnet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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://s.wordpress.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://s.wordpress.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>
  <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/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&blog=305378&post=422&subd=ajdotnet&ref=&feed=1" /></div>]]></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&blog=305378&post=386&subd=ajdotnet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><blockquote><p>Note: This is part of a series…. Well, it will be <img src='http://s.wordpress.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://s.wordpress.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>
  <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/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&blog=305378&post=386&subd=ajdotnet&ref=&feed=1" /></div>]]></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&blog=305378&post=340&subd=ajdotnet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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://s.wordpress.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://s.wordpress.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://s.wordpress.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://s.wordpress.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://s.wordpress.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>
  <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/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&blog=305378&post=340&subd=ajdotnet&ref=&feed=1" /></div>]]></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>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 one [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajdotnet.wordpress.com&blog=305378&post=325&subd=ajdotnet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><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>
  <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/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&blog=305378&post=325&subd=ajdotnet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajdotnet.wordpress.com/2009/08/01/posting-guards-guard-classes-explained/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%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>
	</channel>
</rss>