<?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/"
	>

<channel>
	<title>Guido Maliandi</title>
	<atom:link href="http://blogs.southworks.net/gmaliandi/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.southworks.net/gmaliandi</link>
	<description></description>
	<lastBuildDate>Fri, 20 Jan 2012 20:20:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to: Use Application Library Caching in Prism modules</title>
		<link>http://blogs.southworks.net/gmaliandi/2012/01/how-to-use-application-library-caching-in-prism-modules/</link>
		<comments>http://blogs.southworks.net/gmaliandi/2012/01/how-to-use-application-library-caching-in-prism-modules/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 20:18:42 +0000</pubDate>
		<dc:creator>Guido Leandro Maliandi</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[MEF]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Application Library Caching]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/gmaliandi/?p=130</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/gmaliandi/2012/01/how-to-use-application-library-caching-in-prism-modules/" class="more-link">read more<img src="http://blogs.southworks.net/gmaliandi/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>Imagine you have a Silverlight application with functionality that is likely to change over time, but that application depends on some possibly heavyweight libraries that aren’t going to change. Every single change in your code would cause users to download the entire XAP file again, including those heavy libraries that didn’t change.</p>
<p>To address this concern, it’s possible to leverage <a href="http://msdn.microsoft.com/en-us/library/dd833069%28VS.95%29.aspx">Application Library Caching</a>, which involves separating those libraries in ZIP files that are outside the XAP file, and should remain cached in the users’ browsers regardless of changes in the XAP. Prism supports Application Library Caching by, for example, providing the necessary metadata in the Prism assemblies to set them as external libraries.</p>
<p>However, when using Application Library Caching in Prism Modules, this doesn’t work out of the box. Let’s examine why this happens.</p>
<h2>What happens with modules and Application Library Caching?</h2>
<p><a href="http://blogs.southworks.net/aadami/">Agustin Adami</a> and I examined the way Prism loads the content of module’s XAP files and found that the <strong>XapModuleTypeLoader </strong>reads the <strong>AppManifest.xaml</strong> file inside the module&#8217;s XAP file, searches for the <strong>Deployment.Parts</strong> elements and then loads the assemblies corresponding to the ones specified in the <strong>Source </strong>property of the <strong>AssemblyPart </strong>elements in the aforementioned XML element. However, dependencies that have been placed on a ZIP file using Application Library Caching are referenced in <strong>ExtensionPart </strong>elements inside the <strong>Deployment.ExternalParts</strong> element, and the physical file is stored outside the module’s XAP file (which is the only thing downloaded at this point.)</p>
<p>To illustrate this, here&#8217;s how the <strong>AppManifest </strong>for a certain module might look like:</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<pre style="width: 576px;height: 161px;background-color: white;overflow: auto">
<div><span style="color: #008080"> 1</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">Deployment </span><span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://schemas.microsoft.com/client/2007/deployment"</span><span style="color: #ff0000"> (...)</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 2</span> <span style="color: #000000">  </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">Deployment.Parts</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 3</span> <span style="color: #000000">    </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">AssemblyPart </span><span style="color: #ff0000">x:Name</span><span style="color: #0000ff">="SomeModule"</span><span style="color: #ff0000"> Source</span><span style="color: #0000ff">="SomeModule.dll"</span><span style="color: #ff0000"> </span><span style="color: #0000ff">/&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 4</span> <span style="color: #000000">    </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">AssemblyPart </span><span style="color: #ff0000">x:Name</span><span style="color: #0000ff">="Infrastructure"</span><span style="color: #ff0000"> Source</span><span style="color: #0000ff">="Infrastructure.dll"</span><span style="color: #ff0000"> </span><span style="color: #0000ff">/&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 5</span> <span style="color: #000000">  </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">Deployment.Parts</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 6</span> <span style="color: #000000">  </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">Deployment.ExternalParts</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 7</span> <span style="color: #000000">    </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">ExtensionPart </span><span style="color: #ff0000">Source</span><span style="color: #0000ff">="System.Windows.Controls.Data.Input.zip"</span><span style="color: #ff0000"> </span><span style="color: #0000ff">/&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 8</span> <span style="color: #000000">    </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">ExtensionPart </span><span style="color: #ff0000">Source</span><span style="color: #0000ff">="System.ComponentModel.DataAnnotations.zip"</span><span style="color: #ff0000"> </span><span style="color: #0000ff">/&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 9</span> <span style="color: #000000">  </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">Deployment.ExternalParts</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080">10</span> <span style="color: #000000"> </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">Deployment</span><span style="color: #0000ff">&gt;</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>Now, when a module&#8217;s XAP file has been downloaded, the <strong>XapModuleTypeLoader.HandleModuleDownloaded </strong>method is called, which loads in memory the results obtained by calling the <strong>XapModuleTypeLoader.GetParts</strong> method. This method ignores the <strong>Deployment.ExternalParts</strong> element inside the <strong>AppManifest.xaml </strong>file (as seen in the code snippet above):</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<pre style="width: 687px;height: 558px;background-color: white;overflow: auto">
<div><span style="color: #008080"> 1</span> <span style="color: #000000">(...)</span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> IEnumerable</span><span style="color: #000000">&lt;</span><span style="color: #000000">AssemblyPart</span><span style="color: #000000">&gt;</span><span style="color: #000000"> GetParts(Stream stream)
</span><span style="color: #008080"> 2</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">            List</span><span style="color: #000000">&lt;</span><span style="color: #000000">AssemblyPart</span><span style="color: #000000">&gt;</span><span style="color: #000000"> assemblyParts </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> List</span><span style="color: #000000">&lt;</span><span style="color: #000000">AssemblyPart</span><span style="color: #000000">&gt;</span><span style="color: #000000">();
</span><span style="color: #008080"> 4</span> <span style="color: #000000">
</span><span style="color: #008080"> 5</span> <span style="color: #000000">            var streamReader </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> StreamReader(Application.GetResourceStream(</span><span style="color: #0000ff">new</span><span style="color: #000000"> StreamResourceInfo(stream, </span><span style="color: #0000ff">null</span><span style="color: #000000">), </span><span style="color: #0000ff">new</span><span style="color: #000000"> Uri(</span><span style="color: #800000">"</span><span style="color: #800000">AppManifest.xaml</span><span style="color: #800000">"</span><span style="color: #000000">, UriKind.Relative)).Stream);
</span><span style="color: #008080"> 6</span> <span style="color: #000000">            </span><span style="color: #0000ff">using</span><span style="color: #000000"> (XmlReader xmlReader </span><span style="color: #000000">=</span><span style="color: #000000"> XmlReader.Create(streamReader))
</span><span style="color: #008080"> 7</span> <span style="color: #000000">            {
</span><span style="color: #008080"> 8</span> <span style="color: #000000">                xmlReader.MoveToContent();
</span><span style="color: #008080"> 9</span> <span style="color: #000000">                </span><span style="color: #0000ff">while</span><span style="color: #000000"> (xmlReader.Read())
</span><span style="color: #008080">10</span> <span style="color: #000000">                {
</span><span style="color: #008080">11</span> <span style="color: #000000">                    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (xmlReader.NodeType </span><span style="color: #000000">==</span><span style="color: #000000"> XmlNodeType.Element </span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000"> xmlReader.Name </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #800000">"</span><span style="color: #800000">Deployment.Parts</span><span style="color: #800000">"</span><span style="color: #000000">)
</span><span style="color: #008080">12</span> <span style="color: #000000">                    {
</span><span style="color: #008080">13</span> <span style="color: #000000">                    </span><span style="color: #008000">//</span><span style="color: #008000"> Deployment.Parts is examined, but Deployment.ExternalParts isn't</span><span style="color: #008000">
</span><span style="color: #008080">14</span> <span style="color: #008000"> </span><span style="color: #000000">                        </span><span style="color: #0000ff">using</span><span style="color: #000000"> (XmlReader xmlReaderAssemblyParts </span><span style="color: #000000">=</span><span style="color: #000000"> xmlReader.ReadSubtree())
</span><span style="color: #008080">15</span> <span style="color: #000000">                        {
</span><span style="color: #008080">16</span> <span style="color: #000000">                            </span><span style="color: #0000ff">while</span><span style="color: #000000"> (xmlReaderAssemblyParts.Read())
</span><span style="color: #008080">17</span> <span style="color: #000000">                            {
</span><span style="color: #008080">18</span> <span style="color: #000000">                                </span><span style="color: #0000ff">if</span><span style="color: #000000"> (xmlReaderAssemblyParts.NodeType </span><span style="color: #000000">==</span><span style="color: #000000"> XmlNodeType.Element </span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000"> xmlReaderAssemblyParts.Name </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #800000">"</span><span style="color: #800000">AssemblyPart</span><span style="color: #800000">"</span><span style="color: #000000">)
</span><span style="color: #008080">19</span> <span style="color: #000000">                                {
</span><span style="color: #008080">20</span> <span style="color: #000000">                                    AssemblyPart assemblyPart </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> AssemblyPart();
</span><span style="color: #008080">21</span> <span style="color: #000000">                                    assemblyPart.Source </span><span style="color: #000000">=</span><span style="color: #000000"> xmlReaderAssemblyParts.GetAttribute(</span><span style="color: #800000">"</span><span style="color: #800000">Source</span><span style="color: #800000">"</span><span style="color: #000000">);
</span><span style="color: #008080">22</span> <span style="color: #000000">                                    assemblyParts.Add(assemblyPart);
</span><span style="color: #008080">23</span> <span style="color: #000000">                                }
</span><span style="color: #008080">24</span> <span style="color: #000000">                            }
</span><span style="color: #008080">25</span> <span style="color: #000000">                        }
</span><span style="color: #008080">26</span> <span style="color: #000000">
</span><span style="color: #008080">27</span> <span style="color: #000000">                        </span><span style="color: #0000ff">break</span><span style="color: #000000">;
</span><span style="color: #008080">28</span> <span style="color: #000000">                    }
</span><span style="color: #008080">29</span> <span style="color: #000000">                }
</span><span style="color: #008080">30</span> <span style="color: #000000">            }
</span><span style="color: #008080">31</span> <span style="color: #000000">
</span><span style="color: #008080">32</span> <span style="color: #000000">            </span><span style="color: #0000ff">return</span><span style="color: #000000"> assemblyParts;
</span><span style="color: #008080">33</span> <span style="color: #000000">        }
</span><span style="color: #008080">34</span> <span style="color: #000000">(...)
</span><span style="color: #008080">35</span> <span style="color: #000000"> </span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<h2>The Unity Solution</h2>
<p>As a possible workaround to avoid this problem from happening, we created a modified version of the <strong>XapModuleTypeLoader </strong>(named <strong>LibraryCachingXapModuleTypeLoader</strong>), which loads the extension parts in memory before loading the assembly parts. To do this, we modified the <strong>IFileDownloader_DownloadCompleted</strong> method to obtain an <strong>ExternalPartsLoader</strong> from the container and call its <strong>LoadExtensionParts</strong> method before calling the <strong>HandleModuleDownloaded</strong>. The <strong>ExternalPartsLoader.LoadExtensionParts</strong> method basically searches for the <strong>AppManifest.xaml</strong> inside the XAP file, downloads the ZIP files containing the extension parts and loads the corresponding libraries in memory. Once this operation has finished, the <strong>HandleModuleDownloaded</strong> (which had been passed as a callback) is called, and the module loading process continues as it would regularly do.</p>
<p>To make this work, we had to create a class that inherits from <strong>ModuleManager </strong>and overrides its <strong>ModuleTypeLoaders </strong>property to use the <strong>LibraryCachingXapModuleTypeLoaderWith </strong>class instead of the regular <strong>XapModuleTypeLoader</strong>. We then overrode the <strong>ConfigureContainer </strong>method in the bootstrapper to register this custom module manager (named <strong>LibraryCachingModuleManager</strong>) in the container, so that it is used instead of the regular one.</p>
<p>You can find a sample that contains all the aforementioned modifications in my <a href="https://skydrive.live.com/#cid=7890102B5B8BC928&amp;id=7890102B5B8BC928%21103">Skydrive account</a> under the name <strong>LibraryCachingSupport.zip</strong>. This sample contains a Shell project and a module; both of which use Application Library Caching.</p>
<h2>The MEF Solution</h2>
<p>In the <strong>MefXapModuleTypeLoader</strong> a <strong>DeploymentCatalog</strong> is used to download the module’s XAP file and then compose all the parts defined in that file. Unlike in the <strong>XapModuleTypeLoader</strong>, it’s not possible to insert the external parts loading logic in the middle, so for this workaround, we had to opt out of the <strong>DeploymentCatalog </strong>and implement a similar functionality using the <strong>LibraryCachingXapModuleTypeLoader</strong> class.</p>
<p>Basically, the main aspect that should be considered for the MEF version is that the <strong>DeploymentCatalog</strong>, aside from loading the modules in memory, composes the parts discovered in it into the container. So, we added the logic to do so in both the <strong>LibraryCachingMefXapModuleTypeLoader</strong> and the <strong>MefExternalPartsLoader</strong>:</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<pre style="width: 694px;height: 163px;background-color: white;overflow: auto">
<div><span style="color: #008080"> 1</span> <span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> ComposePartsInContainer(Assembly assembly)
</span><span style="color: #008080"> 2</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">            var catalog </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> AssemblyCatalog(assembly);
</span><span style="color: #008080"> 4</span> <span style="color: #000000">
</span><span style="color: #008080"> 5</span> <span style="color: #000000">            var batch </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> CompositionBatch(catalog.Parts.Select(e </span><span style="color: #000000">=&gt;</span><span style="color: #000000"> e.CreatePart()), </span><span style="color: #0000ff">null</span><span style="color: #000000">);
</span><span style="color: #008080"> 6</span> <span style="color: #000000">
</span><span style="color: #008080"> 7</span> <span style="color: #000000">            var container </span><span style="color: #000000">=</span><span style="color: #000000"> ServiceLocator.Current.GetInstance</span><span style="color: #000000">&lt;</span><span style="color: #000000">CompositionContainer</span><span style="color: #000000">&gt;</span><span style="color: #000000">();
</span><span style="color: #008080"> 8</span> <span style="color: #000000">
</span><span style="color: #008080"> 9</span> <span style="color: #000000">            container.Compose(batch);
</span><span style="color: #008080">10</span> <span style="color: #000000">        }</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>Additionally, we had to register the <strong>CompositionContainer</strong> in itself in order to be retrieved by the service locator in that piece of code.</p>
<p>You can find a sample that contains the MEF version of this approach in my <a href="https://skydrive.live.com/#cid=7890102B5B8BC928&amp;id=7890102B5B8BC928%21103">Skydrive account</a> under the name <strong>MefLibraryCachingSupport.zip</strong>.</p>
<p>Please note that this might not be the best approach to achieve this functionality, and it hasn’t been thoroughly tested; the intention of this post is to explain why this happens, and provide a possible workaround that might also serve as an example to implement the approach differently.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: define module-specific resource dictionaries in Prism</title>
		<link>http://blogs.southworks.net/gmaliandi/2012/01/how-to-define-module-specific-resource-dictionaries-in-prism/</link>
		<comments>http://blogs.southworks.net/gmaliandi/2012/01/how-to-define-module-specific-resource-dictionaries-in-prism/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 21:09:15 +0000</pubDate>
		<dc:creator>Guido Leandro Maliandi</dc:creator>
				<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/gmaliandi/?p=126</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/gmaliandi/2012/01/how-to-define-module-specific-resource-dictionaries-in-prism/" class="more-link">read more<img src="http://blogs.southworks.net/gmaliandi/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>Resource dictionaries are a nice way to specify styles, data templates, and similar items in WPF/Silverlight applications. In Prism modules, some times one would expect to define resource dictionaries that are specific to a certain module, as this would avoid exposing module specifics to the rest of the application. Yet, this might not be totally trivial, because resource dictionaries are usually defined in the <strong>App.xaml</strong>, and the<strong> </strong>only <strong>App.xaml </strong>that is used in most Prism applications is the one that belongs to the <strong>Shell</strong> project. I thought of a possible way to overcome this problem, which I’ll explain below.</p>
<p>But first, let’s examine what happens with those resource dictionaries when they are specified in the Shell’s <strong>App.xaml</strong>, and why views can consume them even if they’re defined on a separate project. Resources defined in the <strong>App.xaml</strong> become available in the <strong>Application.Resources</strong> <strong>ResourceDictionary</strong> of the current <strong>Application</strong> class (which can be accessed through the <strong>Application.Current</strong> static property.) Once they’re available there, they can be consumed from within the XAML as static resources. Since modules are loaded into the same application domain as the <strong>Shell</strong> project, views defined there can access resources as long as they can be found in the corresponding <strong>Application.Resources</strong> dictionary.</p>
<p>You may have noticed that some times modules also contain an <strong>App.xaml</strong> file. This file isn’t loaded when Prism modules are loaded; only one <strong>Application</strong> class is instantiated, and that’s the one in the <strong>Shell</strong> project.</p>
<p><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/gmaliandi/files/2012/01/image.png" border="0" alt="image" width="244" height="231" /></p>
<p>So, while defining the resources in the module’s <strong>App.xaml</strong> file would make them show in the designer, they wouldn’t work when the application is ran. Going backwards a little, <strong>Application.Current.Resources </strong>can be accessed from anywhere inside the Prism application (even modules), and the <strong>ResourceDictionary</strong> class supports adding new entries! So you might see where I’m going with this…</p>
<h2>The approach</h2>
<p>I tried programmatically adding new entries to the <strong>Application.Current.Resources</strong> dictionary and it worked! So this leaves us with two more needs in my opinion:</p>
<ol>
<li>A way to get the resources to add from a XAML resource dictionary file (in the module, of course.)</li>
<li>A comfortable way to specify that the resources in that file should be loaded.</li>
</ol>
<p>The first one was actually simple. We can create a new instance of the <strong>ResourceDictionary</strong> class passing the file’s URI as the source. As for the second one, I thought that perhaps abstracting the whole thing with an attribute might be a good idea. So, I created an attribute named <strong>ModuleResourceAttribute</strong>, which has a constructor that accepts a string as a parameter; this string should be the location of the XAML file, e.g. <em>“/ModuleA;component/ModuleResources/Resources.xaml”</em>. The idea is that this attribute could be specified on a module, like this:</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<pre style="width: 652px;height: 119px;background-color: white;overflow: auto">
<div><span style="color: #008080">1</span> <span style="color: #000000">[ModuleResource(</span><span style="color: #800000">"</span><span style="color: #800000">/ModuleA;component/ModuleResources/Resources.xaml</span><span style="color: #800000">"</span><span style="color: #000000">)]
</span><span style="color: #008080">2</span> <span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> ModuleA : IModule
</span><span style="color: #008080">3</span> <span style="color: #000000">    {
</span><span style="color: #008080">4</span> <span style="color: #000000">        (...)
</span><span style="color: #008080">5</span> <span style="color: #000000">    }</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>Then, I created a simple service to load resources into the <strong>Application.Current.Resources</strong> dictionary:</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<pre style="width: 652px;height: 260px;background-color: white;overflow: auto">
<div><span style="color: #008080"> 1</span> <span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">interface</span><span style="color: #000000"> IResourceLoader
</span><span style="color: #008080"> 2</span> <span style="color: #000000">    {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">        </span><span style="color: #0000ff">void</span><span style="color: #000000"> LoadModuleResources(Uri resourceUri);
</span><span style="color: #008080"> 4</span> <span style="color: #000000">    }
</span><span style="color: #008080"> 5</span> <span style="color: #000000">
</span><span style="color: #008080"> 6</span> <span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> ResourceLoader : IResourceLoader
</span><span style="color: #008080"> 7</span> <span style="color: #000000">    {
</span><span style="color: #008080"> 8</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> LoadModuleResources(Uri resourceUri)
</span><span style="color: #008080"> 9</span> <span style="color: #000000">        {
</span><span style="color: #008080">10</span> <span style="color: #000000">            var resources </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> ResourceDictionary { Source </span><span style="color: #000000">=</span><span style="color: #000000"> resourceUri };
</span><span style="color: #008080">11</span> <span style="color: #000000">
</span><span style="color: #008080">12</span> <span style="color: #000000">            </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (var key </span><span style="color: #0000ff">in</span><span style="color: #000000"> resources.Keys)
</span><span style="color: #008080">13</span> <span style="color: #000000">            {
</span><span style="color: #008080">14</span> <span style="color: #000000">                Application.Current.Resources.Add(key, resources[key]);
</span><span style="color: #008080">15</span> <span style="color: #000000">            }
</span><span style="color: #008080">16</span> <span style="color: #000000">        }
</span><span style="color: #008080">17</span> <span style="color: #000000">    }</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>Finally, I created a modified implementation of the <strong>ModuleInitializer</strong> so that it checks if the module has any <strong>ModuleResourceAttribute</strong>s to load the necessary resources prior to module initialization:</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<pre style="width: 877px;height: 624px;background-color: white;overflow: auto">
<div><span style="color: #008080"> 1</span> <span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> ModifiedModuleInitializer : IModuleInitializer
</span><span style="color: #008080"> 2</span> <span style="color: #000000">    {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">        (...)
</span><span style="color: #008080"> 4</span> <span style="color: #000000">
</span><span style="color: #008080"> 5</span> <span style="color: #000000">
</span><span style="color: #008080"> 6</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> Initialize(ModuleInfo moduleInfo)
</span><span style="color: #008080"> 7</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 8</span> <span style="color: #000000">            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (moduleInfo </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">) </span><span style="color: #0000ff">throw</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> ArgumentNullException(</span><span style="color: #800000">"</span><span style="color: #800000">moduleInfo</span><span style="color: #800000">"</span><span style="color: #000000">);
</span><span style="color: #008080"> 9</span> <span style="color: #000000">
</span><span style="color: #008080">10</span> <span style="color: #000000">            IModule moduleInstance </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">;
</span><span style="color: #008080">11</span> <span style="color: #000000">            </span><span style="color: #0000ff">try</span><span style="color: #000000">
</span><span style="color: #008080">12</span> <span style="color: #000000">            {
</span><span style="color: #008080">13</span> <span style="color: #000000">                moduleInstance </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">this</span><span style="color: #000000">.CreateModule(moduleInfo);
</span><span style="color: #008080">14</span> <span style="color: #000000">                </span><span style="color: #0000ff">this</span><span style="color: #000000">.LoadResources(moduleInstance);
</span><span style="color: #008080">15</span> <span style="color: #000000">                moduleInstance.Initialize();
</span><span style="color: #008080">16</span> <span style="color: #000000">            }
</span><span style="color: #008080">17</span> <span style="color: #000000">            </span><span style="color: #0000ff">catch</span><span style="color: #000000"> (Exception ex)
</span><span style="color: #008080">18</span> <span style="color: #000000">            {
</span><span style="color: #008080">19</span> <span style="color: #000000">                </span><span style="color: #0000ff">this</span><span style="color: #000000">.HandleModuleInitializationError(
</span><span style="color: #008080">20</span> <span style="color: #000000">                    moduleInfo,
</span><span style="color: #008080">21</span> <span style="color: #000000">                    moduleInstance </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000"> </span><span style="color: #000000">?</span><span style="color: #000000"> moduleInstance.GetType().Assembly.FullName : </span><span style="color: #0000ff">null</span><span style="color: #000000">,
</span><span style="color: #008080">22</span> <span style="color: #000000">                    ex);
</span><span style="color: #008080">23</span> <span style="color: #000000">            }
</span><span style="color: #008080">24</span> <span style="color: #000000">        }
</span><span style="color: #008080">25</span> <span style="color: #000000">
</span><span style="color: #008080">26</span> <span style="color: #000000">           (...)
</span><span style="color: #008080">27</span> <span style="color: #000000">
</span><span style="color: #008080">28</span> <span style="color: #000000">        </span><span style="color: #0000ff">protected</span><span style="color: #000000"> </span><span style="color: #0000ff">virtual</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> LoadResources(IModule moduleInstance)
</span><span style="color: #008080">29</span> <span style="color: #000000">        {
</span><span style="color: #008080">30</span> <span style="color: #000000">            var attributes </span><span style="color: #000000">=</span><span style="color: #000000"> moduleInstance.GetType().GetCustomAttributes(</span><span style="color: #0000ff">typeof</span><span style="color: #000000">(ModuleResourceAttribute), </span><span style="color: #0000ff">true</span><span style="color: #000000">).Cast</span><span style="color: #000000">&lt;</span><span style="color: #000000">ModuleResourceAttribute</span><span style="color: #000000">&gt;</span><span style="color: #000000">();
</span><span style="color: #008080">31</span> <span style="color: #000000">            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (attributes </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">)
</span><span style="color: #008080">32</span> <span style="color: #000000">            {
</span><span style="color: #008080">33</span> <span style="color: #000000">                </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (var attribute </span><span style="color: #0000ff">in</span><span style="color: #000000"> attributes)
</span><span style="color: #008080">34</span> <span style="color: #000000">                {
</span><span style="color: #008080">35</span> <span style="color: #000000">                    var resourceUri </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Uri(attribute.ResourceLocation, UriKind.RelativeOrAbsolute);
</span><span style="color: #008080">36</span> <span style="color: #000000">                    resourceLoader.LoadModuleResources(resourceUri);
</span><span style="color: #008080">37</span> <span style="color: #000000">                }
</span><span style="color: #008080">38</span> <span style="color: #000000">            }
</span><span style="color: #008080">39</span> <span style="color: #000000">        }
</span><span style="color: #008080">40</span> <span style="color: #000000">    }</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>I also created a little sample that portrays this, which can be found <a href="https://skydrive.live.com/#cid=12A8B70137345033&amp;id=12A8B70137345033!119">in my SkyDrive account</a> under the name <strong>ModuleSpecificResourceDictionaries</strong>.</p>
<p>I hope you find this handy!</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prism: Binding to commands from inside DataTemplates</title>
		<link>http://blogs.southworks.net/gmaliandi/2011/11/prism-binding-to-commands-from-inside-datatemplates/</link>
		<comments>http://blogs.southworks.net/gmaliandi/2011/11/prism-binding-to-commands-from-inside-datatemplates/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 14:15:05 +0000</pubDate>
		<dc:creator>Guido Leandro Maliandi</dc:creator>
				<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/gmaliandi/?p=117</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/gmaliandi/2011/11/prism-binding-to-commands-from-inside-datatemplates/" class="more-link">read more<img src="http://blogs.southworks.net/gmaliandi/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>Placing command bindings inside <strong>DataTemplates</strong> is a common scenario when developing rich client applications in Sliverlight/WPF; for example, when defining the item template in an items control to decide how to show certain data object, it’s likely that you’d want to include a button with a command binding in the template. However, since the <strong>DataContext</strong> of a <strong>DataTemplate</strong> is set to the data object itself, and commands are usually defined in the <strong>ViewModel</strong> of a view, not in the data object to be shown, it’s not possible, at first sight, to bind to the command from within it.</p>
<h2>ObservableCommand</h2>
<p>However, there’s a clever solution for this, devised by the Prism team in the <a href="http://msdn.microsoft.com/en-us/library/gg430881%28PandP.40%29.aspx">View-Switching Navigation QuickStart</a>. The idea is that the command can be reached through the <strong>Source</strong> property in the command binding, since that property allows one to specify where to look for the property to bind to. In the QuickStart, they define an instance of <strong>ObservableCommand </strong>as a resource in the user control that will have a command binding from a <strong>DataTemplate</strong>. <strong>ObservableCommand</strong> is a class that simply inherits from Prism’s <strong>ObservableObject&lt;T&gt;</strong> class specifying <strong>ICommand</strong> as the type parameter. This class has a <strong>Value</strong> property of type <strong>ICommand</strong>, a <strong>ValueProperty</strong> dependency property, and implements the <strong>INotifyPropertyChanged</strong>, which makes it possible for others to bind to its <strong>Value</strong> property and receive the changes in the element bound to it.</p>
<h2>Sample Application</h2>
<p>I’ve created a sample application to exemplify the use of the <strong>ObservableCommand</strong> to achieve command bindings from within <strong>DataTemplates</strong>, using Prism.</p>
<p><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/gmaliandi/files/2011/11/image1.png" border="0" alt="image" width="669" height="591" /></p>
<p>The sample contains a region inside an <strong>ItemsControl</strong>. The <strong>ItemsControl</strong> defines a button inside its <strong>ItemTemplate</strong>, which binds to a command that just pops a message in a message box. To be able to bind to the command, an ObservableCommand is used. The message to be shown depends on the string added to the region. The XAML for this can be seen here:</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<pre style="width: 700px;height: 293px;background-color: white;overflow: auto">
<div><span style="color: #008080"> 1</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">UserControl.Resources</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 2</span> <span style="color: #000000">        </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">infrastructure:ObservableCommand </span><span style="color: #ff0000">x:Key</span><span style="color: #0000ff">="ShowMessageCommand"</span><span style="color: #ff0000"> Value</span><span style="color: #0000ff">="</span><span style="color: #808000">{Binding ShowMessageCommand}</span><span style="color: #0000ff">"</span><span style="color: #ff0000"> </span><span style="color: #0000ff">/&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 3</span> <span style="color: #000000">    </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">UserControl.Resources</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 4</span> <span style="color: #000000">
</span><span style="color: #008080"> 5</span> <span style="color: #000000">    </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">ItemsControl </span><span style="color: #ff0000">Regions:RegionManager.RegionName</span><span style="color: #0000ff">="MainRegion"</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 6</span> <span style="color: #000000">        </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">ItemsControl.ItemTemplate</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 7</span> <span style="color: #000000">            </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">DataTemplate</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 8</span> <span style="color: #000000">                </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">Border </span><span style="color: #ff0000">Background</span><span style="color: #0000ff">="Cyan"</span><span style="color: #ff0000"> HorizontalAlignment</span><span style="color: #0000ff">="Center"</span><span style="color: #ff0000"> BorderBrush</span><span style="color: #0000ff">="Black"</span><span style="color: #ff0000"> BorderThickness</span><span style="color: #0000ff">="3"</span><span style="color: #ff0000"> Margin</span><span style="color: #0000ff">="5"</span><span style="color: #ff0000"> Padding</span><span style="color: #0000ff">="5"</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 9</span> <span style="color: #000000">                    </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">StackPanel</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080">10</span> <span style="color: #000000">                        </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">TextBlock</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">The following button is located inside a DataTemplate, and will show a message corresponding to the string added to the region.</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">TextBlock</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080">11</span> <span style="color: #000000">                        </span><span style="color: #0000ff">&lt;</span><span style="color: #800000">Button </span><span style="color: #ff0000">Width</span><span style="color: #0000ff">="100"</span><span style="color: #ff0000"> Content</span><span style="color: #0000ff">="Show Message"</span><span style="color: #ff0000"> Command</span><span style="color: #0000ff">="</span><span style="color: #808000">{Binding Value, Source={StaticResource ShowMessageCommand}}</span><span style="color: #0000ff">"</span><span style="color: #ff0000"> CommandParameter</span><span style="color: #0000ff">="</span><span style="color: #808000">{Binding}</span><span style="color: #0000ff">"</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">Button</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080">12</span> <span style="color: #000000">                    </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">StackPanel</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080">13</span> <span style="color: #000000">                </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">Border</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080">14</span> <span style="color: #000000">            </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">DataTemplate</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080">15</span> <span style="color: #000000">        </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">ItemsControl.ItemTemplate</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">
</span><span style="color: #008080">16</span> <span style="color: #000000">    </span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">ItemsControl</span><span style="color: #0000ff">&gt;</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>You can find the sample <a href="https://skydrive.live.com/#!/?cid=12a8b70137345033&amp;sc=documents&amp;uc=1&amp;id=12A8B70137345033%21119">in my SkyDrive account</a>, under the name <strong>ObservableCommandSample</strong>.</p>
<p>I hope you find this helpful!</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using WCF services in Prism Silverlight applications</title>
		<link>http://blogs.southworks.net/gmaliandi/2011/10/using-wcf-services-in-prism-silverlight-applications/</link>
		<comments>http://blogs.southworks.net/gmaliandi/2011/10/using-wcf-services-in-prism-silverlight-applications/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 14:26:23 +0000</pubDate>
		<dc:creator>Guido Leandro Maliandi</dc:creator>
				<category><![CDATA[Prism]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/gmaliandi/?p=103</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/gmaliandi/2011/10/using-wcf-services-in-prism-silverlight-applications/" class="more-link">read more<img src="http://blogs.southworks.net/gmaliandi/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>There have been some discussions (e.g. <a href="http://compositewpf.codeplex.com/discussions/241013">this one</a>) where people using Prism wonder how to include service references (for example, to WCF services) to Prism applications. It has been shown, for example in <a href="http://www.global-webnet.net/blogengine/post/2009/01/03/PrismWCF-Cannot-find-ServiceReferencesClientConfig-in-xap-application-package.aspx">this blog post</a> and <a href="http://blogs.southworks.net/matiasb/2009/06/20/how-to-consume-wcf-services-from-composite-application-guidance-for-wpf-and-silverlightprism-v2-modules/">this other one</a> that this is possible with certain precautions.</p>
<p>However, the auto generated proxy classes that are created when including WCF service references might not be easily integrated in a Prism application, which has testability requirements, and most likely uses a DI container.</p>
<p>Here I will show a possible way to add a reference to a WCF service inside a Prism Silverlight application, exposing the service functionality as a shared service.</p>
<p><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/gmaliandi/files/2011/10/image3.png" border="0" alt="image" width="540" height="418" /></p>
<h2>The big picture</h2>
<p>The sample application I created contains:</p>
<ul>
<li>An infrastructure project (<strong>HelloWorld.Infrastructure</strong>) with a <strong>Customer </strong>class and a <strong>ICustomerServiceAgent</strong> interface,</li>
<li>A web project (<strong>HelloWorld.Silverlight.Web</strong>) that defines a WCF service using the <strong>Customer </strong>class (linked) as the data contract,</li>
<li>A Prism shell project (<strong>HelloWorld.Silverlight</strong>) containing the Shell with the main region and the application bootstrapper, and a link to the <strong>ServiceReferences.ClientConfig</strong> file (necessary for the service reference to work),</li>
<li>A <strong>ServicesModule</strong> that has a service reference to the WCF service defined in the Web project, and provides an implementation of <strong>ICustomerServiceAgent</strong>,</li>
<li>A <strong>HelloWorldModule</strong> that consumes the <strong>ICustomerServiceAgent </strong>and displays the data obtained from the service in a <strong>DataGrid</strong>.</li>
</ul>
<p><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/gmaliandi/files/2011/10/SNAGHTML658335.png" border="0" alt="SNAGHTML658335" width="266" height="410" /></p>
<p>The <strong>CustomerServiceAgent</strong> class, defined inside the <strong>ServicesModule</strong>, is exported in the container using the <strong>ICustomerServiceAgent</strong> interface as the contract type, thus becoming a <a href="http://msdn.microsoft.com/en-us/library/ff921122%28PandP.40%29.aspx#sec7">shared service</a> that can be consumed throughout the application.</p>
<h2>The implementation</h2>
<p>The <strong>CustomersService</strong>, as defined in the web project, exposes simply a <strong>GetCustomers</strong> method which returns a list of <strong>Customer</strong> entities. <strong>Customer</strong> entities have a FullName, a Company and an Address.</p>
<p>The implementation provided for this service in the web project is a mock one, that simply returns a hardcoded list of customers, with a fixed name, a fixed company, and an address with random numbers.</p>
<p>Now back to the client side of the application, the <strong>ICustomerServiceAgent</strong> interface provides a <strong>LoadCustomers</strong> method that accepts a callback (which has an <strong>ObservableCollection</strong> of <strong>Customer</strong>s as the parameter):</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<pre style="width: 747px;height: 97px;background-color: white;overflow: auto">
<div><span style="color: #008080">1</span> <span style="color: #000000"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">interface</span><span style="color: #000000"> ICustomerServiceAgent
</span><span style="color: #008080">2</span> <span style="color: #000000">    {
</span><span style="color: #008080">3</span> <span style="color: #000000">        </span><span style="color: #0000ff">void</span><span style="color: #000000"> LoadCustomers(Action</span><span style="color: #000000">&lt;</span><span style="color: #000000">ObservableCollection</span><span style="color: #000000">&lt;</span><span style="color: #000000">Customer</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000"> callback);
</span><span style="color: #008080">4</span> <span style="color: #000000">    }</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>And then, the implementation of this interface in the <strong>ServicesModule</strong> consumes the WCF service through the auto-generated service proxy (which is the result of the service reference), and exposes the <strong>LoadCustomers</strong> method as defined in the interface, abstracting away the details of how the asynchronous request to the service is made:</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<pre style="width: 750px;height: 329px;background-color: white;overflow: auto">
<div><span style="color: #008080"> 1</span> <span style="color: #000000">[Export(</span><span style="color: #0000ff">typeof</span><span style="color: #000000">(ICustomerServiceAgent))]
</span><span style="color: #008080"> 2</span> <span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> CustomerServiceAgent : ICustomerServiceAgent
</span><span style="color: #008080"> 3</span> <span style="color: #000000">    {
</span><span style="color: #008080"> 4</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">readonly</span><span style="color: #000000"> ICustomersService WCFServiceClient;
</span><span style="color: #008080"> 5</span> <span style="color: #000000">
</span><span style="color: #008080"> 6</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> CustomerServiceAgent()
</span><span style="color: #008080"> 7</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 8</span> <span style="color: #000000">            </span><span style="color: #0000ff">this</span><span style="color: #000000">.WCFServiceClient </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> CustomersServiceClient();
</span><span style="color: #008080"> 9</span> <span style="color: #000000">        }
</span><span style="color: #008080">10</span> <span style="color: #000000">
</span><span style="color: #008080">11</span> <span style="color: #000000">        </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> LoadCustomers(Action</span><span style="color: #000000">&lt;</span><span style="color: #000000">ObservableCollection</span><span style="color: #000000">&lt;</span><span style="color: #000000">Customer</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000"> callback)
</span><span style="color: #008080">12</span> <span style="color: #000000">        {
</span><span style="color: #008080">13</span> <span style="color: #000000">            </span><span style="color: #0000ff">this</span><span style="color: #000000">.WCFServiceClient.BeginGetCustomers(
</span><span style="color: #008080">14</span> <span style="color: #000000">                (e) </span><span style="color: #000000">=&gt;</span><span style="color: #000000"> Deployment.Current.Dispatcher.BeginInvoke(
</span><span style="color: #008080">15</span> <span style="color: #000000">                    () </span><span style="color: #000000">=&gt;</span><span style="color: #000000"> callback(</span><span style="color: #0000ff">this</span><span style="color: #000000">.WCFServiceClient.EndGetCustomers(e))),
</span><span style="color: #008080">16</span> <span style="color: #000000">                    </span><span style="color: #0000ff">null</span><span style="color: #000000">);
</span><span style="color: #008080">17</span> <span style="color: #000000">        }
</span><span style="color: #008080">18</span> <span style="color: #000000">    }
</span><span style="color: #008080">19</span> <span style="color: #000000"> </span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>You can find the solution <a href="https://skydrive.live.com/?cid=e607cef85d62e176&amp;sc=documents&amp;uc=1&amp;id=E607CEF85D62E176%21195#cid=12A8B70137345033&amp;id=12A8B70137345033%21119">in my SkyDrive account</a>, under the name <strong>WCFServiceAgentSample</strong>. This code is provided “AS IS” with no warranties and confers no rights.</p>
<p>As a final note, It’s worth mentioning that, to prepare this sample, I checked the following blog post:</p>
<ul>
<li><a href="http://weblogs.asp.net/dwahlin/archive/2010/12/20/wcf-ria-services-domaincontext-abstraction-strategies-say-that-10-times.aspx">WCF RIA Services DomainContext Abstraction Strategies–Say That 10 Times!</a></li>
</ul>
<p>Even though I created a sample using a plain WCF service in Prism, the idea can be extrapolated to WCF RIA Services, using as well the abstraction strategies proposed in Dan Wahlin’s post.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Authentication and role based authorization in Prism v4</title>
		<link>http://blogs.southworks.net/gmaliandi/2011/10/authentication-and-role-based-authorization-in-prism-v4/</link>
		<comments>http://blogs.southworks.net/gmaliandi/2011/10/authentication-and-role-based-authorization-in-prism-v4/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 19:38:51 +0000</pubDate>
		<dc:creator>Guido Leandro Maliandi</dc:creator>
				<category><![CDATA[Prism]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Authorization]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/gmaliandi/?p=88</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/gmaliandi/2011/10/authentication-and-role-based-authorization-in-prism-v4/" class="more-link">read more<img src="http://blogs.southworks.net/gmaliandi/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>Hi everybody,</p>
<p>Authentication and authorization are topics that are often discussed in the Prism community (for example, <a href="http://compositewpf.codeplex.com/workitem/7118">this work item</a> or <a href="http://compositewpf.codeplex.com/discussions/265488">this thread</a>), even though the Prism guidance does not provide support for these scenarios.</p>
<p>In this blog post, we will show a possible approach <a href="http://blogs.southworks.net/aadami">Agustin Adami</a> and I thought to achieve authentication and authorization in Prism, by deciding which modules to load depending on the role of an authenticated user.</p>
<p><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://blogs.southworks.net/gmaliandi/files/2011/10/image.png" border="0" alt="image" width="227" height="279" /></p>
<h2>The big picture</h2>
<p>The Solution contains a shell project, three modules and an infrastructure project.</p>
<p><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://blogs.southworks.net/gmaliandi/files/2011/10/image1.png" border="0" alt="image" width="264" height="115" /></p>
<p>The key components of this sample are located in the <strong>AuthenticationModule</strong>, which basically contains:</p>
<ul>
<li>An <strong>Authentication</strong> service, responsible of verifying the password of a user and returning his/her role.</li>
<li>An <strong>Authorization</strong> service, responsible of providing a list of the modules that correspond to a certain role.</li>
<li>A <strong>Login</strong> view, with its corresponding view model, which handles the interactions needed to authenticate a user, and navigates away once authentication is completed.</li>
</ul>
<p>Once a user has been authenticated, the modules corresponding to his/her role are loaded, and the <strong>MainMenu</strong> view is shown. This view contains one button per module, each of which navigates to a view representative of that module.</p>
<p><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://blogs.southworks.net/gmaliandi/files/2011/10/image2.png" border="0" alt="image" width="523" height="293" /></p>
<h2>The implementation</h2>
<p>Both the authentication and authorization services are exported to the container, using interfaces defined in the <strong>Infrastructure</strong> project as the contract type. This allows other components to consume those services without necessarily being aware of the specific implementation used.</p>
<h3>Authentication</h3>
<p>This service provides a method that authenticates asynchronously, and invokes a callback in case it successfully authenticates (indicating the role of the logged user), and a different callback in case it can’t authenticate (indicating the error message).</p>
<p>Additionally, once a user is authenticated, his/her user name is stored in a property of the service. This is intended for other components to depend on this service and consume this information, and then provide a certain degree of customization (for example, showing a welcome text):</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<pre style="width: 900px;height: 180px;background-color: white;overflow: auto">
<div><span style="color: #008080">1</span> <span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">interface</span><span style="color: #000000"> IAuthenticationService
</span><span style="color: #008080">2</span> <span style="color: #000000">{
</span><span style="color: #008080">3</span> <span style="color: #000000">    </span><span style="color: #0000ff">void</span><span style="color: #000000"> Authenticate(</span><span style="color: #0000ff">string</span><span style="color: #000000"> userName, </span><span style="color: #0000ff">string</span><span style="color: #000000"> password, Action</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000"> successCallback, Action</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000"> failureCallback);
</span><span style="color: #008080">4</span> <span style="color: #000000">
</span><span style="color: #008080">5</span> <span style="color: #000000">    </span><span style="color: #0000ff">string</span><span style="color: #000000"> AuthenticatedUserName { </span><span style="color: #0000ff">get</span><span style="color: #000000">; }
</span><span style="color: #008080">6</span> <span style="color: #000000">}</span></div>
</pre>
</div>
<p>It is worth mentioning that in a real scenario it’s likely that the information returned by this service will be more than just the role and the name of the user. We chose to include only that information to keep things simple.</p>
<p>Internally, the implementation of the Authentication Service consumes entities of type <strong>User</strong> from a repository (which in this sample is mocked but might point to, for example, a database).</p>
<h3>Authorization</h3>
<p>This service provides a method that asynchronously obtains a list of module names for a given role:</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<pre style="width: 900px;height: 180px;background-color: white;overflow: auto">
<div><span style="color: #008080">1</span> <span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">interface</span><span style="color: #000000"> IAuthorizationService
</span><span style="color: #008080">2</span> <span style="color: #000000">{
</span><span style="color: #008080">3</span> <span style="color: #000000">    </span><span style="color: #0000ff">void</span><span style="color: #000000"> GetAllowedModules(</span><span style="color: #0000ff">string</span><span style="color: #000000"> role, Action</span><span style="color: #000000">&lt;</span><span style="color: #000000">IList</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000"> callback);
</span><span style="color: #008080">4</span> <span style="color: #000000">} </span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>In the sample, the <strong>Login</strong> view model consumes the information provided by this service, and then uses Prism’s <strong>ModuleManager</strong> to load these modules:</p>
<div class="wlWriterEditableSmartContent" style="margin: 0px;float: none;padding: 0px">
<pre style="width: 900px;height: 470px;background-color: white;overflow: auto">
<div><span style="color: #008080"> 1</span> <span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> LoginSuccess(</span><span style="color: #0000ff">string</span><span style="color: #000000"> roleOfAuthenticatedUser)
</span><span style="color: #008080"> 2</span> <span style="color: #000000">        {
</span><span style="color: #008080"> 3</span> <span style="color: #000000">            </span><span style="color: #0000ff">this</span><span style="color: #000000">.authorizationService.GetAllowedModules(
</span><span style="color: #008080"> 4</span> <span style="color: #000000">                roleOfAuthenticatedUser,
</span><span style="color: #008080"> 5</span> <span style="color: #000000">                modules </span><span style="color: #000000">=&gt;</span><span style="color: #000000">
</span><span style="color: #008080"> 6</span> <span style="color: #000000">                {
</span><span style="color: #008080"> 7</span> <span style="color: #000000">                    LoadCorrespondingModules(modules);
</span><span style="color: #008080"> 8</span> <span style="color: #000000">
</span><span style="color: #008080"> 9</span> <span style="color: #000000">                    (…)
</span><span style="color: #008080">10</span> <span style="color: #000000">                });
</span><span style="color: #008080">11</span> <span style="color: #000000">        }
</span><span style="color: #008080">12</span> <span style="color: #000000">
</span><span style="color: #008080">13</span> <span style="color: #000000">        </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> LoadCorrespondingModules(System.Collections.Generic.IList</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">string</span><span style="color: #000000">&gt;</span><span style="color: #000000"> modules)
</span><span style="color: #008080">14</span> <span style="color: #000000">        {
</span><span style="color: #008080">15</span> <span style="color: #000000">            </span><span style="color: #0000ff">foreach</span><span style="color: #000000"> (var module </span><span style="color: #0000ff">in</span><span style="color: #000000"> modules)
</span><span style="color: #008080">16</span> <span style="color: #000000">            {
</span><span style="color: #008080">17</span> <span style="color: #000000">                </span><span style="color: #0000ff">this</span><span style="color: #000000">.moduleManager.LoadModule(module);
</span><span style="color: #008080">18</span> <span style="color: #000000">            }
</span><span style="color: #008080">19</span> <span style="color: #000000">        }
</span><span style="color: #008080">20</span> <span style="color: #000000"> </span></div>
</pre>
</div>
<p>Internally, the Authorization Service consumes entities of type <strong>Permission</strong> from a repository (which is mocked in the sample but might point to, for example, a configuration file).</p>
<p>You can download the sample <a href="https://skydrive.live.com/?cid=12A8B70137345033&amp;id=12A8B70137345033%21119#!/?cid=12a8b70137345033&amp;sc=documents&amp;uc=1&amp;id=12A8B70137345033%21119">in my SkyDrive account</a>, under the name <strong>AuthenticationAndRolesSample</strong>. This code is provided “AS IS” with no warranties and confers no rights.</p>
<p>I hope you find this useful!</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Prism modularity differences when using MEF</title>
		<link>http://blogs.southworks.net/gmaliandi/2011/08/prism-modularity-differences-when-using-mef/</link>
		<comments>http://blogs.southworks.net/gmaliandi/2011/08/prism-modularity-differences-when-using-mef/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 18:14:39 +0000</pubDate>
		<dc:creator>Guido Leandro Maliandi</dc:creator>
				<category><![CDATA[Prism]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[MEF]]></category>
		<category><![CDATA[Modularity]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/gmaliandi/?p=81</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/gmaliandi/2011/08/prism-modularity-differences-when-using-mef/" class="more-link">read more<img src="http://blogs.southworks.net/gmaliandi/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>When developing applications with Prism, there are certain differences between using Unity and MEF, essentially because MEF provides the possibility of using declarative attributes to export types to the container. So in this post I’ll analyze a curious example of these differences: the <strong>MarketModule</strong> of the Prism <a href="http://msdn.microsoft.com/en-us/library/ff921074%28PandP.40%29.aspx">StockTrader Reference Implementation</a>.</p>
<p>In the Prism-v2 version of the StockTrader RI (which uses Unity), certain interface mappings for common services are registered in the container and certain views are placed inside regions in the <strong>MarketModule</strong>’s <strong>Initialize</strong> method, as shown in the code below:</p>
<pre><span style="font-size: x-small"><span><span style="color: #0000ff">public</span></span><span style="color: #000000"> </span><span><span style="color: #0000ff">void</span></span></span><span style="font-size: x-small"><span style="color: #000000"> Initialize()
        {
            RegisterViewsAndServices();

            </span><span><span style="color: #0000ff">this</span></span><span style="color: #000000">.regionManager.RegisterViewWithRegion(RegionNames.ResearchRegion,</span></span></pre>
<pre><span style="font-size: x-small"><span style="color: #000000"> () =&gt; </span><span><span style="color: #0000ff">this</span></span></span><span style="font-size: x-small"><span style="color: #000000">.container.Resolve&lt;ITrendLinePresentationModel&gt;().View);
        }

        </span><span><span style="color: #0000ff">protected</span></span><span style="color: #000000"> </span><span><span style="color: #0000ff">void</span></span></span><span style="font-size: x-small"><span style="color: #000000"> RegisterViewsAndServices()
        {
            container.RegisterType&lt;IMarketHistoryService, MarketHistoryService&gt;(</span><span><span style="color: #0000ff">new</span></span></span><span style="font-size: x-small"><span style="color: #000000"> ContainerControlledLifetimeManager());
            container.RegisterType&lt;IMarketFeedService, MarketFeedService&gt;(</span><span><span style="color: #0000ff">new</span></span></span><span style="color: #000000;font-size: x-small"> ContainerControlledLifetimeManager());
            container.RegisterType&lt;ITrendLineView, TrendLineView&gt;();
            container.RegisterType&lt;ITrendLinePresentationModel, TrendLinePresentationModel&gt;();
        }</span></pre>
<p>Therefore, the <strong>MarketModule</strong> class must inherit from <strong>IModule</strong>, so that the <strong>Initialize</strong> method is called as soon as the module is loaded.</p>
<p>However, in the Prism-v4 version of the StockTrader RI (which uses MEF), the <strong>MarketModule</strong> class is an empty placeholder which doesn’t even implement the <strong>IModule </strong>interface, which might seem strange at first sight. This is because, as explained in the class’s summary, every view and service present in the market module is discovered through the use of declarative attributes, such as the <strong>Export</strong> attribute for services, or the custom <strong>ViewExport</strong> attribute to register views in regions (which works in the the same way as calling the <strong>RegisterViewWithRegion</strong> method). Below you can find the class’s summary, which explains this situation:</p>
<blockquote><p>This module is intentionally left empty because views, services, and other types are discovered through declarative attributes.</p>
<p>View registration for this module is done through the ViewExportAttribute.</p>
<p>If you extend this reference implementation and need to initialization when this module is loaded, uncomment the module export attribute, IModule interface, Initialize method.</p></blockquote>
<p>I believe this is a good example that portrays the idea that Prism is a set of Guidance that can be used and modified to suit specific needs, and not a strict rule set to develop applications.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to prevent Region Navigation from hiding exceptions in Prism</title>
		<link>http://blogs.southworks.net/gmaliandi/2011/08/how-to-prevent-region-navigation-from-hiding-exceptions-in-prism/</link>
		<comments>http://blogs.southworks.net/gmaliandi/2011/08/how-to-prevent-region-navigation-from-hiding-exceptions-in-prism/#comments</comments>
		<pubDate>Fri, 19 Aug 2011 13:05:51 +0000</pubDate>
		<dc:creator>Guido Leandro Maliandi</dc:creator>
				<category><![CDATA[Prism]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Navigation]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/gmaliandi/?p=74</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/gmaliandi/2011/08/how-to-prevent-region-navigation-from-hiding-exceptions-in-prism/" class="more-link">read more<img src="http://blogs.southworks.net/gmaliandi/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>There’s a behavior in Prism Region Navigation which might cause some confusion for those that aren’t used to it: a navigation request that leads to an error doesn’t throw an exception, but rather the navigation request stops and the exception apparently vanishes.</p>
<p>This is because, instead of throwing an exception, the <strong>RegionNavigationService</strong> exposes a <strong>NavigationFailed</strong> event which is raised in case an error occurs when attempting to navigate to a view in a region. This can be evidenced by this fragment of the <strong>ExecuteNavigate</strong> method, which is called inside the <strong>NavigationService</strong> when a navigation operation is requested:</p>
<pre><span style="color: #000000"><span> </span></span><span style="font-size: small"><span><span style="color: #0000ff">private</span></span><span style="color: #000000"> </span><span><span style="color: #0000ff">void</span></span><span style="color: #000000"> ExecuteNavigation(
NavigationContext navigationContext, </span><span><span style="color: #0000ff">object</span></span></span><span style="font-size: small"><span style="color: #000000">[] activeViews,
 Action&lt;NavigationResult&gt; navigationCallback)
        {
            </span><span><span style="color: #0000ff">try</span></span>
</span><span style="font-size: small"><span style="color: #000000">            {
                NotifyActiveViewsNavigatingFrom(navigationContext, activeViews);

                </span><span><span style="color: #0000ff">object</span></span><span style="color: #000000"> view = </span><span><span style="color: #0000ff">this</span></span><span style="color: #000000">.regionNavigationContentLoader.LoadContent(</span><span><span style="color: #0000ff">this</span></span></span><span style="font-size: small"><span style="color: #000000">.Region, navigationContext);

                </span><span><span style="color: #008000">// Raise the navigating event just before activing the view.</span></span>
<span style="color: #000000">                </span><span><span style="color: #0000ff">this</span></span></span><span style="font-size: small"><span style="color: #000000">.RaiseNavigating(navigationContext);

                </span><span><span style="color: #0000ff">this</span></span></span><span style="font-size: small"><span style="color: #000000">.Region.Activate(view);

</span><span style="color: #000000">                (...)</span></span><span style="font-size: small"><span style="color: #000000">            </span></span></pre>
<pre><span style="font-size: small"><span style="color: #000000">        }
            </span><span><span style="color: #0000ff"><strong>catch</strong></span></span></span><span style="font-size: small"><strong><span style="color: #000000"> (Exception e)
            {
                </span><span><span style="color: #0000ff">this</span></span></strong></span><span style="color: #000000;font-size: small"><strong>.NotifyNavigationFailed(navigationContext, navigationCallback, e);
            }</strong>
        }</span></pre>
<p>Therefore, a possible way to avoid this from happening is to subscribe to the <strong>NavigationFailed</strong> event in the corresponding <strong>NavigationService</strong> instance, and perform the desired operations in response to that error in the handler for that event. The <strong>NavigationService</strong> instance can be found as a property of the <strong>Region</strong> involved in the navigation request.</p>
<p>Additionally, in case this behavior isn’t comfortable for your scenario, you can modify the Prism Library to make it actually throw an exception, in the catch block inside the aforementioned method for example.</p>
<p>You can find more information about Prism Region Navigation in this post from Karl Shifflett:</p>
<h5><a href="http://blogs.msdn.com/b/kashiffl/archive/2010/10/04/prism-v4-region-navigation-pipeline.aspx">Prism v4 Region Navigation Pipeline</a></h5>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prism Training Kit 4.0 is Out!</title>
		<link>http://blogs.southworks.net/gmaliandi/2010/11/prism-training-kit-4-0-is-out/</link>
		<comments>http://blogs.southworks.net/gmaliandi/2010/11/prism-training-kit-4-0-is-out/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 18:06:42 +0000</pubDate>
		<dc:creator>Guido Leandro Maliandi</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Developer Experience]]></category>
		<category><![CDATA[Guidance]]></category>
		<category><![CDATA[MEF]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[Programming Practices]]></category>
		<category><![CDATA[Training Kits]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Training Kit]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/gmaliandi/?p=55</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/gmaliandi/2010/11/prism-training-kit-4-0-is-out/" class="more-link">read more<img src="http://blogs.southworks.net/gmaliandi/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>As you probably read in <a href="../../matiasb/2010/11/16/prism-training-kit-updated-to-prism-4-0/">this  post</a>, we’ve been working on the <a href="http://prismtk.codeplex.com/">Prism  Training kit</a> this past week. This update took place after the <a href="../../dpoza/2010/11/15/prism-4-0-released/">official  release of Prism 4.0</a> and the enthusiasm around it.</p>
<p>Now with <a href="http://blogs.southworks.net/dschenkelman/">Damian</a>, <a href="http://blogs.southworks.net/matiasb/">Matias</a>, <a href="http://blogs.southworks.net/dpoza/">Diego </a>and <a href="http://blogs.southworks.net/ejadib/">Ezequiel</a> we’ve released <a href="http://prismtk.codeplex.com/releases/56048/download/169718">Prism Traning Kit 4.0</a>, with the pre-existing labs updated to Prism 4.0, bug fixes from the first version and two new labs  addressing Prism 4 new features:</p>
<div>
<li>Managed Extensibility Framework (MEF) with Prism Applications.</li>
<li>Prism Navigation Framework.</li>
<p>We’ve made such a major version leap (even bigger than Prism’s! <a href="http://blogs.southworks.net/gmaliandi/files/2010/11/wlEmoticon-smile.png"><img class="alignnone size-full wp-image-53" src="http://blogs.southworks.net/gmaliandi/files/2010/11/wlEmoticon-smile.png" alt="" width="19" height="19" /></a>)  to reflect more accurately that the training kit is now addressing the latest  features from Prism, providing an easy way to learn and obtain resources to more  effectively build <em>modular</em> <em>composite client applications</em>.</p>
<h2>What’s Prism?</h2>
<p>For those of you who are just starting with this, Prism is a set of guidance for building rich, flexible and easy to maintain  applications with WPF and Silverlight (including Windows Phone 7), using design  patterns that help to build applications using loosely coupled components that  can evolve independently but which can be seamlessly integrated into the overall  application (which are thus commonly referred to as <em>composite  applications</em>).</p>
<p>In the latest release, the following features have been included:</p>
<ul>
<li>MEF support</li>
<li>MVVM guidance</li>
<li>Navigation support</li>
<li>A Prism version for Windows Phone 7</li>
</ul>
<h2>Managed Extensibility Framework</h2>
<p>The <a href="http://mef.codeplex.com/">Managed Extensibility Framework  (MEF)</a> is a new library in .NET Framework 4 and Silverlight 4 that simplifies  the design of extensible applications and components. Prism makes use of MEF to  leverage the Dependency Injection pattern, using MEF</p>
<p>to compose components that are required throughout the application.</p>
<p>The <strong>MEF Lab</strong> walks you through the following scenarios:</p>
<ul>
<li>Loading modules using MEF catalogs</li>
<li>Registering views through the use of MEF</li>
<li>Loading modules remotely on-demand</li>
<li>Monitoring download progress of modules</li>
</ul>
<p><img class="alignnone size-large wp-image-62" src="http://blogs.southworks.net/gmaliandi/files/2010/11/MEF-LAB1-690x601.png" alt="MEF LAB" width="613" height="533" /></p>
<h2>Region Navigation</h2>
<p>As the user interacts with a rich client application, its user interface will  be continuously updated to reflect the current task the user is working on. The  UI may undergo considerable changes over time as the user interacts with it. The  process by which the application coordinates these UI changes is often referred  to as <em>navigation</em>. Prism leverages this scenario by extending the region  mechanism to support navigation.</p>
<p>The <strong>Navigation Lab</strong> covers the following scenarios:</p>
<ul>
<li>Basic navigation</li>
<li>Passing parameters during navigation</li>
<li>Confirming/canceling navigation</li>
<li>Using the navigation journal</li>
</ul>
<p><img class="alignnone size-full wp-image-63" src="http://blogs.southworks.net/gmaliandi/files/2010/11/Nav-Lab.png" alt="Navigation Lab" width="553" height="624" /></p>
<p>Hope you find this helpful to learn and use Prism. Any feedback is highly  appreciated!</p>
</div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My thoughts on developer experience</title>
		<link>http://blogs.southworks.net/gmaliandi/2010/11/my-thoughts-on-developer-experience/</link>
		<comments>http://blogs.southworks.net/gmaliandi/2010/11/my-thoughts-on-developer-experience/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 19:22:58 +0000</pubDate>
		<dc:creator>Guido Leandro Maliandi</dc:creator>
				<category><![CDATA[Culture]]></category>
		<category><![CDATA[Developer Experience]]></category>
		<category><![CDATA[People]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/gmaliandi/?p=42</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/gmaliandi/2010/11/my-thoughts-on-developer-experience/" class="more-link">read more<img src="http://blogs.southworks.net/gmaliandi/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>On this post I’ll write about an interesting tendency I’ve seen in Microsoft technologies. My impression is that, as technology advances, efforts are put not only in achieving the possibility of great technical prowess but also on simplifying the development of software.</p>
<p><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/gmaliandi/files/2010/11/Untitled.png" border="0" alt="Untitled" width="404" height="264" /></p>
<p>A recent example that illustrates this is the release of <a href="http://www.microsoft.com/visualstudio/en-us/lightswitch">Visual Studio LightSwitch</a>, which has simplicity as its goal and essence. But perhaps a little bit subtler is the case of the <a href="http://mef.codeplex.com/">Managed Extensibility Framework</a> (MEF), for example, which makes it simpler to build extensible applications and components. Or even the <a href="http://www.microsoft.com/net/">.NET Framework</a> itself, which<em> </em>allows developers to<em> “apply common skills across a variety of devices, application types, and programming tasks</em>”.</p>
<p>Nowadays I think it’s quite known that user experience is a key aspect of software development, and understanding that has made a difference in putting technology at the reach of several people, not only technical users. Without a focus on user experience, things like <a href="http://blogs.msdn.com/b/alexbarn/archive/2005/10/08/478598.aspx">this</a> wouldn’t be possible.</p>
<p>But the same principle applies to developers, I believe. As the means to build applications become simpler to use and repetitive or tedious tasks are taken care of by guidance, tools and frameworks, not only the number of developers grow, but also it is possible for us to dedicate more time to important aspects of software development (<em>such as user experience, I would say</em>).</p>
<p>I don’t think it’s a matter of capacity; it’s not that it is impossible to develop great software the hard way. In fact, some times that’s the only possible way. But by having  a <em>developer experience-</em>oriented platform, we can do more in the same time, and focus on what’s really decisive in terms of business needs.</p>
<p>However, I strongly believe it’s important not to sacrifice critical aspects of software development such as performance, transparency, among others. In the end, I believe successful technologies will tend to feature a balance between them.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Discovering the potential of Windows Presentation Foundation</title>
		<link>http://blogs.southworks.net/gmaliandi/2010/03/discovering-the-potential-of-windows-presentation-foundation/</link>
		<comments>http://blogs.southworks.net/gmaliandi/2010/03/discovering-the-potential-of-windows-presentation-foundation/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 13:58:48 +0000</pubDate>
		<dc:creator>Guido Leandro Maliandi</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[Bookx]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/gmaliandi/?p=35</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/gmaliandi/2010/03/discovering-the-potential-of-windows-presentation-foundation/" class="more-link">read more<img src="http://blogs.southworks.net/gmaliandi/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>The <strong>user interface</strong> is an important aspect of software development that in most cases defines the <strong>first impression</strong> the customer gets of an application. We&#8217;ve seen lots of great software with poor, overly-simple interfaces, or on the contrary, sophisticated ones that sacrifice functionality, intuitiveness and/or efficiency. <strong>Windows Presentation Foundation</strong> (WPF) is Microsoft&#8217;s response to the need of 21th century-worthy user interfaces that are also easy to implement and use.</p>
<p><a href="http://msdn.microsoft.com/es-es/library/aa970268.aspx"><img src="http://blogs.southworks.net/gmaliandi/files/2010/03/image.png" border="0" alt="image" width="570" height="376" /></a></p>
<h2>Why WPF?</h2>
<p>As mentioned in <a href="http://blogs.msdn.com/adam_nathan/">Adam Nathan</a>&#8216;s book &#8216;<a href="http://www.amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917">Windows Presentation Foundation Unleashed</a>&#8216;, there are six major benefits WPF has over the previous Microsoft technologies that shared its purpose (like GDI+, Windows Forms):</p>
<ul>
<li><strong>Broad integration</strong>. WPF integrates all the necessary technologies for developing 2D, 3D, audio, video, rich documents, and so forth, avoiding the need to learn, and implement several independent technologies.</li>
<li><strong>Resolution independence</strong>. Due to the emphasis on vector graphics, WPF applications can be resolution independent, and contents of an application can automatically resize when the application itself resizes.</li>
<li><strong>Hardware acceleration</strong>. Since WPF is built on top of Direct3D, everything from 3D graphics to text gets rendered by hardware, making every application -not only games- benefit from powerful video cards. However, if no powerful hardware is present, WPF still has a software rendering pipeline so that the hardware isn&#8217;t a <em>requirement</em> for WPF applications to run.</li>
<li><strong>Declarative programming</strong>. The use of <a href="http://msdn.microsoft.com/en-us/library/ms747122.aspx">Extensible Application Markup Language</a> (XAML) in WPF makes it possible to leverage the use of declarative programming to an incredible level of expressiveness, enabling graphic designers to contribute to not only the look and feel of the application, but also some behavior that is usually coded by developers.</li>
<li><strong>Rich composition and customization</strong>. WPF controls are extremely customizable, so it is possible to dramatically alter the looks of any control without affecting its functionality.</li>
<li><strong>Easy deployment</strong>. WPF provides support for deploying Windows applications through Windows Installer or ClickOnce, and even hosting them in a web browser (although the browser must be IE7 or further).</li>
</ul>
<p>An interesting fact about WPF is that, apart from being part of the .Net Framework and designed <em>for</em> managed code, it is also implemented largely <em>in</em> managed code.</p>
<h2>XAML</h2>
<p>The introduction of this new markup language greatly simplifies the creation of a UI for the .NET framework, as it enables the use of declarative markup that <em>directly represent the instantiation of managed objects</em>, which can be later referenced through code-behind files. This is achieved by using partial class definitions; the window class is defined as a partial class when a window is created in XAML, and it&#8217;s explicitly defined as a partial class in the code-behind file.</p>
<p>This approach makes it possible to separate the UI runtime logic from the UI definition itself, which is an extraordinary benefit for making <em>extensible</em>, <em>modular</em> applications, especially if design patterns such as the ones facilitated by <a href="http://msdn.microsoft.com/en-us/practices/default.aspx">Prism</a> are used.</p>
<h2>Customization &amp; Simplicity</h2>
<p>At first sight, WPF may not seem easy to learn, since it introduces a lot of new concepts. But it has what I think is absolutely essential for any technology: it enables an extreme degree of <strong>customization</strong>, while keeping the <strong>simplicity</strong> of default values prepared for the most common scenarios. While I think both are very important, it&#8217;s not uncommon to see a technology sacrificing one to achieve the other. That&#8217;s what I think WPF accomplishes greatly, and I realize a lot of emphasis has been put in combining those two aspects. An example of this is the use of <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.controltemplate.aspx">ControlTemplates</a>: controls have a default template that defines their most usual appearance (such as a button being the typical grey rectangle we all know), but a custom template can be applied to <em>completely redefine the way they look</em> without altering, however, how they behave.</p>
<p><img src="http://blogs.southworks.net/gmaliandi/files/2010/03/image1.png" border="0" alt="image" width="312" height="111" /></p>
<p>As for the learning curve, once you&#8217;ve grasped the main new concepts introduced in WPF (that is, the theory), everything else is really straightforward, and the initial overhead of learning those concepts is greatly compensated by the simplicity of creating applications with it.</p>
<p>Although XAML syntax may seem a little bit confusing at first sight, integration with Visual Studio and tools like <a href="http://www.microsoft.com/expression/products/Blend_Overview.aspx">Expression Blend</a> makes it easy to develop applications without being an expert at all: just having an idea of what WPF is about is enough to start learning by trial and error and discover the whole new set of possibilities this technology offers!</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
