<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.southworks.net/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Damian Schenkelman</title>
	
	<link>http://blogs.southworks.net/dschenkelman</link>
	<description />
	<lastBuildDate>Fri, 08 Feb 2013 03:40:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.southworks.net/dschenkelman" /><feedburner:info uri="dschenkelman" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>To Arrow Function or not to Arrow Function</title>
		<link>http://feeds.southworks.net/~r/dschenkelman/~3/F7fenlmEke4/</link>
		<comments>http://blogs.southworks.net/dschenkelman/2013/02/08/to-arrow-function-or-not-to-arrow-function/#comments</comments>
		<pubDate>Fri, 08 Feb 2013 03:35:31 +0000</pubDate>
		<dc:creator>Damian Schenkelman</dc:creator>
				<category><![CDATA[Emerging Technology]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[TypeScript]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/dschenkelman/?p=391</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/dschenkelman/2013/02/08/to-arrow-function-or-not-to-arrow-function/" class="more-link">read more<img src="http://blogs.southworks.net/dschenkelman/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>If you have used TypeScript you are probably aware of the compiled outcome of an Arrow Function (section 4.9.2 of the <a href="http://www.typescriptlang.org/Content/TypeScript%20Language%20Specification.pdf">TypeScript Language Specification</a>). The idea behind using <strong>() =&gt; {…};</strong> instead of <strong>function(){…};</strong> is to have access to the object represented by <em>this</em> in the outer scope, which is what you would expect when using a C# lambda. Of course this feature is particulalry useful in JavaScript because <a href="http://es5.github.com/#x10.4.3"><em>this</em> holds a reference to the object to which a function was applied or called</a>, and more often than not the <em>this </em>inside the function&#8217;s <a href="http://davidshariff.com/blog/what-is-the-execution-context-in-javascript/">execution context</a> ends up being different from the one in the outer execution context.</p>
<p>When using an Arrow Function, TypeScript automatically assigns <em>this </em>to a separate variable in the outer execution context (called <em>_this),</em> which can be accessed by the function that results of the compilation of the Arrow Function through its closure. As the previous sentence was probably not the simplest one to digest, take the following TypeScript code snippet as an example:</p>
<pre class="brush: js;">class MyClass {
    constructor() {
    }

    private add(a, b) {
        return a + b;
    }

    public partialAdd(a) {
        return (b) =&gt; {
            return this.add(a, b);
        }
    }

    public partialAdd2(a) {
        return function(b) {
            return this.add(a, b);
        }
    }
}</pre>
<p>The resulting JavaScript is:</p>
<pre class="brush: js;">var MyClass = (function () {
    function MyClass() {
    }
    MyClass.prototype.add = function (a, b) {
        return a + b;
    };
    MyClass.prototype.partialAdd = function (a) {
        var _this = this;
        return function (b) {
            return _this.add(a, b);
        }
    };
    MyClass.prototype.partialAdd2 = function (a) {
        return function (b) {
            return this.add(a, b);
        }
    };
    return MyClass;
})();</pre>
<p>As you can see, partialAdd stores <em>this </em>in the local <em>_this</em> variable which is accessible from the function that is returned through its closure. On the other hand, partialAdd2 uses <em>this </em>as the variable, but as I mentioned before <em>this</em> might not be &#8220;an instance of MyClass&#8221; but something completely different instead.</p>
<h2>Complex Cases</h2>
<p>You could (wrongly) deduce that every time you need access to the outer <em>this</em> inside the function you should use an Arrow Function, but what if you need to use both the outer <em>this </em>and the object on which the function was applied? That could be a usual situation in an event handler, <a href="http://api.jquery.com/click/">which applies the callback functions to the target DOM elements when handling the event</a> (for the sake of the example assume that there is no way to other way to access the DOM element other than <em>this</em>).</p>
<p>In these cases, it is important to understand what the compiler is doing underneath the hood. The two common approaches that would lead to errors are:</p>
<ol>
<li><strong>Using an Arrow Function:</strong> this would cause TypeScript&#8217;s <em>this </em>to shadow the compiled JavaScript&#8217;s <em>this</em>, not allowing you to access the DOM elements that was clicked inside the click handler.</li>
<li><strong>Using a function literal: </strong>this would cause the outer <em>this</em> to not be accessible, which is unexpected for developers used to C#.</li>
</ol>
<h2>The Answer</h2>
<p>One possible (and simple) solution to this is the usual workaround (<em>that = this</em>):</p>
<pre class="brush: js;">class MyClass {
    constructor() {
    }

    private add(a, b) {
        return a + b;
    }

    public partialAdd(a) {
        var that = this;
        return function(b) {
            // this is accessible inside the function
            // and points to the object to which the function was applied
            var _this = this;
            // that is accessible inside the function through the closure
            // and points to the object that had partialAdd called
            return that.add(a, b);
        }
    }
}</pre>
<p>The following figures show that TypeScript&#8217;s type inference system confirms the comments from the previous code snippet:</p>
<p><em>this can be an instance of any type, as it depends on the object on which the function was called</em></p>
<p><a href="http://blogs.southworks.net/dschenkelman/files/2013/02/image2.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/dschenkelman/files/2013/02/image_thumb2.png" border="0" alt="image" width="494" height="247" /></a></p>
<p><em>that is an instance of MyClass</em></p>
<p><a href="http://blogs.southworks.net/dschenkelman/files/2013/02/image3.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/dschenkelman/files/2013/02/image_thumb3.png" border="0" alt="image" width="502" height="247" /></a></p>
<h2>Conclusion</h2>
<p>This is not a complex issue, but is one that I&#8217;ve seen a couple of times while working with TypeScript, so hopefully if you ever run into it you will be able to solve it in no time.</p>
<img src="http://feeds.feedburner.com/~r/dschenkelman/~4/F7fenlmEke4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogs.southworks.net/dschenkelman/2013/02/08/to-arrow-function-or-not-to-arrow-function/</feedburner:origLink></item>
		<item>
		<title>Creating Indexes via Data Annotations with Entity Framework 5.0</title>
		<link>http://feeds.southworks.net/~r/dschenkelman/~3/3JZTwOuq9hU/</link>
		<comments>http://blogs.southworks.net/dschenkelman/2012/08/18/creating-indexes-via-data-annotations-with-entity-framework-5-0/#comments</comments>
		<pubDate>Sat, 18 Aug 2012 15:44:39 +0000</pubDate>
		<dc:creator>Damian Schenkelman</dc:creator>
				<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Entity Framework Code First]]></category>
		<category><![CDATA[SQL Indexes]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/dschenkelman/?p=371</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/dschenkelman/2012/08/18/creating-indexes-via-data-annotations-with-entity-framework-5-0/" class="more-link">read more<img src="http://blogs.southworks.net/dschenkelman/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>This week, for a project at Southworks, my friend <a href="http://blogs.southworks.net/mconverti/">Mariano Converti</a> and I had to create indexes in a SQL database for two string type properties of entities that were part of an <a href="http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx">Entity Framework Code First</a> model. As we were also required to support changes to the model after the application was deployed, we decided to use <a href="http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx">Entity Framework Code Base Migrations</a>.</p>
<p>This approach successfully satisfied our requirements, but it required us to add additional migrations to specify the indexes. Thus, I started to research to see if there where other ways to do this, thinking that there was probably an available data annotation to get this done. To my surprise, I wasn&#8217;t able to find such an attribute when searching the web (for example, this is the list of <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.aspx">available Data Annotations</a>). Once I realized this, I decided to create the necessary components on my own.</p>
<table style="border:1px">
<tbody>
<tr>
<td><strong>Update: </strong>After a quick twitter discussion with <a href="http://thedatafarm.com/blog/">@julielerman</a>, I decided to be more specific as to why I think using an attribute is better than code first migrations:</p>
<ol>
<li>Code first migrations create a class per migration which results in too many classes. While developing your model changes a lot, so having to create an extra class whenever you discover that you want to add an index is not really confortable (once you have deployed to production however, migrations are probably the way to go).</li>
<li>Attributes are more descriptive. By just looking at the entity you can determine the indexes that will be created for it, without the need to check a separate class&#8217; code.</li>
</ol>
</td>
</tr>
</tbody>
</table>
<h2>Creating the components</h2>
<p>I found a couple of StackOverflow questions (<a href="http://stackoverflow.com/questions/4995642/add-index-with-entity-framework-code-first-ctp5">here</a> and <a href="http://stackoverflow.com/questions/8262590/entity-framework-code-first-fluent-api-adding-indexes-to-columns">here</a>) from where I got some really useful ideas, such as using the <a href="http://msdn.microsoft.com/en-us/library/system.data.entity.database.executesqlcommand%28VS.103%29.aspx">ExecuteSqlCommand</a> method introduced in Entity Framework 4.1 and detecting the attributes in a <a href="http://msdn.microsoft.com/en-us/library/gg696323%28VS.103%29.aspx">DataBaseInitializer</a>.</p>
<p>The attribute code is really simple. It forces you to define the index name and gives the possibility of specifying whether the index is unique or not.</p>
<pre class="brush: csharp;">using System;

[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
public class IndexAttribute : Attribute
{
    public IndexAttribute(string name, bool unique = false)
    {
        this.Name = name;
        this.IsUnique = unique;
    }

    public string Name { get; private set; }

    public bool IsUnique { get; private set; }
}</pre>
<p>And the Initializer basically goes through the <a href="http://msdn.microsoft.com/en-us/library/gg696460%28VS.103%29.aspx">DbSet&lt;&gt;</a> properties in the <a href="http://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext%28VS.103%29.aspx">DbContext</a> to retrieve the entity table names and check for the Index attribute in the properties in those entities.</p>
<pre class="brush: csharp;">using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Reflection;

public class IndexInitializer&lt;T&gt; : IDatabaseInitializer&lt;T&gt; where T : DbContext
{
    private const string CreateIndexQueryTemplate = "CREATE {unique} INDEX {indexName} ON {tableName} ({columnName})";

    public void InitializeDatabase(T context)
    {
        const BindingFlags PublicInstance = BindingFlags.Public | BindingFlags.Instance;

        foreach (var dataSetProperty in typeof(T).GetProperties(PublicInstance).Where(
            p =&gt; p.PropertyType.Name == typeof(DbSet&lt;&gt;).Name))
        {
            var entityType = dataSetProperty.PropertyType.GetGenericArguments().Single();

            TableAttribute[] tableAttributes = (TableAttribute[])entityType.GetCustomAttributes(typeof(TableAttribute), false);

            foreach (var property in entityType.GetProperties(PublicInstance))
            {
                IndexAttribute[] indexAttributes = (IndexAttribute[])property.GetCustomAttributes(typeof(IndexAttribute), false);
                NotMappedAttribute[] notMappedAttributes = (NotMappedAttribute[])property.GetCustomAttributes(typeof(NotMappedAttribute), false);
                if (indexAttributes.Length &gt; 0 &amp;&amp; notMappedAttributes.Length == 0)
                {
                    ColumnAttribute[] columnAttributes = (ColumnAttribute[])property.GetCustomAttributes(typeof(ColumnAttribute), false);

                    foreach (var indexAttribute in indexAttributes)
                    {
                        string indexName = indexAttribute.Name;
                        string tableName = tableAttributes.Length != 0 ? tableAttributes[0].Name : dataSetProperty.Name;
                        string columnName = columnAttributes.Length != 0 ? columnAttributes[0].Name : property.Name;
                        string query = CreateIndexQueryTemplate.Replace("{indexName}", indexName)
                            .Replace("{tableName}", tableName)
                            .Replace("{columnName}", columnName)
                            .Replace("{unique}", indexAttribute.IsUnique ? "UNIQUE" : string.Empty);

                        context.Database.CreateIfNotExists();

                        context.Database.ExecuteSqlCommand(query);
                    }
                }
            }
        }
    }
}</pre>
<h2>Trying it out</h2>
<p>I created a simple console application and ran a couple of tests to see if the data base was correctly created. For example, when using the following entity:</p>
<pre class="brush: csharp;">using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

public class Customer
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public Guid Id { get; set; }

    [Index("NameIndex", unique: true)]
    [MaxLength(128)]
    public string Name { get; set; }
}</pre>
<p>The following table is created.</p>
<p><a href="http://blogs.southworks.net/dschenkelman/files/2012/08/image.png"><img style="margin: 0px;padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://blogs.southworks.net/dschenkelman/files/2012/08/image_thumb.png" border="0" alt="image" width="244" height="196" /></a></p>
<p>If, for example the Table and Column name are customized:</p>
<pre class="brush: csharp;">[Table("Clients")]
public class Customer
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public Guid Id { get; set; }

    [Index("NameIndex", unique: true)]
    [MaxLength(128)]
    [Column("CustomerName")]
    public string Name { get; set; }
}</pre>
<p>We get the following index:</p>
<p><a href="http://blogs.southworks.net/dschenkelman/files/2012/08/image1.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://blogs.southworks.net/dschenkelman/files/2012/08/image_thumb1.png" border="0" alt="image" width="425" height="214" /></a></p>
<h2>What if I already have an Initializer?</h2>
<p>Well, in this case, a simple approach would be to add the IndexInitializer logic to your own Initializer, but that is not the only way to support the IndexAttribute and keep your initialization logic. During the week I also put together a simple CompositeDatabaseInitializer that can be used to separate the logic in different initializers. You could, for instance, have the IndexInitializer and another one to generate data.</p>
<pre class="brush: csharp;">using System.Collections.Generic;
using System.Data.Entity;

public class CompositeDatabaseInitializer&lt;T&gt; : IDatabaseInitializer&lt;T&gt; where T : DbContext
{
    private readonly List&lt;IDatabaseInitializer&lt;T&gt;&gt; initializers;

    public CompositeDatabaseInitializer(params IDatabaseInitializer&lt;T&gt;[] databaseInitializers)
    {
        this.initializers = new List&lt;IDatabaseInitializer&lt;T&gt;&gt;();
        this.initializers.AddRange(databaseInitializers);
    }

    public void InitializeDatabase(T context)
    {
        foreach (var databaseInitializer in this.initializers)
        {
            databaseInitializer.InitializeDatabase(context);
        }
    }

    public void AddInitializer(IDatabaseInitializer&lt;T&gt; databaseInitializer)
    {
        this.initializers.Add(databaseInitializer);
    }

    public void RemoveInitializer(IDatabaseInitializer&lt;T&gt; databaseInitializer)
    {
        this.initializers.Remove(databaseInitializer);
    }
}</pre>
<h2>Wrapping up</h2>
<p>There are a lot of improvement opportunities for this implementation (such as adding support for clustered indexes). Nevertheless, features such as support for custom database initializers and the ability to execute SQL statements from the DbContext provide really powerful extensibility capabilities.</p>
<p>I hope that you can either use the code as is or take some useful ideas out of it.</p>
<img src="http://feeds.feedburner.com/~r/dschenkelman/~4/3JZTwOuq9hU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://blogs.southworks.net/dschenkelman/2012/08/18/creating-indexes-via-data-annotations-with-entity-framework-5-0/</feedburner:origLink></item>
		<item>
		<title>Microsoft Media Platform Video Editor (former RCE) 2.0 just released</title>
		<link>http://feeds.southworks.net/~r/dschenkelman/~3/D_aYvqdU5lQ/</link>
		<comments>http://blogs.southworks.net/dschenkelman/2011/10/03/microsoft-media-platform-video-editor-former-rce-2-0-just-released/#comments</comments>
		<pubDate>Mon, 03 Oct 2011 16:40:12 +0000</pubDate>
		<dc:creator>Damian Schenkelman</dc:creator>
				<category><![CDATA[Adaptive Streaming]]></category>
		<category><![CDATA[CSM]]></category>
		<category><![CDATA[Composite Application Guidance for WPF & SL]]></category>
		<category><![CDATA[Composite Stream Manifest]]></category>
		<category><![CDATA[Emerging Technology]]></category>
		<category><![CDATA[Live Smooth Streaming]]></category>
		<category><![CDATA[Media]]></category>
		<category><![CDATA[Microsoft Media Platform]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[Prism-v2.2]]></category>
		<category><![CDATA[RCE]]></category>
		<category><![CDATA[Rough Cut Editing]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 5]]></category>
		<category><![CDATA[Smooth Streaming]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/dschenkelman/?p=348</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/dschenkelman/2011/10/03/microsoft-media-platform-video-editor-former-rce-2-0-just-released/" class="more-link">read more<img src="http://blogs.southworks.net/dschenkelman/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>Today, the new version of the Microsoft Media Platform (MMP) Video Editor <a href="http://archive.msdn.microsoft.com/VideoEditor/Release/ProjectReleases.aspx?ReleaseId=5763">was released</a> to the public. The new release is based on Silverlight 5, and has a lot (really a lot!) of new features (fully listed below), such as a UI based on floating windows, and a new Sub-Clip tool which gives editors more control when creating clips.</p>
<p>You can play with the new version at <a href="http://videoeditor.cloudapp.net/">http://videoeditor.cloudapp.net/</a>.</p>
<p>The downloadable packages of the new release are:</p>
<ul>
<li><strong>MMP Video Editor 2.0 Source Code:</strong> Useful in case you want to know how the different features are implemented.</li>
<li><strong>MMP Video Editor 2.0 Binaries:</strong> If you don’t care about the source and just can’t wait to host it.</li>
<li><strong>MMP Video Editor 2.0 Documentation:</strong> Updated documentation, including the <strong>“New Features in the MMP Video Editor 2.0” </strong>that provides a brief overview of the brand new features.</li>
<li><strong>MMP Video Editor 2.0 Overlays &amp; Rubberbanding Plugin Sample:</strong> Two plug-ins for the &#8220;Microsoft Media Platform Player Framework (formerly SMF)&#8221; were created to manage overlays and rubber-banding in CSMs (see new features document). The sample includes the source code for the plug-ins and a sample player that showcases the plug-ins’ capabilities.</li>
</ul>
<h2><a href="http://blogs.southworks.net/dschenkelman/files/2011/10/image2.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/dschenkelman/files/2011/10/image_thumb2.png" border="0" alt="image" width="333" height="211" /></a></h2>
<h2>New Features</h2>
<p>The full list of new features included in this version are:</p>
<ul>
<li>Silverlight 5 based</li>
<li>Out-of-Browser capabilities</li>
<li>Floating Windows</li>
<li>Playback Model: CSM Based</li>
<li>Multiple Sequences</li>
<li>Sub-clip Tool
<ul>
<li>Asset Preview</li>
<li>Multiple Video Cameras selection</li>
<li>Multiple Audio Tracks selection</li>
<li>Metadata Support</li>
</ul>
</li>
<li>Multiple clips selection and locking</li>
<li>Enhanced Overlays Support</li>
<li>Markers and Ads Browser</li>
<li>Rubber banding and multiple audio tracks</li>
<li>Keyboard Layout Configuration</li>
<li>Jog wheel support</li>
</ul>
<p><a href="http://blogs.southworks.net/dschenkelman/files/2011/10/image1.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/dschenkelman/files/2011/10/image_thumb1.png" border="0" alt="image" width="657" height="325" /></a></p>
<p>I recommend you to go over the new features document before you start editing clips, as there are a lot changes in most of the major features of the application.</p>
<p>If you have comments, questions, suggestions or any issue, please visit the <a href="http://archive.msdn.microsoft.com/VideoEditor">MMP Video Editor community site</a>.</p>
<p>We hope enjoy this new version and have a lot of fun editing!!!</p>
<img src="http://feeds.feedburner.com/~r/dschenkelman/~4/D_aYvqdU5lQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blogs.southworks.net/dschenkelman/2011/10/03/microsoft-media-platform-video-editor-former-rce-2-0-just-released/</feedburner:origLink></item>
		<item>
		<title>Needle Container: Fluency and Mapping Types</title>
		<link>http://feeds.southworks.net/~r/dschenkelman/~3/TQH8qJUCN1Q/</link>
		<comments>http://blogs.southworks.net/dschenkelman/2011/07/18/needle-container-fluency-and-mapping-types/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 00:13:51 +0000</pubDate>
		<dc:creator>Damian Schenkelman</dc:creator>
				<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Needle]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/dschenkelman/?p=340</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/dschenkelman/2011/07/18/needle-container-fluency-and-mapping-types/" class="more-link">read more<img src="http://blogs.southworks.net/dschenkelman/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.southworks.net/dschenkelman/2011/02/18/needle-dependency-injection-container-alpha-0-1-version-released/">Back in February</a>, I blogged about <a href="http://needlecontainer.codeplex.com/">Needle</a>, a dependency injection container that I was developing. In that post, I listed some of the most relevant features Needle has, one of them being its Fluent API. I thought it would be a would idea to talk about Needle again, but this time sharing some code and ideas behind it.</p>
<h3>First things first, why do I want fluency?</h3>
<p>This is of course a matter of appreciation, but I personally relate fluency to both ease of use and readability. Interestingly enough one of them is important before writing the code, and the other one after doing so. The idea is that a fluent API will give you a small set of options when performing a particular operation, each of them will be presented at the correct moment, and that once the code has been written, you can explain it to your non-tech grandma.</p>
<h3>Our fluent scenario, mapping types</h3>
<p>A really common operation that needs to be performed when working with DI containers is mapping types, which involves configuring the container to determine the type you want to get when requesting another type. This is commonly used by mapping an interface to a concrete implementation.</p>
<p>Let’s say we have an <strong>IForceEnlightened</strong> interface, and a <strong>Jedi</strong> class which implements that interface. If we wanted to get a <strong>Jedi</strong> whenever we request an instance of <strong>IForceEnlightened </strong>from the container, we can write the following code:</p>
<pre class="brush: csharp;">INeedleContainer needleContainer = new NeedleContainer();
needleContainer
    .Map&lt;IForceEnlightened&gt;() // when we request an IForceEnlightened
    .To&lt;Jedi&gt;() // provide a Jedi
    .Commit(); // save the mapping</pre>
<p>One really important thing about the fluent API is that, in every step of the way, IntelliSense only shows us the relevant members:</p>
<p><a href="http://blogs.southworks.net/dschenkelman/files/2011/07/image.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/dschenkelman/files/2011/07/image_thumb.png" width="440" height="253" /></a></p>
<p><a href="http://blogs.southworks.net/dschenkelman/files/2011/07/image1.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/dschenkelman/files/2011/07/image_thumb1.png" width="530" height="188" /></a></p>
<h3>Transactional Operations</h3>
<p>The Commit() method call might have caught your eye in the previous code sample. This call is necessary, because Needle uses a transactional operation model. When performing a configuration operation with Needle, a committable object is created, which you must commit back to the container for the operation to take place. </p>
<p>This can also be useful in situations where you need to perform a certain configuration in a component, but want to wait until that configuration takes place. In this cases, keeping a reference to the <strong>ICommitable</strong> object until you want the configuration to take place does the trick.</p>
<h3>Each thing by its own name</h3>
<p>Let’s say we have another scenario, in which we could need either a Jedi or a Sith when requesting a force enlightened subject. In this case, the following code would do the trick:</p>
<pre class="brush: csharp;">needleContainer
    .Map&lt;IForceEnlightened&gt;()
    .To&lt;Jedi&gt;()
    .WithId(&quot;Jedi&quot;)
    .Commit();

needleContainer
    .Map&lt;IForceEnlightened&gt;()
    .To&lt;Sith&gt;()
    .WithId(&quot;Sith&quot;)
    .Commit();
</pre>
<p><font face="Helvetica">After that the container will have both mappings, which can be injected into another component using, for example, <a href="http://needlecontainer.codeplex.com/wikipage?title=Constructor%20Injection&amp;referringTitle=Documentation">Constructor</a> or <a href="http://needlecontainer.codeplex.com/wikipage?title=Property%20Injection&amp;referringTitle=Documentation">Property</a> injection.</font></p>
<h3>Lifetime Management</h3>
<p>In case we want to get the same Jedi instance each time we request a force enlightened subject, we can change the default lifetime registration from Transient (a different instance each time we request an <strong>IForceEnlightened</strong> subject)&#160; to Singleton (returns the same instance every time).</p>
<pre class="brush: csharp;">needleContainer
    .Map&lt;IForceEnlightened&gt;()
    .To&lt;Jedi&gt;()
    .UsingLifetime(RegistrationLifetime.Singleton)
    .Commit();</pre>
<p>Singleton registrations are commonly used with services in most applications.</p>
<h3>Putting it all together</h3>
<p>Of course, we can both name and determine the scope of a registration. If we want fast and simple access to Master Yoda (and who doesn’t), we can name the mapping and set its lifetime to Singleton:</p>
<pre class="brush: csharp;">needleContainer
    .Map&lt;IForceEnlightened&gt;()
    .To&lt;Jedi&gt;()
    .WithId(&quot;Yoda&quot;)
    .UsingLifetime(RegistrationLifetime.Singleton)
    .Commit();</pre>
<h3>Wrapping Up</h3>
<p>I hope you found this post fun, and that you try out Needle and its fluent API sometime. You can download Needle from <a href="http://needlecontainer.codeplex.com/releases/view/60894">here</a> or through Nuget:</p>
<pre class="brush: csharp;">PM&gt; Install-Package NeedleContainer</pre>
<p><a rev="vote-for" href="http://dotnetshoutout.com/Needle-Container-Fluency-and-Mapping-Types-Damian-Schenkelman"><img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.southworks.net%2Fdschenkelman%2F2011%2F07%2F18%2Fneedle-container-fluency-and-mapping-types%2F" style="border:0px" /></a></p>
<img src="http://feeds.feedburner.com/~r/dschenkelman/~4/TQH8qJUCN1Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blogs.southworks.net/dschenkelman/2011/07/18/needle-container-fluency-and-mapping-types/</feedburner:origLink></item>
		<item>
		<title>Binding to View Model properties in Data Templates. The RootBinding Markup Extension</title>
		<link>http://feeds.southworks.net/~r/dschenkelman/~3/vWrV4DUs3eE/</link>
		<comments>http://blogs.southworks.net/dschenkelman/2011/06/26/binding-to-view-model-properties-in-data-templates-the-rootbinding-markup-extension/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 17:39:48 +0000</pubDate>
		<dc:creator>Damian Schenkelman</dc:creator>
				<category><![CDATA[Data Binding]]></category>
		<category><![CDATA[Emerging Technology]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[Markup Extensions]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 5]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/dschenkelman/?p=326</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/dschenkelman/2011/06/26/binding-to-view-model-properties-in-data-templates-the-rootbinding-markup-extension/" class="more-link">read more<img src="http://blogs.southworks.net/dschenkelman/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>If you work with Silverlight and MVVM, you must have probably been forced to do some weird thing to bind to a property in your view model (say a Command) from a DataTemplate. Some of the common approaches I have seen and used myself are:</p>
<ul>
<li>Using some kind of binding helper as a View’s resource.</li>
<li>Having a View Model wrap the entity of each collection item, and add the command to the View Model.</li>
</ul>
<p>Although these are perfectly valid approaches, they require extra work compared to the good old {Binding} syntax we are all used to.</p>
<p>Now that Silverlight 5 Beta is out, we can take advantage of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.markupextension(VS.96).aspx">XAML Markup Extensions</a> to help is in this kind of tasks, using a simpler and more intuitive approach.</p>
<p>I have created a <strong>RootBindingExtension</strong>, which can be used as follows:</p>
<pre class="brush: xml;">&lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
    &lt;ListBox ItemsSource=&quot;{Binding Names}&quot;&gt;
        &lt;ListBox.ItemTemplate&gt;
            &lt;DataTemplate&gt;
                &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
                    &lt;TextBlock Text=&quot;{Binding}&quot;/&gt;
                    &lt;Button Content=&quot;{current:RootBinding Path=ButtonContent}&quot; Command=&quot;{current:RootBinding Path=MessageBoxCommand}&quot;/&gt;
                &lt;/StackPanel&gt;
            &lt;/DataTemplate&gt;
        &lt;/ListBox.ItemTemplate&gt;
    &lt;/ListBox&gt;
&lt;/Grid&gt;</pre>
<p>The <strong>RootBindingExtension </strong>uses the <strong>Path</strong> property to create a Binding that binds to a property of that name in the View’s <strong>DataContext</strong>.</p>
<pre class="brush: csharp;">public class RootBindingExtension : IMarkupExtension&lt;Binding&gt;
{
    public string Path { get; set; }

    public Binding ProvideValue(IServiceProvider serviceProvider)
    {
        IRootObjectProvider rootProvider = (IRootObjectProvider) serviceProvider.GetService(typeof(IRootObjectProvider));

        var view = rootProvider.RootObject;
        var fe = view as FrameworkElement;

        if (fe == null)
        {
            throw new InvalidOperationException(&quot;Root element must have data context&quot;);
        }

        var binding = new Binding();
        binding.Path = new PropertyPath(this.Path);
        binding.Source = fe.DataContext;

        return binding;
    }
}</pre>
<p>You can download the RootBindingExtension and a sample that uses it from <a href="https://skydrive.live.com/#!/?cid=09f63fc7ac065e5e&amp;sc=documents&amp;nl=1&amp;uc=2&amp;id=9F63FC7AC065E5E%21215">here</a>.</p>
<p>Let me know if you have used it.</p>
<p><a rev="vote-for" href="http://dotnetshoutout.com/Binding-to-View-Model-properties-in-Data-Templates-The-RootBinding-Markup-Extension-Damian-Schenkelman"><img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.southworks.net%2Fdschenkelman%2F2011%2F06%2F26%2Fbinding-to-view-model-properties-in-data-templates-the-rootbinding-markup-extension%2F" style="border:0px" /></a></p>
<img src="http://feeds.feedburner.com/~r/dschenkelman/~4/vWrV4DUs3eE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://blogs.southworks.net/dschenkelman/2011/06/26/binding-to-view-model-properties-in-data-templates-the-rootbinding-markup-extension/</feedburner:origLink></item>
		<item>
		<title>Microsoft Media Platform Video Editor SP2 Released</title>
		<link>http://feeds.southworks.net/~r/dschenkelman/~3/rvNoWYcQi18/</link>
		<comments>http://blogs.southworks.net/dschenkelman/2011/06/01/microsoft-media-platform-video-editor-sp2-released/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 12:56:08 +0000</pubDate>
		<dc:creator>Damian Schenkelman</dc:creator>
				<category><![CDATA[Adaptive Streaming]]></category>
		<category><![CDATA[CSM]]></category>
		<category><![CDATA[Composite Stream Manifest]]></category>
		<category><![CDATA[Live Smooth Streaming]]></category>
		<category><![CDATA[Media]]></category>
		<category><![CDATA[Microsoft Media Platform]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[RCE]]></category>
		<category><![CDATA[Rough Cut Editing]]></category>
		<category><![CDATA[SSME]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 4]]></category>
		<category><![CDATA[Smooth Streaming]]></category>
		<category><![CDATA[Smooth Streaming Media Element]]></category>
		<category><![CDATA[Live Smoooth Streaming]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/dschenkelman/?p=317</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/dschenkelman/2011/06/01/microsoft-media-platform-video-editor-sp2-released/" class="more-link">read more<img src="http://blogs.southworks.net/dschenkelman/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>On Monday, Microsoft released the <a href="http://archive.msdn.microsoft.com/VideoEditor/Release/ProjectReleases.aspx?ReleaseId=5312">Service Pack 2</a> version of the <a href="http://archive.msdn.microsoft.com/VideoEditor">Microsoft Media Platform Video Editor</a> (formerly known as RCE).</p>
<p><a href="http://blogs.southworks.net/dschenkelman/files/2011/06/image.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/dschenkelman/files/2011/06/image_thumb.png" border="0" alt="image" width="576" height="273" /></a></p>
<p>This version includes all the <a href="http://blogs.southworks.net/ejadib/2011/01/14/silverlight-rough-cut-editor-sp1-released/">new features and bug fixes that were included in SP1</a>, an important fix for an issue that occurs when playing live smooth streaming videos and a minor fix in the <a href="http://blogs.southworks.net/ejadib/2010/05/27/composite-stream-manifest-csm-generator-rough-cut-editor-rce/">Composite Stream Manifest generator</a>.</p>
<p>Full descriptions of the issues are provided below in case you have run into them.</p>
<h2><strong>Issues Description</strong></h2>
<h5><strong>Live Smooth Streaming Videos without text tracks fails on playback</strong></h5>
<p>When playing a live smooth streaming video without any text tracks, a message is shown explaining that the video can&#8217;t be played.<br />
The log has the following related entry: <em>&#8220;Exception: Failed to parse manifest: Index was out of range. Must be non-negative and less than the size of the collection.&#8221;</em></p>
<h5><strong>First chunk duration are not generated sometimes</strong></h5>
<p>In some scenarios, the duration of the first chunk of the video and audio streams is not generated.</p>
<p>The error message when playing the generated CSM is the following: <em>&#8220;</em><em>Caught exception trying to parse main manifest: First audio chunk in clip 1 [start time = <strong>X</strong>, duration = <strong>Y</strong>] does not contain clip start position <strong>Z</strong>]<em>&#8220;, </em></em>where X, Y and Z are values that depend on your clips. For more information on common issues when generating and using CSMs, please check this<a href="http://blogs.southworks.net/ejadib/2010/02/05/common-mistakes-issues-when-creating-and-using-composite-stream-manifests-csm/"> blog post</a>.</p>
<p><em> </em></p>
<p>Hopefully, you will find this new release useful.</p>
<p>If you have comments, questions, suggestions or any issue, please visit the <a href="http://archive.msdn.microsoft.com/VideoEditor">MMP Video Editor community site</a>.</p>
<p><a rev="vote-for" href="http://dotnetshoutout.com/Microsoft-Media-Platform-Video-Editor-SP2-Released"><img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.southworks.net%2Fdschenkelman%2F2011%2F06%2F01%2Fmicrosoft-media-platform-video-editor-sp2-released%2F" style="border:0px" /></a></p>
<img src="http://feeds.feedburner.com/~r/dschenkelman/~4/rvNoWYcQi18" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blogs.southworks.net/dschenkelman/2011/06/01/microsoft-media-platform-video-editor-sp2-released/</feedburner:origLink></item>
		<item>
		<title>Needle Dependency Injection Container – Alpha 0.1 version released</title>
		<link>http://feeds.southworks.net/~r/dschenkelman/~3/vbMo5F7VU_Y/</link>
		<comments>http://blogs.southworks.net/dschenkelman/2011/02/18/needle-dependency-injection-container-alpha-0-1-version-released/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 23:06:50 +0000</pubDate>
		<dc:creator>Damian Schenkelman</dc:creator>
				<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Needle]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/dschenkelman/?p=280</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/dschenkelman/2011/02/18/needle-dependency-injection-container-alpha-0-1-version-released/" class="more-link">read more<img src="http://blogs.southworks.net/dschenkelman/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago I uploaded to <a href="http://nuget.org/Packages/Packages/Details/NeedleContainer-0-1">NuGet</a> (which was really easy BTW) the <a href="http://needlecontainer.codeplex.com/releases/view/60894">first alpha release</a> of the <a href="http://needlecontainer.codeplex.com/">Needle Container</a>.</p>
<p><a href="http://blogs.southworks.net/dschenkelman/files/2011/02/image.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/dschenkelman/files/2011/02/image_thumb.png" border="0" alt="image" width="475" height="296" /></a></p>
<p>Needle is a lightweight dependency injection container. Initially the project came up as something to do on weekends and boring afternoons with practicing goals (TDD, reflection), but after that I started putting more work into it, by adding documentation in code, and basic features that are commonly found in other containers such as Autofac or Unity.</p>
<p>You can download the <strong>Nuget</strong> package using the following command, which will automatically include a reference to the container’s assembly.</p>
<p><textarea>PM&gt; Install-Package NeedleContainer</textarea></p>
<p>Some of the features that are part of this release are:</p>
<ul>
<li>Constructor Injection</li>
<li>Property Injection</li>
<li>Type mapping using lifetime scopes and Ids</li>
<li>Storing instances using various Ids</li>
<li>Asynchronous object resolution</li>
<li>Fluent API</li>
<li>Support to inject factories using Func&lt;T&gt;</li>
<li>Support to inject instances for all stored registrations using IEnumerable&lt;T&gt;</li>
</ul>
<p>After I come back from my holidays, I expect to be adding more functionality to it in my free time (collaborators are welcome, <a href="http://www.codeplex.com/site/users/view/dschenkelman">contact me through codeplex</a>), as well as doing a couple of posts on the most relevant features, for instance how the Fluent API works and how to perform asynchronous resolution.</p>
<p>If you try it out, let me know what you think of it. You can use the <a href="http://needlecontainer.codeplex.com/discussions">discussions boards</a> to do so.</p>
<p><a rev="vote-for" href="http://dotnetshoutout.com/Needle-Dependency-Injection-Container-Alpha-01-version-released"><img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.southworks.net%2Fdschenkelman%2F2011%2F02%2F18%2Fneedle-dependency-injection-container-alpha-0-1-version-released%2F" style="border:0px" /></a></p>
<img src="http://feeds.feedburner.com/~r/dschenkelman/~4/vbMo5F7VU_Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blogs.southworks.net/dschenkelman/2011/02/18/needle-dependency-injection-container-alpha-0-1-version-released/</feedburner:origLink></item>
		<item>
		<title>MMC 3.0 Sample Plug-In using MVP and Unity</title>
		<link>http://feeds.southworks.net/~r/dschenkelman/~3/QB1Qd1OJdu8/</link>
		<comments>http://blogs.southworks.net/dschenkelman/2011/01/13/mmc-3-0-sample-plug-in-using-mvp-and-unity/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 17:49:42 +0000</pubDate>
		<dc:creator>Damian Schenkelman</dc:creator>
				<category><![CDATA[Guidance]]></category>
		<category><![CDATA[MMC]]></category>
		<category><![CDATA[MVP Pattern]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/dschenkelman/?p=257</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/dschenkelman/2011/01/13/mmc-3-0-sample-plug-in-using-mvp-and-unity/" class="more-link">read more<img src="http://blogs.southworks.net/dschenkelman/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>The last couple of days I have been working on a MMC spike that leverage dependency injection and some kind of presentation pattern (in this case MVP), to search for ways to make MMC applications more testable. The scenario I chose for the spike was having a plug-in that could connect/disconnect network adapters through a service that used WMI objects. The sample is very fresh, and there is still work to do to decouple things a bit more (for example, moving strings for WMI objets to config files).</p>
<p>To work with MMC, you need the <strong>Microsoft.ManagementConsole.dll</strong> assembly, which comes as part of the Windows SDK 6.1 for Windows Server 2008. This is important because versions 7.0 and 7.1 do not include this assembly. Additionally,&nbsp; <em>&#8220;MMC is one of the very few extensibility point in the OS that will not support .NET 4. MMC &#8221; </em>(from <a href="http://connect.microsoft.com/VisualStudio/feedback/details/474039/can-not-use-net-4-0-to-create-mmc-snapin">this thread</a>), which is why MEF went out the door and in came Unity.</p>
<p>The <a href="http://msdn.microsoft.com/en-us/library/aa394217%28VS.85%29.aspx">MMC documentation</a>, explains the basics on how to get started, so if you have never coded an MMC plug-in, I recommend you to start there. To summarize things, you are required to inherit from a couple of classes, override some methods, and put some attributes in place to get the ball rolling.&nbsp; The <a href="http://msdn.microsoft.com/en-us/library/aa394217%28VS.85%29.aspx">Hello World Sample</a> goes over this.</p>
<p><a href="http://blogs.southworks.net/dschenkelman/files/2011/01/image.png"><img style="border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/dschenkelman/files/2011/01/image_thumb.png" width="570" height="344"></a></p>
<h3>Implementation Details</h3>
<p>One of the decisions I had to take was there to make the calls so Unity would resolve and inject the necessary objects. This can be challenging, specially because we have no control over when our Views are instantiated. As you can see in the following code, MMC makes us set a ViewType for a particular description, but gives to control over how the view itself is created.</p>
<pre class="brush: csharp;">public ConnectionsSnapIn()
{
    ...
    var lvd = new MmcListViewDescription(MmcListViewOptions.ExcludeScopeNodes);
    lvd.DisplayName = "Options";
    lvd.ViewType = typeof(ConnectionListView);
    ...
}
</pre>
<p>How does the View get a reference to the presenter? I decided to use the <a href="http://msdn.microsoft.com/en-us/library/microsoft.managementconsole.snapinbase.tag%28VS.85%29.aspx">Tag</a> property of the <a href="http://msdn.microsoft.com/en-us/library/microsoft.managementconsole.snapin_members%28VS.85%29.aspx">SnapIn</a> class to store the container. The View can then access the Tag property, make the necessary cast and resolve the presenter.</p>
<pre class="brush: csharp;">public ConnectionsSnapIn()
{
    ConfigureContainer();
    this.Tag = container;
    ...
}
</pre>
<p>After that, Unity is in the game, so we can resort to constructor injection and normal object resolution. Below is some code from the constructors of the View and Presenter classes.</p>
<p>
<pre class="brush: csharp;">public class ConnectionListView : MmcListView, IConnectionListView
{

    private readonly IConnectionListPresenter presenter;

    public ConnectionListView()
    {

        var container = this.SnapIn.Tag as IUnityContainer;

        if (container != null)
        {
            this.presenter = container.Resolve&lt;IConnectionListPresenter&gt;();
            this.presenter.View = this;
        }

    }
    ...
}
</pre>
<pre class="brush: csharp;">public class ConnectionListPresenter : IConnectionListPresenter
{

    private readonly IConnectionsService connectionsService;

    public ConnectionListPresenter(IConnectionsService connectionsService)
    {
        this.connectionsService = connectionsService;
    }

    ...
}
</pre>
<h3>Alternative Approaches</h3>
<p>Another possible approach I though of could be using a WinForm View&nbsp; instead of a List View, but having it as a placeholder for the real views we want to show depending on the Node that is clicked. This approach leaves the instantiation of the placeholder form to MMC, but would give us control for the instantiation of the other views. This is just an idea, and I might get deeper into this without getting the expected results.</p>
<h3>Getting the Code and Plug-in</h3>
<p>You can download the source code from <a href="http://cid-09f63fc7ac065e5e.office.live.com/self.aspx/p%5E0p%20Samples/ConnectionsPlug-in%20Source.zip">here</a>, and the plug-in (built assembly) from <a href="http://cid-09f63fc7ac065e5e.office.live.com/self.aspx/p%5E0p%20Samples/Connections%20MMC%20Plug-in.zip">here</a>. To install the plug-in, open the Windows SDK console, <strong>cd</strong> to the directory where the assemblies are, and run <strong>InstallUtil.exe MMCSpike.dll </strong>(as shown below)<strong>.</strong></p>
<p><a href="http://blogs.southworks.net/dschenkelman/files/2011/01/image1.png"><img style="border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/dschenkelman/files/2011/01/image_thumb1.png" width="552" height="312"></a></p>
<p>That&#8217;s all for this post. If I get any deeper with the sample or find other interesting approaches I&#8217;ll let you know.</p>
<p><a href="http://dotnetshoutout.com/MMC-30-Sample-Plug-In-using-MVP-and-Unity-Damian-Schenkelman" rev="vote-for"><img style="border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.southworks.net%2Fdschenkelman%2F2011%2F01%2F13%2Fmmc-3-0-sample-plug-in-using-mvp-and-unity%2F"></a></p>
<img src="http://feeds.feedburner.com/~r/dschenkelman/~4/QB1Qd1OJdu8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blogs.southworks.net/dschenkelman/2011/01/13/mmc-3-0-sample-plug-in-using-mvp-and-unity/</feedburner:origLink></item>
		<item>
		<title>How to: Load Prism modules packaged in a separate XAP file in an OOB application</title>
		<link>http://feeds.southworks.net/~r/dschenkelman/~3/qllxhcDbLWE/</link>
		<comments>http://blogs.southworks.net/dschenkelman/2011/01/10/how-to-load-prism-modules-packaged-in-a-separate-xap-file-in-an-oob-application/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 14:32:15 +0000</pubDate>
		<dc:creator>Damian Schenkelman</dc:creator>
				<category><![CDATA[Composite Application Guidance for WPF & SL]]></category>
		<category><![CDATA[Guidance]]></category>
		<category><![CDATA[Patterns & Practices]]></category>
		<category><![CDATA[Prism-v4]]></category>
		<category><![CDATA[Remote Module Loading]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 4]]></category>
		<category><![CDATA[p&p]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/dschenkelman/2011/01/10/how-to-load-prism-modules-packaged-in-a-separate-xap-file-in-an-oob-application/</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/dschenkelman/2011/01/10/how-to-load-prism-modules-packaged-in-a-separate-xap-file-in-an-oob-application/" class="more-link">read more<img src="http://blogs.southworks.net/dschenkelman/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>I have seen many questions, both in the Codeplex  (<a href="http://compositewpf.codeplex.com/Thread/View.aspx?ThreadId=208004">here</a>) and StackOverflow forums (<a href="http://stackoverflow.com/questions/2875121/will-prism-ondemand-module-loading-work-in-an-oob-scenerio">here</a>), asking how to load modules that were packaged for remote module loading in a Silverlight out of browser application.</p>
<p>I created this sample a couple of months ago, and I thought might be useful for others. <a href="http://cid-09f63fc7ac065e5e.office.live.com/self.aspx/p%5E0p%20Samples/OOBCachingSample.zip">Here</a> you can download the sample I put together using the Modularity QS from Prism 4. You can also download the necessary files separately (<a href="http://cid-09f63fc7ac065e5e.office.live.com/self.aspx/p%5E0p%20Samples/OOBModuleManager.cs">OOBModuleManager.cs</a> and <a href="http://cid-09f63fc7ac065e5e.office.live.com/self.aspx/p%5E0p%20Samples/CachingXapModuleTypeLoader.cs">CachingXapModuleTypeLoader.cs</a>)</p>
<p>The following are the highlights and steps to follow to run the sample:</p>
<ol>
<li>Open the solution is under <strong>PrismV4\Quickstarts\Modularity\Silverlight\ModularityWithUnity</strong>.</li>
<li>Make sure the Web Site project is set as startup project.</li>
<li>Open the <strong>CachingXapModuleTypeLoader</strong> and <strong>OOBModuleManager </strong>to see how they work. Also check out how the <strong>OOBModuleManager</strong> is registered in the Bootstrapper&#8217;s <strong>ConfigureContainer</strong> method.</li>
<li>Run the application. Load all 6 modules.</li>
<li>Install the application (add to Desktop and Start Menu).</li>
<li>Close web browser and OOB window.</li>
<li>Check in Systray that <a href="http://localhost:portX">http://localhost:portX</a> is not running. If it is, stop the site.</li>
<li>Open OOB App from desktop.</li>
<li>Load modules, they should load correctly.</li>
</ol>
<p><a href="http://blogs.southworks.net/dschenkelman/files/2011/01/image001.jpg"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/dschenkelman/files/2011/01/image001_thumb.jpg" border="0" alt="image001" width="562" height="325" /></a></p>
<table border="2" cellspacing="0" cellpadding="2" width="1129">
<tbody>
<tr>
<td width="1125" valign="top"><strong>Note</strong>: Modules B, D, E &amp; F are loaded remotely, in background, not from main xap or however the Prism docs are explaining it (if you open Iso Storage you’ll find the .xap files there).</td>
</tr>
</tbody>
</table>
<p>I hope this is useful for you in case you are required to implement this scenario.</p>
<p><P></P> <a rev="vote-for" href="http://dotnetshoutout.com/How-to-Load-Prism-modules-packaged-in-a-separate-XAP-file-in-an-OOB-application-Damian-Schenkelman"><img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.southworks.net%2Fdschenkelman%2F2011%2F01%2F10%2Fhow-to-load-prism-modules-packaged-in-a-separate-xap-file-in-an-oob-application%2F" style="border:0px" /></a></p>
<img src="http://feeds.feedburner.com/~r/dschenkelman/~4/qllxhcDbLWE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blogs.southworks.net/dschenkelman/2011/01/10/how-to-load-prism-modules-packaged-in-a-separate-xap-file-in-an-oob-application/</feedburner:origLink></item>
		<item>
		<title>Prism Training Kit 4.0 Released</title>
		<link>http://feeds.southworks.net/~r/dschenkelman/~3/LU52xHPOYkg/</link>
		<comments>http://blogs.southworks.net/dschenkelman/2010/11/20/prism-training-kit-4-0-released/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 03:10:47 +0000</pubDate>
		<dc:creator>Damian Schenkelman</dc:creator>
				<category><![CDATA[Composite Application Guidance for WPF & SL]]></category>
		<category><![CDATA[MEF]]></category>
		<category><![CDATA[Patterns & Practices]]></category>
		<category><![CDATA[Prism]]></category>
		<category><![CDATA[PrismTK]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 4]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[p&p]]></category>
		<category><![CDATA[Prism-v4]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/dschenkelman/?p=237</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/dschenkelman/2010/11/20/prism-training-kit-4-0-released/" class="more-link">read more<img src="http://blogs.southworks.net/dschenkelman/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>This past week with <a href="http://blogs.southworks.net/dpoza/">Diego</a>, <a href="http://blogs.southworks.net/ejadib/">Ezequiel</a>, <a href="http://blogs.southworks.net/gmaliandi/">Guido</a> and <a href="http://blogs.southworks.net/matiasb/">Matias</a> we worked on updating <a href="http://prismtk.codeplex.com/releases/view/55821">Prism training kit</a> to <a href="http://msdn.microsoft.com/en-us/library/gg406140.aspx">Prism 4.0</a>. Following the trend from the Prism team guys, we updated the version number to Prism Training Kit 4.0. Download the latest version from <a href="http://prismtk.codeplex.com/releases/view/56048">here</a>.</p>
<p>﻿<a href="http://blogs.southworks.net/dschenkelman/files/2010/11/prismtk.png"><img class="alignnone size-medium wp-image-239" src="http://blogs.southworks.net/dschenkelman/files/2010/11/prismtk-300x125.png" alt="" width="300" height="125" /></a></p>
<p>I really recommend downloading this release, as we put a lot of effort in getting out there what we believed would be the most useful content. You can get a set of detailed updates and features in <a href="http://blogs.southworks.net/gmaliandi/2010/11/prism-training-kit-4-0-is-out/">Guido&#8217;s blog</a>, but to summarize the main changes are:</p>
<ol>
<li>Updated Modularity, Bootstrapper, Dependency Injection, Communication and UI Composition labs to Prism 4.0.</li>
<li>Created new labs for MEF and Navigation.</li>
<li>Fixed bugs from first version of the Training Kit.</li>
</ol>
<p><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/dschenkelman/files/2010/11/MEF-LAB1-690x601_thumb.png" border="0" alt="MEF-LAB1-690x601" width="457" height="399" /></p>
<p>The reason we <em>&#8220;left out&#8221;</em> the MVVM training is that Karl Shifflett has released the <a href="http://karlshifflett.wordpress.com/2010/11/07/in-the-box-ndash-mvvm-training/">&#8220;In the box&#8221; training</a> which does a great job covering MVVM scenarios.</p>
<p>If you have any feedback about the PrismTK, you can use the site&#8217;s <a href="http://prismtk.codeplex.com/discussions">discussion list</a>, <a href="http://prismtk.codeplex.com/workitem/list/basic">issue tracker</a> or this blog.</p>
<p>We hope that you find it really useful.</p>
<img src="http://feeds.feedburner.com/~r/dschenkelman/~4/LU52xHPOYkg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blogs.southworks.net/dschenkelman/2010/11/20/prism-training-kit-4-0-released/</feedburner:origLink></item>
	</channel>
</rss>
