<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Fredrik Normén</title><subtitle type="html">ASP.NET, AJAX, Silverlight, RIA, Architecture, Clean Code</subtitle><id>http://weblogs.asp.net/fredriknormen/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/fredriknormen/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2009-10-08T14:12:00Z</updated><entry><title>WCF RIA Services – What you need to know when creating DTO/Presentation Model</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/20/wcf-ria-services-what-you-need-to-know-when-creating-dto-presentation-model.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/20/wcf-ria-services-what-you-need-to-know-when-creating-dto-presentation-model.aspx</id><published>2009-11-20T16:37:14Z</published><updated>2009-11-20T16:37:14Z</updated><content type="html">&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: This is based on the WCF RIA Services Beta, so the code in this post can change in a future release of the framework.&lt;/em&gt;&lt;/strong&gt;    &lt;br /&gt;    &lt;br /&gt;When defining DTO or a “Presentation Model” (Not the Presentation Model pattern by Martin Fowler, a model suited for presentation purpose, not all entities are) there are things you may want to now. The following is an simple DTO:    &lt;br /&gt;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Order
{
     [Key]
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; OrderID { get; set; }

     &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerable&amp;lt;OrderRow&amp;gt; Rows { get; set; }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The KeyAttribute is used to mark one or more properties to be the unique identifier of the object. As you can see the OrderID is a public property with both set and get methods. In some cases we want to have the OrderID as “read-only” and one or all more properties “read-only”. To make sure a property is “read-only” we can for example make sure the set method is internal:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Order
{
     [Key]
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; OrderID { get; &lt;span class="kwrd"&gt;internal&lt;/span&gt; set; }

     &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerable&amp;lt;OrderRow&amp;gt; Rows { get; set; }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;We can also remove the set to make it “read-only”. The generated code on the client-side will now have an Order class where the OrderID is “read-only”, BUT! It still has the set method. It’s first at runtime we get an exception when we try to set a “read-only” property to a value. In this case it can be too late or results in bugs. Here is the client-side version of the generated OrderID property:
  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[DataMember()]
[Editable(&lt;span class="kwrd"&gt;false&lt;/span&gt;)]
[Key()]
[ReadOnly(&lt;span class="kwrd"&gt;true&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; OrderID
{
    get
    {
         &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;._orderID;
    }
    set
    {
          &lt;span class="kwrd"&gt;if&lt;/span&gt; ((&lt;span class="kwrd"&gt;this&lt;/span&gt;._orderID != &lt;span class="kwrd"&gt;value&lt;/span&gt;))
         {
              &lt;span class="kwrd"&gt;this&lt;/span&gt;.ValidateProperty(&lt;span class="str"&gt;&amp;quot;OrderID&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;value&lt;/span&gt;);
              &lt;span class="kwrd"&gt;this&lt;/span&gt;.OnOrderIDChanging(&lt;span class="kwrd"&gt;value&lt;/span&gt;);
              &lt;span class="kwrd"&gt;this&lt;/span&gt;._orderID = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
              &lt;span class="kwrd"&gt;this&lt;/span&gt;.RaisePropertyChanged(&lt;span class="str"&gt;&amp;quot;OrderID&amp;quot;&lt;/span&gt;);
              &lt;span class="kwrd"&gt;this&lt;/span&gt;.OnOrderIDChanged();
          }
     }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;To make a whole DTO “read-only” (still set methods will be generated, so we will only know that a property is “ready-only” at runtime if we try to give it a value) we can avoid adding the Update operation to our DomainService for that DTO.&lt;/p&gt;

&lt;p&gt;When it comes to IEnumerable types (including data structures inherit from the IEnumerable interface) they will by default be “read&amp;quot;-only”, in a way where we can’t Add objects to it. To make it not “read-only” we need to add a Add operation of the type the collection takes to our DomainService, for example:
  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AddOrderRow(OrderRow row)
{
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;If you don’t add the Add operation and no Update operation for the OrderRow, we can still on the client side change the OrderRow returned from the collection. So have that in mind. By default in C# if we return an IEnumerable&amp;lt;T&amp;gt; as in the code example in this post, it’s read-only, we can’t add or remove or do anything to an IEnumerable interface. It will be read only one the server-side if we create an instance of the DomainService, but not on the client-side. On client-side it will be generated to a EntityCollection&amp;lt;T&amp;gt;. Sadly an interface with a lot of methods that we maybe don’t even want the user to see, for example Remove or Add if we only want to return a “read-only” collection. We can have the Add and Remove disabled by not adding the Add or Remove operation to the DomainService for the type the collection holds, but still it’s available for the user on the client-side, and they can use them. If they don’t test the code or run the part where they will use them, it can results in bugs. It’s first at runtime we get an exception that we can’t use them.&lt;/p&gt;

&lt;p&gt;When using a DTO we can’t add a constructor which takes parameters, only the default will be generated on the client side, and is also needed. So if we want to use an immutable class, we can’t by just write:
  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Order
{
     &lt;span class="kwrd"&gt;public&lt;/span&gt; Order(&lt;span class="kwrd"&gt;int&lt;/span&gt; orderID)
     {
        &lt;span class="rem"&gt;//..&lt;/span&gt;
     }

    &lt;span class="rem"&gt;//..&lt;/span&gt;
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;The reason why we can’t the constructor on the client-side, is that it will contain code which will not be added to the client-side Order class. So to make it possible to use a constructor, we can use the .shared feature:

  &lt;br /&gt;

  &lt;br /&gt;Order.shared.cs

  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Order
{
     &lt;span class="kwrd"&gt;public&lt;/span&gt; Order(&lt;span class="kwrd"&gt;int&lt;/span&gt; orderID)
    {
          &lt;span class="kwrd"&gt;this&lt;/span&gt;.OrderID = orderID;
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Note: Remember to make the main DTO partial and you have to add the default constructor also.&lt;/em&gt;&lt;/strong&gt;

  &lt;br /&gt;

  &lt;br /&gt;You can’t never make the DTO immutable and “read-only”, because the set methods are always added to the client-side generated class. The way it’s “read-only”, is during runtime.&lt;/p&gt;

&lt;p&gt;
  &lt;br /&gt;If you want a testable DTO where validation should be part of the test (some validation are core concerns and business logic), you can forget about it. BUT! Logic added to a DTO, will not longer make it a DTO. WCF RIA Services uses Annotation to add validations, which will take place on the client-side and server-side. If you add validation code inside of a object you want to expose through a DomainSerivice, it will stay on the server-side, so if you add a validation annotation also, you break DRY (Don’t repeat yourself), but you can write test that will test the object on the server-side. To make sure you don’t repeat yourself and don’t run the same validation twice on the server-side, you need to handle the validation by your own. A god place to do it is in the ViewModel on the client side, for example with IDataErrorInfo and INotifyDataErrorInfo interface. If we only could have partial properties, we could used the .shared feature to add our own validation to the .shared files and make sure we share our validation on the server- and client-side. BUT! Remember a DTO with logic added, is no longer a DTO, it’s an Object.

  &lt;br /&gt;

  &lt;br /&gt;When you return the IEnumerable&amp;lt;T&amp;gt; from your Query method, the Query passed from the client-side down to the DomainService, will only take place after the data is returned. So if your query method retrieves thousands and millions of objects, it will always do that. In this case it would be advisable to use the IQueryable&amp;lt;T&amp;gt; or interpret the Query passed down to the DomainSerivce to filter your data. If you decide to return a IQueryable&amp;lt;T&amp;gt;, the query will still be executed after the Query method is executed. So what you have to do is to make sure your data access components supports the use of IQueryable&amp;lt;T&amp;gt;, Entity Framework and Linq 2 SQL does, also nHib with the LINQ support I guess. But, have in mind that you can’t execute the query, just pass the IQueryable&amp;lt;T&amp;gt; along to the next layers. If you ask me, I wouldn’t do that, it will result in a deferred execution and I will “sort” of lose my control where the query against my data source will take place.&lt;/p&gt;

&lt;p&gt;If you want to know more about associations with DTO, check my previous post: &lt;a title="http://weblogs.asp.net/fredriknormen/archive/2009/11/20/wcf-ria-services-and-dto-with-association.aspx" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/20/wcf-ria-services-and-dto-with-association.aspx"&gt;http://weblogs.asp.net/fredriknormen/archive/2009/11/20/wcf-ria-services-and-dto-with-association.aspx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
  &lt;br /&gt;If you want to know when I publish new blog posts, or just follow my life, you can find me on twitter: &lt;a href="http://www.twitter.com/fredrikn"&gt;http://www.twitter.com/fredrikn&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7261698" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author></entry><entry><title>WCF RIA Services and DTO with association</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/20/wcf-ria-services-and-dto-with-association.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/20/wcf-ria-services-and-dto-with-association.aspx</id><published>2009-11-20T09:46:54Z</published><updated>2009-11-20T09:46:54Z</updated><content type="html">&lt;p&gt;This post will be short, I notice that some people are asking about how to send an object graph which will include an association to other objects. First of all, be careful with the distribution of an object graph, wrong design can affect performance in a way that to much data is passed over the wire.   &lt;br /&gt;    &lt;br /&gt;Here is an simple Order class, this class has OrderRows:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Order
{
    [Key]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; OrderID { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerable&amp;lt;OrderRow&amp;gt; Rows { get; set; }
}


&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; OrderRow
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; OrderID { get; set; }

    [Key]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; OrderRowID { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;Here is my DomainService where I have specified a query method for the Orders:

  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[EnableClientAccess()]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; DomainService1 : DomainService
{
        &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerable&amp;lt;Order&amp;gt; GetOrders()
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Order&amp;gt;()
                        {
                            &lt;span class="kwrd"&gt;new&lt;/span&gt; Order()
                            {
                                OrderID = 0,
                                Rows = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;OrderRow&amp;gt;()
                                        {
                                            &lt;span class="kwrd"&gt;new&lt;/span&gt; OrderRow() { OrderID = 0, Name = &lt;span class="str"&gt;&amp;quot;Row 0&amp;quot;&lt;/span&gt;, OrderRowID = 0 },
                                            &lt;span class="kwrd"&gt;new&lt;/span&gt; OrderRow() { OrderID = 0, Name = &lt;span class="str"&gt;&amp;quot;Row 1&amp;quot;&lt;/span&gt;, OrderRowID = 1 }
                                        }
                            },
                                                        &lt;span class="kwrd"&gt;new&lt;/span&gt; Order()
                            {
                                OrderID = 1,
                                Rows = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;OrderRow&amp;gt;()
                                        {
                                            &lt;span class="kwrd"&gt;new&lt;/span&gt; OrderRow() { OrderID = 1, Name = &lt;span class="str"&gt;&amp;quot;Row 0&amp;quot;&lt;/span&gt;, OrderRowID = 0 },
                                            &lt;span class="kwrd"&gt;new&lt;/span&gt; OrderRow() { OrderID = 1, Name = &lt;span class="str"&gt;&amp;quot;Row 1&amp;quot;&lt;/span&gt;, OrderRowID = 1 }
                                        }
                            }

                        };
        }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: I just fake the loading of data in the GetOrder query method, normally I should of course use Entity Framework 4.0, nHibernate or other ORM&lt;/em&gt;&lt;/strong&gt;.

  &lt;br /&gt;

  &lt;br /&gt;If we now load the Orders from the client, the Order object we will get will not include the Rows property of the order. So the association will not be passed with the Order object. To include an association we need to add the IncludeAttribute, and also the AssociationAttribute:

  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Order
{
        [Key]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; OrderID { get; set; }

&lt;strong&gt;&lt;em&gt;        [Include]
        [Association(&lt;span class="str"&gt;&amp;quot;Order_OrderRows&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;OrderID&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;OrderID&amp;quot;&lt;/span&gt;)]&lt;/em&gt;&lt;/strong&gt;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerable&amp;lt;OrderRow&amp;gt; Rows { get; set; }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;The AssociationAttribute&amp;#160; is needed to specify the association between the Order and the OrderRows. The first argument is only a name of the association, the second is the main key, in this case the Order’s OrderID key, the last argument is the associated objects key which holds the value of the Order’s OrderID, in this case the OrderRow’s OrderID. The Include attributes make sure the Rows property will be included when the object is passed to the client. I hope some of you find this post useful.

  &lt;br /&gt;

  &lt;br /&gt;If you want to know when I publish some new posts, or just follow my life, you can find med on twitter: &lt;a href="http://www.twitter.com/fredrikn"&gt;http://www.twitter.com/fredrikn&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7261358" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="RIA Services" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/RIA+Services/default.aspx" /><category term="WCF Ria Services" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/WCF+Ria+Services/default.aspx" /></entry><entry><title>Silverlight 4 Commanding enables ViewModels</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/19/silverligth-4-commanding-enables-viewmodels.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/19/silverligth-4-commanding-enables-viewmodels.aspx</id><published>2009-11-18T23:41:00Z</published><updated>2009-11-18T23:41:00Z</updated><content type="html">&lt;P&gt;One feature out of many really great feature shipped with Silverlight 4 Beta, is Commanding. With Commanding we can use the MVVM (Model View View Model) Pattern. Commanding is something that WPF has and preview Silverlight doesn’t. Commanding can only be used on ButtonBase controls&amp;nbsp;and Hyperlink control at the moment, and will only be executed by the Click event. In this post I’m going to show how you can use the new Commanding feature and create use the MVVM pattern in Silverlight 4. Here is my simple UI: &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/fredriknormen/ui_705957E4.jpg" mce_href="http://weblogs.asp.net/blogs/fredriknormen/ui_705957E4.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=ui border=0 alt=ui src="http://weblogs.asp.net/blogs/fredriknormen/ui_thumb_6F80F1FA.jpg" width=447 height=190 mce_src="http://weblogs.asp.net/blogs/fredriknormen/ui_thumb_6F80F1FA.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;BR&gt;I have a TextBox and a Button. The ViewModel will represent this view but in code. The main reason to use a ViewModel is because of separation of concerns. The complex UI logic is moved from the View into a class (the ViewModle). The ViewModel for the View above will look like this: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; CustomerViewModel : INotifyPropertyChanged
{
     &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;event&lt;/SPAN&gt; PropertyChangedEventHandler PropertyChanged;

     &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; _firstName;

     &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; FirstName
     {
         get { &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; _firstName; }
         set
         {
             &lt;SPAN class=rem&gt;//Validation code&lt;/SPAN&gt;
            _firstName = &lt;SPAN class=kwrd&gt;value&lt;/SPAN&gt;;

            &lt;SPAN class=rem&gt;//NotifyPropertyChange&lt;/SPAN&gt;
         }
     }

     &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; ICommand Save
     {
        get { &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; SaveCommand(&lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;); }
     }
 }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;The FirsrtName property represents the TextBox in the View, the Save property is the Command that should be executed when the Save button is clicked. As you can see the Save member is a property which will return a ICommand, in this case the SaveCommand. Here is the SaveCommand class: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; SaveCommand : ICommand
{
    &lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; CustomerViewModel _view;

    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; SaveCommand(CustomerViewModel view)
    {
        _view = view;
    }

    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;bool&lt;/SPAN&gt; CanExecute(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; parameter)
    {
            &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
    }

    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;event&lt;/SPAN&gt; EventHandler CanExecuteChanged;

    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Execute(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; parameter)
    {
         &lt;SPAN class=rem&gt;//Do something like saving the Customer&lt;/SPAN&gt;
     }
}&lt;/PRE&gt;
&lt;P&gt;&lt;BR&gt;The SaveCommand implements the ICommand interface which has three members, the CanExecute property, CanExecuteChanged event and the Execute method. The CanExecute return true or false if the command can be executed. The method takes one parameter, this parameter comes from the CommandParamter attribute added to the Button or Hyperlink. The Execute method, is the method that will be executed if the Command can be executed, it’s where you can add your code to perform something when the user clicks the Save button, for example using WCF RIA Services to save the Customer. When the Command and the ViewModel is in place, we can just bind the ViewModel to a DataContext and then use normal Binding to bind to our ViewModel, like this: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;UserControl&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Class&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="SilverlightApplication3.MainPage"&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns:x&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/SPAN&gt;
    &lt;SPAN class=attr&gt;xmlns:vm&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="clr-namespace:SilverlightApplication3"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;STRONG&gt;&lt;EM&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;vm:CustomerViewModel&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="myViewModel"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Grid&lt;/SPAN&gt; &lt;SPAN class=attr&gt;x:Name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="LayoutRoot"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;DataContext&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="&lt;STRONG&gt;&lt;EM&gt;{StaticResource myViewModel}&lt;/EM&gt;&lt;/STRONG&gt;"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;TextBlock&lt;/SPAN&gt;  &lt;SPAN class=attr&gt;Text&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="First Name:"&lt;/SPAN&gt; ... &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;TextBox&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Text&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="&lt;STRONG&gt;&lt;EM&gt;{Binding FirstName, Mode=TwoWay}&lt;/EM&gt;&lt;/STRONG&gt;"&lt;/SPAN&gt; ...&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;Button&lt;/SPAN&gt; &lt;STRONG&gt;&lt;EM&gt;&lt;SPAN class=attr&gt;CommandParameter&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="test"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;Command&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="{Binding Save}"&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt; &lt;SPAN class=attr&gt;Content&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="Save"&lt;/SPAN&gt;  ..." &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;Grid&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;UserControl&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;As you can see the CustomerViewModel is added to the UserControl’s Resources and then added to the LayoutRoot’s DataContext. The TextBox is bind to the FirstName property of the ViewModel and the Command attribute of the Button is bind to the Save property. I just added the CommandParameter to the code so you can see how it can be used to pass a parameter into the CanExecute and Execute method. &lt;BR&gt;&lt;BR&gt;I hope the Silverlight team will also add a way to specify an ViewModel method to any kind of events and where we don’t need to implement the ICommand interface. The Commanding often results in many Command classes.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7259734" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="Silverlight" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/Silverlight/default.aspx" /><category term="VS 2010" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/VS+2010/default.aspx" /><category term="Silverlight 4" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/Silverlight+4/default.aspx" /></entry><entry><title>Is WCF RIA Services ready for the Enterprise?</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/18/is-net-ria-services-ready-for-the-enterprise.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/18/is-net-ria-services-ready-for-the-enterprise.aspx</id><published>2009-11-18T20:11:00Z</published><updated>2009-11-18T20:11:00Z</updated><content type="html">&lt;P&gt;Today Microsoft released the&amp;nbsp;WCF RIA Services Beta, it’s now on top of WCF and by default uses binary data end points and data contract serialization. By using binary data end points we will get better performance and make the data sent over the wire smaller (The other preview versions uses pure JSON). WCF RIA Services is a great framework for Rapid Application Development (RAD) of 2-tier applications. Based on the new changes to the&amp;nbsp;WCF RIA Services it’s defiantly ready for the Intranet and small applications, but how about the Enterprise. First of all if you uses the Entity Framework or Linq to SQL Domain Services, it’s not ready for the Enterprise and will never be, IMO, because when we use it it distribute DAL types to the client. They are useful for small data driven applications. BUT!&amp;nbsp;WCF RIA Services with the DTO (Data Transfer Object) support will make it closer to be ready for the Enterprise, but is that enough?&lt;/P&gt;
&lt;P&gt;It’s complex to build RIA (Rich Internet Application) and require a lot of plumbing. This is something&amp;nbsp;WCF&amp;nbsp;RIA Services is trying to solve. Just remember there is a reason why things are complex, and what every framework developers are trying to do, is to hide the complexity by adding a new level of abstraction. The thing is, the complexity is still there. At first I was skeptic about&amp;nbsp;WCF RIA Services, but it was because the very early previous wasn’t that good, it was ok, good ideas but works had to be done. Now after almost 2 years it starts to look like something promising.&lt;/P&gt;
&lt;P&gt;I have notice several of developers using .WCF RIA Services and because it’s so easy to use, they seems to forgot about the network. What the&amp;nbsp;WCF RIA Services Team have struggle with, is to make sure developers should be aware of the network. I know that even how much they try, some developers will use it in a wrong way. That is nothing they can do anything about. But is that so bad? NO! It gives the people that use it in the right way&amp;nbsp;job opportunists ;)&lt;/P&gt;
&lt;P&gt;I wrote that&amp;nbsp;WCF RIA Services with its DTO support will make it closer to be ready for the Enterprise and the uses of EF and L2S Domain Services are not a good choose when it comes to build Enterprise RIA. There are actually one advantage of using the EF and L2S DomainServices, and that is the way of passing a query from the client to the server. The query will be used when EF and L2S are querying the database (as far as I know, I hope it does at least ;)). It will results in less data sent from the data source. When using DTO the query will take place after we retrieve all the data from our DomainService query methods. But still on the server. But the good thing is that there is a solution to make sure the query also takes place when we query our data source and that is by overriding the DomainService Query method, it has the description of the query passed from the Client. But we had to interpret it and transform it to a query which can query our domain model.&lt;/P&gt;
&lt;P&gt;It looks like developers loves the data annotations added to&amp;nbsp;WCF RIA Services. The validation part is great when it comes to the uses of EF and L2S Domain Services, because the DAL types are generated from the tools (hmm, thinking of the Devils is in the tools ;)), and it’s “hard” to add validation to it. In that case with&amp;nbsp;WCF RIA Services we can use annotation to add validations, which will be available both on the client and the server. Isn’t that great? DTO also support validations buy adding annotations. You have to have in mind, that this validation can’t be tested with Unit Test, it’s the Framework which will execute it. But you also have to remember that DTO is just what is says an object which transfers data. On the client-side we may use a ViewModel which will handle the validation instead.&lt;/P&gt;
&lt;P&gt;Back to the main question, is&amp;nbsp;WCF RIA Services ready for the Enterprise? If I say Yes, it may be a lie, if I say No, it’s definitely a lie. I think it’s ready, or at least I would give it a try. I think the team have made a great framework, I will with no doubt recommand it to others.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7259534" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="RIA" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/RIA/default.aspx" /><category term="WCF Ria Services" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/WCF+Ria+Services/default.aspx" /></entry><entry><title>How to create a Module based Silverlight application (Part 1)</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/16/how-to-create-a-module-based-silverlight-application-part-1.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/16/how-to-create-a-module-based-silverlight-application-part-1.aspx</id><published>2009-11-16T22:48:04Z</published><updated>2009-11-16T22:48:04Z</updated><content type="html">&lt;p&gt;When building RIA (Rich Internet Application) with Silverlight, it’s important to make sure the Silverlight application is loaded as fast as possible. Users don’t like to see a splash screen for several seconds or minutes, they want an application to start directly. One way to make a Silverlight app load fast, is by minimizing the XAP file, this can be done by not adding to much images, videos or other files to the Silverlight application project. If we have a large application, we can also split the application into small “modules”, for example assemblies or .XAP files. We can then load them on demand when they are needed. The base application can be kept small and be the core engine for the other modules. In this first part of my blog post I will add some examples how we can split our Silverlight applications into modules, and load them on demand asynchronous. The next part will be about how to use &lt;a href="http://www.codeplex.com/MEF"&gt;MEF&lt;/a&gt; (Managed Extensibility Framework) to create module bases Silverlight application.&lt;/p&gt; &lt;p&gt;The core components to load assemblies or .XAP on demand is the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.95).aspx"&gt;WebClient&lt;/a&gt; class and the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.assemblypart(VS.95).aspx"&gt;AssemblyPart&lt;/a&gt; class.The following code will demonstrate how we can use the WebClient and AssemblyPart to load a Silverligth Class Library located in the ClientBin folder of our Silverlight Web host:&lt;br&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;var webClient = &lt;span class="kwrd"&gt;new&lt;/span&gt; WebClient();

webClient.OpenReadCompleted += webClient_OpenReadCompleted;
webClinet.OpenReadAsync(&lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;"Module1.dll"&lt;/span&gt;, UriKind.Relative));
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&lt;br&gt;The Module1 Silverlight Class Library can contains Silverlight User Controls and classes etc. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/fredriknormen/image_78512898.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_01C9E70F.png" width="700" height="442"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In this example I have added a Child Window (MyChildWindow) and a Silverlight User control (MyModule) to the Silverlight Class Library. When the project is build, the .xaml will be included into the cliss librarie’s assmebly. The next step is to handle the webClient_OpenReadCompleted event, this event will be trigged when the WebClient have loaded the specified assembly. The following code will demonstrate how the MyModule is added to a Grid dynamically:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; webClient_OpenReadCompleted(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, OpenReadCompletedEventArgs e)
{
    AssemblyPart assemblyPart = &lt;span class="kwrd"&gt;new&lt;/span&gt; AssemblyPart();
    Assembly assembly = assemblyPart.Load(e.Result);

    var userControl = assembly.CreateInstance(&lt;span class="str"&gt;"Module1.MyModule"&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; UserControl;

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (userControl != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        LayoutRoot.Children.Add(userControl);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The AssemblyPart is used to load an Assembly out from a Stream (the OpenReadCompletedEventArgs’s Result property returns the Stream which the WebClient has loaded, in this case a Stream of the Module1.dll). When an Assembly is loaded the Assembly’s CreateInstance method can be used to create an instance of a type (Namespace.ClassName) located in the assembly. The User Control added to the Silverlight Class Library exists in the namespace Module1 and the User Controls name is MyModule. Because the MyModule inherits from the class UserControl we can simply cast the created instance to a UserControl and then add it to the Grid by using the Children.Add method.&lt;br&gt;&lt;br&gt;&lt;em&gt;&lt;strong&gt;Note: If we have added references to other assemblies within the Silverlight Class Library, we also need to load them, or the main Silverlight application need to have a reference to them. If not, we will get an exception about a missing assembly.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;If we want to create a package with all required assemblies for a “module”, we can for example use a .XAP file. The .XAP files contain a AppManifest.xaml file, which contains information of the files inside of an .XAP file. Here is an example of a .XAP files content:&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/fredriknormen/image_594B04FA.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_65D8B216.png" width="559" height="402"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: A .XAP file can be explored by changing the .XAP to .ZIP, it’s basically a normal zip file.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The following is the content of the AppManifest.xaml file in the above .xap file:&lt;br&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Deployment&lt;/span&gt; ...&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Deployment.Parts&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AssemblyPart&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="Module1XAP"&lt;/span&gt; &lt;span class="attr"&gt;Source&lt;/span&gt;&lt;span class="kwrd"&gt;="Module1XAP.dll"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AssemblyPart&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ModuleInfra"&lt;/span&gt; &lt;span class="attr"&gt;Source&lt;/span&gt;&lt;span class="kwrd"&gt;="ModuleInfra.dll"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AssemblyPart&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="System.ComponentModel.DataAnnotations"&lt;/span&gt; &lt;span class="attr"&gt;Source&lt;/span&gt;&lt;span class="kwrd"&gt;="System.ComponentModel.DataAnnotations.dll"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AssemblyPart&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="System.Windows.Controls.Data.DataForm.Toolkit"&lt;/span&gt; &lt;span class="attr"&gt;Source&lt;/span&gt;&lt;span class="kwrd"&gt;="System.Windows.Controls.Data.DataForm.Toolkit.dll"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AssemblyPart&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="System.Windows.Controls.Data.Input"&lt;/span&gt; &lt;span class="attr"&gt;Source&lt;/span&gt;&lt;span class="kwrd"&gt;="System.Windows.Controls.Data.Input.dll"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AssemblyPart&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="System.Windows.Controls"&lt;/span&gt; &lt;span class="attr"&gt;Source&lt;/span&gt;&lt;span class="kwrd"&gt;="System.Windows.Controls.dll"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;AssemblyPart&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="System.Windows.Data"&lt;/span&gt; &lt;span class="attr"&gt;Source&lt;/span&gt;&lt;span class="kwrd"&gt;="System.Windows.Data.dll"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Deployment.Parts&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Deployment&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&lt;br&gt;We can with the WebClient load the .XAP file and get the AppManifest.xaml from the loaded stream by using the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.resources.streamresourceinfo(VS.95).aspx"&gt;StreamResourceInfo&lt;/a&gt; class and the Application’s GetResourceStream method. After that we can get the AssemblyPart from the AppManifest file and load them all. Every assembly we have as an reference will be included in the .XAP file. Here is an example where three Silverlight Application projects are added to a Solution. The Module1XAP and Module2XAP are the modules, and the ModuelBaseSL is the main Silverlight application. The main Silverlight application will load the Modules on demand. When building the solution, the Silverlight applications will be packaged into .XAP file, in this example, Module1XAP.xap, Module2XAP.xap and ModuleBaseSL.xap and will be added to the ClientBin folder.&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/fredriknormen/image_0B622F78.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_30EBACD9.png" width="799" height="796"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;br&gt;There is no API yet out of the box which will help us loading a package (not while this post is written), so we need to write code that will do it. In this example I have created a class which will help us load a module.&lt;br&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ModuleLoader
{

   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; LoadModule(Uri uri, Action&amp;lt;AsyncCompletedEventArgs, AppModule&amp;gt; moduleDownloadCompleted)
   {
      WebClient webClient = &lt;span class="kwrd"&gt;new&lt;/span&gt; WebClient();
      webClient.OpenReadCompleted += webClient_OpenReadCompleted;

      webClient.OpenReadAsync(uri, moduleDownloadCompleted);
   }

   &lt;span class="kwrd"&gt;void&lt;/span&gt; webClient_OpenReadCompleted(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, OpenReadCompletedEventArgs e)
   {
      &lt;span class="rem"&gt;// ...&lt;/span&gt;
   }&lt;br&gt;&lt;/pre&gt;&lt;pre class="csharpcode"&gt;&lt;br&gt;
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&lt;br&gt;The LoadModule method will take an Uri to the .XAP file and also a callback method when the module is loaded.&lt;br&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; webClient_OpenReadCompleted(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, OpenReadCompletedEventArgs e)
{
    var appModule = GetModule(e.Result);&lt;/pre&gt;&lt;pre class="csharpcode"&gt;    var completedCallback = e.UserState as Action&amp;lt;AsyncCompletedEventArgs, AppModule&amp;gt;;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/pre&gt;&lt;pre class="csharpcode"&gt;    if (completedCallback != null)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; completedCallback(new AsyncCompletedEventArgs(e.Error, e.Cancelled, null), appModule);&lt;/pre&gt;&lt;pre class="csharpcode"&gt;}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&lt;br&gt;The following code will create a StreamResourceInfo object. By using the Application’s GetResourceStream method, we can easy get a file out from the Stream. The following code “picks” out the AppManifest.xaml. The code will also load all assemblies located in the .XAP file.&lt;br&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; AppModule GetModule(Stream loadedModuleStream)
{
   AppModule appModule = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

   StreamResourceInfo moduleStreamInfo = &lt;span class="kwrd"&gt;new&lt;/span&gt; StreamResourceInfo(loadedModuleStream, &lt;span class="kwrd"&gt;null&lt;/span&gt;);

   StreamResourceInfo manifestStreamInfo = Application.GetResourceStream(
                                                                moduleStreamInfo,
                                                                &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;"AppManifest.xaml"&lt;/span&gt;, UriKind.Relative));

   &lt;span class="kwrd"&gt;using&lt;/span&gt; (XmlReader reader = XmlReader.Create(manifestStreamInfo.Stream))
   {
       &lt;span class="kwrd"&gt;if&lt;/span&gt; (reader.ReadToFollowing(&lt;span class="str"&gt;"AssemblyPart"&lt;/span&gt;))
       {
          &lt;span class="kwrd"&gt;do&lt;/span&gt;
          {
             &lt;span class="kwrd"&gt;string&lt;/span&gt; source = reader.GetAttribute(&lt;span class="str"&gt;"Source"&lt;/span&gt;);

             &lt;span class="kwrd"&gt;if&lt;/span&gt; (source != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
             {
                StreamResourceInfo sri = Application.GetResourceStream(
                                                                moduleStreamInfo,
                                                                &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(source, UriKind.Relative));

                 var assemblyPart = &lt;span class="kwrd"&gt;new&lt;/span&gt; AssemblyPart();
                 var assembly = assemblyPart.Load(sri.Stream);
                            
                 &lt;span class="kwrd"&gt;if&lt;/span&gt; (appModule == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                     appModule = GetModuleInformation(assembly);
             }
         }
         &lt;span class="kwrd"&gt;while&lt;/span&gt; (reader.ReadToNextSibling(&lt;span class="str"&gt;"AssemblyPart"&lt;/span&gt;));
     }
  }
  &lt;span class="kwrd"&gt;return&lt;/span&gt; appModule;
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&lt;br&gt;The AppModule is a class that will hold all information about a module, such as the Name of the module and the View (UserControl) that should be the startup View for the module. The method GetModuleInformation will check if there is any UserControl inside of the assembly which has a specific Attribute (ModuleViewAttribute), if there is, it will be the startup View for the module. It would be easy to use a Metadata class or file with the information about the Module. But the code in this post is only used to demonstrate how to load modules and kept relative simple.&lt;br&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AppModule
{
     &lt;span class="kwrd"&gt;private&lt;/span&gt; UserControl _mainView;
     &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _name;

     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name
     {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _name; }
        &lt;span class="kwrd"&gt;internal&lt;/span&gt; set { _name = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }
     }


     &lt;span class="kwrd"&gt;public&lt;/span&gt; UserControl View
     {
        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _mainView; }
        &lt;span class="kwrd"&gt;internal&lt;/span&gt; set { _mainView = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }
     }
}&lt;/pre&gt;&lt;pre class="csharpcode"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ModuleViewAttribute : Attribute
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; ModuleViewAttribute()
    {
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; ModuleViewAttribute(&lt;span class="kwrd"&gt;string&lt;/span&gt; name)
    {
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.Name = name;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }
&lt;br&gt; }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&lt;br&gt;The following shows a UserContorl with the ModuleViewAttribute:&lt;br&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;[ModuleView(Name = &lt;span class="str"&gt;"My XAP Module 2"&lt;/span&gt;)]
 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MainPage : UserControl
{
     &lt;span class="kwrd"&gt;public&lt;/span&gt; MainPage()
    {
        InitializeComponent();
    }
}
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&lt;br&gt;The following code will load two different .XAP files and add TabItems to a Tab control in Silverlight 3:&lt;br&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MainPage : UserControl
{
     &lt;span class="kwrd"&gt;public&lt;/span&gt; MainPage()
     {
         InitializeComponent();

         ModuleLoader loader = &lt;span class="kwrd"&gt;new&lt;/span&gt; ModuleLoader();

         loader.LoadModule(
                           &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;"Module1XAP.xap"&lt;/span&gt;, UriKind.Relative),
                           (e, mod) =&amp;gt;
                           {
                              modulesTabContron.Items.Add(
                                              &lt;span class="kwrd"&gt;new&lt;/span&gt; TabItem() { Content = mod.View, Header = mod.Name });
                           });

         loader.LoadModule(
                           &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;"Module2XAP.xap"&lt;/span&gt;, UriKind.Relative),
                           (e, mod) =&amp;gt;
                           {
                             modulesTabContron.Items.Add(
                                             &lt;span class="kwrd"&gt;new&lt;/span&gt; TabItem() { Content = mod.View, Header = mod.Name });
                           });
     }
}&lt;br&gt;&lt;br&gt;&lt;/pre&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;xmlns:controls&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"&lt;/span&gt;  &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="ModuleBaseSL.MainPage"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt; 
    &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
    &lt;span class="attr"&gt;xmlns:d&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/expression/blend/2008"&lt;/span&gt; &lt;span class="attr"&gt;xmlns:mc&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.openxmlformats.org/markup-compatibility/2006"&lt;/span&gt; 
    &lt;span class="attr"&gt;mc:Ignorable&lt;/span&gt;&lt;span class="kwrd"&gt;="d"&lt;/span&gt; &lt;span class="attr"&gt;d:DesignWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="640"&lt;/span&gt; &lt;span class="attr"&gt;d:DesignHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="480"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="LayoutRoot"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="100"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;RowDefinition&lt;/span&gt; &lt;span class="attr"&gt;Height&lt;/span&gt;&lt;span class="kwrd"&gt;="*"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;controls:TabControl&lt;/span&gt; &lt;span class="attr"&gt;Grid&lt;/span&gt;.&lt;span class="attr"&gt;Row&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;x:Name&lt;/span&gt;&lt;span class="kwrd"&gt;="modulesTabContron"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;controls:TabControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;br&gt;&lt;a href="http://weblogs.asp.net/blogs/fredriknormen/image_5A134517.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/fredriknormen/image_thumb_189892BE.png" width="754" height="514"&gt;&lt;/a&gt; &lt;br&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: The code in this post is only used for a demonstration, some refactoring need to be done etc.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I hope this blog post have given you some ideas about how you can create a module based Silverlight application.&lt;/p&gt;
&lt;p&gt;If you want to know when I publish a blog post or other information, you can follow me on twitter: &lt;a href="http://www.twitter.com/fredrikn"&gt;http://www.twitter.com/fredrikn&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7257102" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author></entry><entry><title>Fluent-API to add ActionFilters to Controllers – ASP.NET MVC Part 3</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/10/fluent-api-to-add-actionfilters-to-controllers-asp-net-mvc-part-3.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/10/fluent-api-to-add-actionfilters-to-controllers-asp-net-mvc-part-3.aspx</id><published>2009-11-10T18:04:00Z</published><updated>2009-11-10T18:04:00Z</updated><content type="html">&lt;P&gt;The latest source code for my Fluent-API to add Action Filters to Controllers is no available &lt;A href="http://vinkr.net/misc/ActionFilterConfig.zip" mce_href="http://vinkr.net/misc/ActionFilterConfig.zip"&gt;here&lt;/A&gt;. If you haven’t read about my test project, you can find the other posts here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controller-in-asp-net-mvc.aspx" mce_href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controller-in-asp-net-mvc.aspx"&gt;Fluent-API to add ActionFilters to Controller in ASP.NET MVC&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controllers-asp-net-mvc-part-2.aspx" mce_href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controllers-asp-net-mvc-part-2.aspx"&gt;Fluent-API to add ActionFilters to Controllers – ASP.NET MVC Part 2&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;To use the Fluent-API, you only need to change the Default Controller factory to the ActionFilterConfigControllerFactory, then just configure your controller within the Global.asax. Here is an example where the OutputCache is added to two Action methods, and also an example how to add one or many ActionFilters to one Action method. You can also add Action Filters on a Controller level so they will be used on every Action methods. If you also want a specific Action Filter for all Controllers, you can just Configure the Controller type and add the filters to it.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Application_Start()
{
            ControllerBuilder.Current.SetControllerFactory(&lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt;(ActionFilterConfigControllerFactory));

            RegisterRoutes(RouteTable.Routes);
            RegisterActionFilters();
}

        
&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; RegisterActionFilters()
{
            &lt;SPAN class=rem&gt;// Add OutputCache to all Action Methods for all Controllers which inherits the Contoller class&lt;/SPAN&gt;
            &lt;SPAN class=rem&gt;//ConfigActionFilter.ConfigController&amp;lt;Controller&amp;gt;()&lt;/SPAN&gt;
            &lt;SPAN class=rem&gt;//  .AddFilterToController(new OutputCacheAttribute() { Duration = 10, VaryByParam = "none" });&lt;/SPAN&gt;

            ConfigActionFilter.ConfigController&amp;lt;HomeController&amp;gt;()
                            .AddFilterToController(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HandleErrorAttribute())
                            .AddFilterToActions(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; OutputCacheAttribute() { Duration = 10, VaryByParam = &lt;SPAN class=str&gt;"none"&lt;/SPAN&gt; },
                                                c =&amp;gt; c.About(),
                                                c =&amp;gt; c.Index());

            ConfigActionFilter.ConfigController&amp;lt;AccountController&amp;gt;()
                              .AddFilterToAction(c =&amp;gt; c.LogOn(), &lt;BR&gt;                                                 &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HandleErrorAttribute(), &lt;BR&gt;                                                 new MyCustomFilterAttribute());
}&lt;/PRE&gt;
&lt;P&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;
&lt;/P&gt;
&lt;P&gt;This is as I wrote only a test project, and I do like the idea to add cross-cutting concerns by not adding attributes directly to the Controllers source code.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7250727" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="ASP.NET MVC" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.NET+MVC/default.aspx" /></entry><entry><title>.NET 4.0 is so Lazy</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/10/net-4-0-is-to-lazy.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/10/net-4-0-is-to-lazy.aspx</id><published>2009-11-10T13:10:00Z</published><updated>2009-11-10T13:10:00Z</updated><content type="html">&lt;P&gt;With .NET 4.0 there is a new class added to the System namespace called Lazy&amp;lt;T&amp;gt;. This class is what the name says, lazy. Here is an example where Lazy is used: &lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;var lazy = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Lazy&amp;lt;IList&amp;lt;OrderRow&amp;gt;&amp;gt;(
                                () =&amp;gt;
                                {
                                        var rows = &lt;SPAN class=rem&gt;//get order rows;&lt;/SPAN&gt;
                                        &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; rows;
                                });

var rows = lazy.Value;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;The Lazy&amp;lt;T&amp;gt;’s constructor can take a Func&amp;lt;T&amp;gt; as an argument, the function passed as an argument to the contractor will first be invoked when the Value property of the Lazy&amp;lt;T&amp;gt; class is used, but not invoked the next time the Value property is used. The code above will first execute the function passed as an argument when the we request the value of the Lazy&amp;lt;T&amp;gt;, the returned value of the function will be cached. The next time Value is used, the function will not be invoked, instead the cached value will be returned. This class&amp;nbsp; can for example be used when we want some kind of Lazy Loading.&lt;/P&gt;
&lt;P&gt;I’m on twitter: &lt;A href="http://www.twitter.com/fredrikn" mce_href="http://www.twitter.com/fredrikn"&gt;http://www.twitter.com/fredrikn&lt;/A&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7250520" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="C#" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/C_2300_/default.aspx" /><category term=".Net" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/.Net/default.aspx" /><category term="VS2010" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/VS2010/default.aspx" /></entry><entry><title>Fluent-API to add ActionFilters to Controllers – ASP.NET MVC Part 2</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controllers-asp-net-mvc-part-2.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controllers-asp-net-mvc-part-2.aspx</id><published>2009-11-07T09:39:00Z</published><updated>2009-11-07T09:39:00Z</updated><content type="html">&lt;P&gt;I’m working with my Fluent-API for adding Action Filters to Controllers and Action Methods. In my &lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controller-in-asp-net-mvc.aspx" mce_href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controller-in-asp-net-mvc.aspx"&gt;previous post&lt;/A&gt;, I created a new instance of each Action Filter and add it to an Action Method or Controller. Based on how the Action Filters are often implemented they don’t or shouldn’t keep any state, so in that case I don’t need to create a new instance of the same Action Filter with the same configuration for each Action Method I want to add it to. I also want to have an option to have a better overview of which Action Filter is added to which Controllers and Action Methods. I have added to methods, AddFilterToControllers and AddFilterToActions:&lt;/P&gt;&lt;PRE class=csharpcode&gt;            .AddFilterToActions(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HandleErrorAttribute(),
                                c=&amp;gt; c.About(),
                                c=&amp;gt; c.Index());
            .AddFilterToActions(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; OutOfMemoryException(),
                                c=&amp;gt; c.About());
             .AddFilterToActions(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HandleErrorAttribute() { ... },
                                c=&amp;gt; c.MyMethod());

&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;The code is not yet available due to some more changes and testing.&lt;/P&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7248779" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="ASP.Net" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.Net/default.aspx" /><category term="ASP.NET MVC" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.NET+MVC/default.aspx" /></entry><entry><title>Fluent-API to add ActionFilters to Controller in ASP.NET MVC</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controller-in-asp-net-mvc.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controller-in-asp-net-mvc.aspx</id><published>2009-11-07T00:45:00Z</published><updated>2009-11-07T00:45:00Z</updated><content type="html">&lt;P&gt;&lt;STRONG&gt;Note: The name of the classes and the methods are just temporary and may change, I’m so bad when it comes to naming classes and methods. The source code is simple and haven’t done so much refactoring etc. Just wanted to see if I could get it to work, so please have that in mind.&lt;/STRONG&gt;&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;EDIT:&amp;nbsp;Working with new methods&amp;nbsp;to get a better overview of Action Filters added and also reusing AcitonFitlers,&amp;nbsp;you can read about it &lt;/STRONG&gt;&lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controllers-asp-net-mvc-part-2.aspx" mce_href="http://weblogs.asp.net/fredriknormen/archive/2009/11/07/fluent-api-to-add-actionfilters-to-controllers-asp-net-mvc-part-2.aspx"&gt;&lt;STRONG&gt;here&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;When we create controllers for our ASP.NET MVC application we can also add Action Filters to handle cross-cutting concerns, like Authorization, Error handling and Caching etc. If we want to have Error handling on every controller we need to add the HandleErrorAttribute to all controllers, like this: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;[HandleError] 
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; MyController : Controller 
{ 
}&lt;BR&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR&gt;By adding Action Filters by using attributes it can be hard to get a good overview of which controllers that has the HandleErrorAttribute. The same regarding Action methods, for example if we have a lot of Controllers and want to see see all the Action methods that uses for example the OutputCacheAttribute, we need to go through all Controllers and methods, there is no easy way to get a simple overview of them.&lt;/P&gt;
&lt;P&gt;Adding Action Filters to Action methods and Controllers also add some sort of “dependency” to action filters (not a big deal, though). I decided to try a way to add Action Filters to Controllers and Action methods in one single file, so I could get a better overview of which Controllers and Action methods uses what ActionFilter etc. Because ActionFitlers contains cross-cutting concerns I also wanted to move it away as attributes from the Controllers and Action methods so developers don’t need to care about the cross-cutting concerns during the creation of Controllers. instead add them later.&lt;/P&gt;
&lt;P&gt;I sort of used a Fluent-API for the configuration of ActionFilters, and the configuration is added to the Global.asax’s Application_Start event. Here is an example where I add the ErroHandler Action Filter to all Controllers Action Methods: &lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;
&lt;PRE class=csharpcode&gt;ConfigActionFilter.ConfigController&amp;lt;Controller&amp;gt;() 
                  .AddFilterToController(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HandleErrorAttribute());
&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;If I want to add an Action Filters to a specific Controller I just use the type of the Controller:&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;ConfigActionFilter.ConfigController&amp;lt;HomeController&amp;gt;()
                              .AddFilterToController(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HandleErrorAttribute());&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Note: The reason I don’t use XML and a XML meta data provider as a configuration is because I wanted to make the configuration type safe. If we use XML we can only get an exception if we spell something wrong at runtime.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;If I want to add Action Filters to Action Methods I can write something like this:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;ConfigActionFilter.ConfigController&amp;lt;HomeController&amp;gt;()
                              .AddFilterToController(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HandleErrorAttribute())
                              .AddFilterToAction(c =&amp;gt; c.About(),
                                                 &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MyActionFilterAttribute(),
                                                 &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MyOtherActionFilter() { Metadata=10 })
                              .AddFilterToAction(c =&amp;gt; c.Index(),
                                                 &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MyActionFilterAttribute());&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn’t wanted to use a string for the ActionMethod (AddFilterToAction(“About”)) because it would not be type safe. I want to get a warning or error while typing the code, so instead I created an Expression. The AddFilterToAction takes a params of FilterAttributes, so I can easy add several of Action Filters to an Action Method. The AddFilterToController method will add Action Filter to the Controller, just like adding an Action Filter attribute to the class definition, so all Action Methods within the Controller will use the Action Filter.&lt;/P&gt;
&lt;P&gt;I created a Custom ControllerFactory so I could add my Custom ControllerActionInvoker to the Controller:&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt; &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; ActionFilterConfigControllerFactory : DefaultControllerFactory
 {
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;override&lt;/SPAN&gt; IController CreateController(RequestContext requestContext, &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; controllerName)
        {
             ...&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&lt;STRONG&gt;&lt;EM&gt;                controllerInstance.ActionInvoker = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; ActionFilerConfigControllerActionInvoker();&lt;/EM&gt;&lt;/STRONG&gt;

            &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; controller;
        }
 }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The custom ControllerActionInvoker will make sure the Action Filter added by using my solution is added to the FilterInfo class. This is done by overriding the GetFilters method:&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; ActionFilerConfigControllerActionInvoker : ControllerActionInvoker
{
        &lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;override&lt;/SPAN&gt; FilterInfo GetFilters(ControllerContext controllerContext,
                                                 ActionDescriptor actionDescriptor)
        {
            var filters = &lt;SPAN class=kwrd&gt;base&lt;/SPAN&gt;.GetFilters(controllerContext, actionDescriptor);

            &lt;SPAN class=kwrd&gt;...&lt;/SPAN&gt;

            &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (ConfigActionFilter.Config.ContainsKey(controllerName))
                AddFiltersToFilerList(actionDescriptor, filters, controllerName);

            &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; filters;
        }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This project only a fun thing to do and I like the idea of having different options to add Action Filters, and this solution will make the Controller clean from Attributes and also have one place to add them. When I create my Controller I don’t need to worry or think about the cross-cutting concerns, I just add them later and into the Global.asax.&lt;/P&gt;
&lt;P&gt;I want to thanks &lt;A href="http://weblogs.asp.net/mikaelsoderstrom/" mce_href="http://weblogs.asp.net/mikaelsoderstrom/"&gt;Mikael Söderström&lt;/A&gt; for taking time to discuss this solution with him, and get some feedback and also “host” the source code for me.&lt;BR&gt;&lt;BR&gt;You can download the source code with an example here: &lt;A title=http://vinkr.net/misc/ActionFilterConfig.zip href="http://vinkr.net/misc/ActionFilterConfig.zip" mce_href="http://vinkr.net/misc/ActionFilterConfig.zip"&gt;http://vinkr.net/misc/ActionFilterConfig.zip&lt;/A&gt;&lt;/P&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7248619" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="ASP.Net" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.Net/default.aspx" /><category term="ASP.NET MVC" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.NET+MVC/default.aspx" /></entry><entry><title>Visual Studio 2010 Launch Countdown Sidebar Widget</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/04/visual-studio-2010-launch-countdown-sidebar-widget.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/04/visual-studio-2010-launch-countdown-sidebar-widget.aspx</id><published>2009-11-04T10:15:00Z</published><updated>2009-11-04T10:15:00Z</updated><content type="html">
&lt;STYLE type=text/css&gt;

div#widget { position: relative; width: 250px; height: 155px; }

body ul#cntdwn { width: 250px; height: 80px; background: transparent url(http://toysfortweets.com/visualstudiowidget/cntdwn-bg.png) no-repeat scroll left top; list-style-type: none; text-align: center; padding: 74px 0 0 0; margin: 0; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }

body ul#cntdwn li { float: left; margin: 0 8px 0 0; background: transparent url(http://toysfortweets.com/visualstudiowidget/number-bg.png) no-repeat scroll left top; padding: 0 0 5px 7px; }

body ul#cntdwn li.first { margin-left: 20px; }

body ul#cntdwn li em { display: block;  color: #111; font-size: 1.6em; font-style: normal; font-weight: bold; background: transparent url(http://toysfortweets.com/visualstudiowidget/number-cap.png) no-repeat scroll right top; padding: 3px 7px 0 0; height: 35px; margin-bottom: -5px; }

div#widget a#link { display: block; width: 250px; height: 155px; position: absolute; top: 0; left: 0; }

&lt;/STYLE&gt;

&lt;SCRIPT language=javascript src="http://toysfortweets.com/visualstudiowidget/countdown.js" mce_src="http://toysfortweets.com/visualstudiowidget/countdown.js"&gt; &lt;/SCRIPT&gt;
&lt;BR&gt;&lt;BR&gt;Here is a&amp;nbsp;sidebar widget that will show the countdown&amp;nbsp;for Visual Studio 2010, launching on March 22, 2010.&lt;BR&gt;
&lt;P&gt;&amp;lt;style type="text/css"&amp;gt;&lt;BR&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;div#widget { position: relative; width: 250px; height: 155px; }&lt;/P&gt;
&lt;P&gt;body ul#cntdwn { width: 250px; height: 80px; background: transparent url(&lt;A href="http://toysfortweets.com/visualstudiowidget/cntdwn-bg.png" mce_href="http://toysfortweets.com/visualstudiowidget/cntdwn-bg.png"&gt;http://toysfortweets.com/visualstudiowidget/cntdwn-bg.png&lt;/A&gt;) no-repeat scroll left top; list-style-type: none; text-align: center; padding: 74px 0 0 0; margin: 0; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }&lt;/P&gt;
&lt;P&gt;body ul#cntdwn li { float: left; margin: 0 8px 0 0; background: transparent url(&lt;A href="http://toysfortweets.com/visualstudiowidget/number-bg.png" mce_href="http://toysfortweets.com/visualstudiowidget/number-bg.png"&gt;http://toysfortweets.com/visualstudiowidget/number-bg.png&lt;/A&gt;) no-repeat scroll left top; padding: 0 0 5px 7px; }&lt;/P&gt;
&lt;P&gt;body ul#cntdwn li.first { margin-left: 20px; }&lt;/P&gt;
&lt;P&gt;body ul#cntdwn li em { display: block;&amp;nbsp; color: #111; font-size: 1.6em; font-style: normal; font-weight: bold; background: transparent url(&lt;A href="http://toysfortweets.com/visualstudiowidget/number-cap.png" mce_href="http://toysfortweets.com/visualstudiowidget/number-cap.png"&gt;http://toysfortweets.com/visualstudiowidget/number-cap.png&lt;/A&gt;) no-repeat scroll right top; padding: 3px 7px 0 0; height: 35px; margin-bottom: -5px; }&lt;/P&gt;
&lt;P&gt;div#widget a#link { display: block; width: 250px; height: 155px; position: absolute; top: 0; left: 0; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;lt;/style&amp;gt; &lt;BR&gt;&amp;lt;script language="javascript" src="http://toysfortweets.com/visualstudiowidget/countdown.js" mce_src="http://toysfortweets.com/visualstudiowidget/countdown.js"&amp;gt; &amp;lt;/script&amp;gt; &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7246715" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="VS 2010" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/VS+2010/default.aspx" /></entry><entry><title>Introduction to Templates in ASP.NET MVC 2 Screen cast</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/11/02/introduction-to-templates-in-asp-net-mvc-2-screen-cast.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/11/02/introduction-to-templates-in-asp-net-mvc-2-screen-cast.aspx</id><published>2009-11-02T20:05:16Z</published><updated>2009-11-02T20:05:16Z</updated><content type="html">&lt;p&gt;I have recorded some screen casts during the last week for Microsoft, one is was published today on Channel 9 (The Screen cast is in Swedish, I will eventually try to record screen casts also in English, but when that happens, I don’t now). You can found the screen cast here:   &lt;br /&gt;    &lt;br /&gt;&lt;a title="http://channel9.msdn.com/posts/MSDNSweden/Introduktion-till-Template-i-ASPNET-MVC-2/" href="http://channel9.msdn.com/posts/MSDNSweden/Introduktion-till-Template-i-ASPNET-MVC-2/"&gt;http://channel9.msdn.com/posts/MSDNSweden/Introduktion-till-Template-i-ASPNET-MVC-2/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For those who can’t understand Swedish, here is a short summary of the screen cast.&lt;/p&gt;  &lt;p&gt;With ASP.NET MVC version 2.0 we can use templates. It will help us rendering forms etc out form the Model we passed to the View. We can easy modify templates to satisfy our needs. The simples way to use the Template feature is to use the Html’s DisplayForModel method:   &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;%= Html.DisplayForModel() %&amp;gt;&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;This method will iterate through the ViewData.ModelMetadata.Properties to render the Model. The ModelMetadata hold information about the model, such as properties etc. The result will remind us about the DetailView control shipped with ASP.NET 2.0, but will put the name of the property at top, and then a new line with the value of the property, like this:    &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;FirstName&lt;/p&gt;  &lt;p&gt;John&lt;/p&gt;  &lt;p&gt;LastName&lt;/p&gt;  &lt;p&gt;Doe&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;There is also a method to render a editable from, EditorForModel. By default the methods will use a default template, we can easy override the template. We do that by adding a ASP.NET MVC User Control to the ~/Views/ControllerName/DisplayTemplates or EditTemplates folder. If you want to override how a String should be “rendered”, then you simply add a String.ascx file to the Templates folders, here is an example of a DisplayTemplate:&lt;/p&gt; &lt;code&gt;   &lt;br /&gt;&amp;lt;%@ Control Language=&amp;quot;C#&amp;quot; Inherits=&amp;quot;System.Web.Mvc.ViewUserControl&amp;quot;%&amp;gt;     &lt;br /&gt;&lt;/code&gt;&lt;code&gt;&amp;lt;i&amp;gt;&amp;lt;%= Html.Encode(Model) %&amp;gt;&amp;lt;/i&amp;gt;&lt;/code&gt;  &lt;p&gt;   &lt;br /&gt;The above template will make the value of the rendered property to use italic:&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;FirstName&lt;/p&gt;  &lt;p&gt;&lt;em&gt;John&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;LastName&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Doe&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;We can do several more stuffs with template, for more information check out the following blog post from &lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html"&gt;Brad Wilson&lt;/a&gt;:&lt;/p&gt;  &lt;li&gt;&lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html"&gt;Part 1: Introduction&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-2-modelmetadata.html"&gt;Part 2: ModelMetadata&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-3-default-templates.html"&gt;Part 3: Default Templates&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-4-custom-object-templates.html"&gt;Part 4: Custom Object Templates&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-5-master-page-templates.html"&gt;Part 5: Master Page Templates&lt;/a&gt;&lt;/li&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;You can find me on twitter: &lt;a href="http://www.twitter.com/fredrikn"&gt;http://www.twitter.com/fredrikn&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7245440" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="ASP.Net" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.Net/default.aspx" /><category term="VS 2010" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/VS+2010/default.aspx" /><category term="ASP.NET MVC" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/ASP.NET+MVC/default.aspx" /></entry><entry><title>Distributing domain entities over the wire</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/10/31/distributing-domain-entities-over-the-wire.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/10/31/distributing-domain-entities-over-the-wire.aspx</id><published>2009-10-31T18:12:46Z</published><updated>2009-10-31T18:12:46Z</updated><content type="html">&lt;p&gt;When we design our domain entities we don’t have a presentation layer or database in mind. The domain entities are core business objects located on the server or client side based of what kind of application we are building. Domain entities aren’t designed for distribution. When we realize that we need a distribution, we shouldn’t distribute the entities, instead collect the data we need to distribute and create a data transfer object (DTO) instead. Have the network in mind, a domain entity aren’t designed with a network in mind and of that reason not suitable for distribution. When we create our domain entities, they aren’t designed for presentation purpose, they are designed to fulfill business needs. You should be careful when you start thinking about returning a domain entity to the View when using a patterns like MVC, instead use DTO or a ViewModel, because once again the domain entities aren’t designed with presentation in mind, and aren’t often suitable for presentation purpose. It’s often better to map them to a DTO or ViewModel, objects that are suitable for presentation purpose or passed over the wire.   &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;I often see demos and example codes where models are generated out from a database. Remember it you do that, your application’s design is driven by a relational database schema, do you really want a database to set the limit in your application design? I don’t. Developers are good at one thing, implementing business logic, that is what they do, that is what they are good at, that is what they should focus on (if we live in the perfect world ;)). We should work against our model. We shouldn’t care about how the database schema looks like. A database is a way to store information, and we have database administrator that are experts in the database area, let them handle the database schema and together with developers map the domain model to the database schema, with the use of an ORM, like Entity Framework 4.0 or nHibernate etc.&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;When it comes to WCF or Web Services, never distribute the domain entities, they aren’t designed for that kind of purpose in the first place(if we don’t use Distributed Domain Driven Design). There is a reason why we call the data sent from a Service as a message. A message is created with network in mind, that is why we use data contracts. When it comes to .NET RIA Services, don’t distribute the Entity Framework generated object or LINQ to SQL, they are generated out from a database schema, and it’s so easy to select whole tables and related tables to get what we want and then we distribute it and forget about the network between the client and server. In some cases we don’t even want to think about the network existence because it adds limit to the information and how we would like to work with objects. But we can’t hide the complexity how much we try, we have to realize that we do have a network, and have that in mind when we design our RIA. We can still on the server-side create our perfect domain model, but we shouldn’t distribute it. Instead transform peace of it into DTOs and only make sure we send the data we are needed. I have seen several examples where developers generate codes from Entity Framework or LINQ to SQL and returns it with .NET RIA Services. When I look at the examples I can see big object graphs passed over the wire and developers are using it as it was local objects, they start to requesting about Lazy Loading support in .NET RIA Services etc. Either they forgot about the network, or they have lack of experience. For&amp;#160; intranet, small database driven applications it can be ok to create a model out from a database schema and distribute it with .NET RIA Services, they don’t often even use business logic, and they don’t need a domain model. But when it comes to large application it’s not often an good idea to generate object out from a database schema and distribute it. In that case DTO is much better option. Not only to limit the data passed, but also because of separation of concerns. The best thing with .NET RIA Services is that it does support DTOs :) Microsoft are good at creating frameworks for developers, but sometimes they want to satisfy everyone, and that often leads to people will use the frameworks in a wrong way. WCF is probably one of the better technologies made from Microsoft, they have learned from the fail of DCOM. When we use WCF we have to create a data contract, which force us to think about what we are distributing, they have also add a small limit of how much data we can by default pass over the wire. I know that some developers think WCF is complex to use and not so easy to learn, but sometimes it shouldn’t be easy to create things that are complex, the complexity is there by some reasons, and it can’t be hidden.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7244009" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="Design" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/Design/default.aspx" /><category term="RIA" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/RIA/default.aspx" /><category term="RIA Services" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/RIA+Services/default.aspx" /><category term="Entitis" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/Entitis/default.aspx" /></entry><entry><title>VS 2010 Beta 2 and .Net 4.0 is now available for downloading from MSDN Sub.</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/10/21/vs-2010-beta-2-and-net-4-0-is-now-available-for-downloading-from-msdn-sub.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/10/21/vs-2010-beta-2-and-net-4-0-is-now-available-for-downloading-from-msdn-sub.aspx</id><published>2009-10-21T11:39:00Z</published><updated>2009-10-21T11:39:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;Oh, I'm late.. but better late then never.. you can now download VS 2010 nad .Net 4.0 Beta 2, if you are a MSDN Subscriber.. You can read more about VS 2010 Beta 2 on &lt;A href="http://weblogs.asp.net/scottgu/archive/2009/10/19/vs-2010-and-net-4-0-beta-2.aspx" mce_href="http://weblogs.asp.net/scottgu/archive/2009/10/19/vs-2010-and-net-4-0-beta-2.aspx"&gt;Scott Guthrie's&lt;/A&gt; blog.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;Wow, my shortest blog post ever!&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7234892" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term=".NET 4.0" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/.NET+4.0/default.aspx" /><category term="VS 2010" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/VS+2010/default.aspx" /></entry><entry><title>ASP.NET 4.0 Web Form routing</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/10/14/asp-net-4-0-web-form-routing.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/10/14/asp-net-4-0-web-form-routing.aspx</id><published>2009-10-14T07:43:26Z</published><updated>2009-10-14T07:43:26Z</updated><content type="html">&lt;p&gt;One of hundreds things I like about ASP.NET MVC, is the routing, a way to use clear and friendly URLs like: &lt;a href="http://www.server.com/Customer/List"&gt;www.server.com/Customer/List&lt;/a&gt;, instead of something like &lt;a href="http://www.server.com/Customers.aspx"&gt;www.server.com/Customers.aspx&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The routing part is now also added to the ASP.NET Web Form 4.0, so we can now use routing to avoid pointing to a .aspx file and ugly query stings. &lt;a href="http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx"&gt;Scott Guthrie&lt;/a&gt; have wrote a blog post about it &lt;a href="http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx"&gt;here&lt;/a&gt;. I will only write a short post to introduce it.&lt;/p&gt;  &lt;p&gt;To define a route, we will use the Application_Start event of the Gloabal.asax file (a file which will be “executed” every time we visit a .aspx page). The Application_Start event will only be executed one time, and that is when the application starts (the first user visit our app). By using the static RouteTable class, we can add routes to the RouteTable’s Routes collection. This is done by using the MapPageRoute method. The MapPageRoute method can take some parameters, for example the name of the Route (to give a route an identifier so we can get and create routes in our code), the new URL where we also can specify parameters and route constraints etc. So for example if we have a URL look like this: &lt;a href="http://www.server.com/Customer.aspx?id=10"&gt;www.server.com/Customer.aspx?id=10&lt;/a&gt;, we can use the Route feature to use a URL like this instead: &lt;a href="http://www.server.com/Customer/10"&gt;www.server.com/Customer/10&lt;/a&gt;. The following code will setup this route:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; RegisterRoutes(RouteCollection routes)
{
      routes.MapPageRoute(
          &lt;span class="str"&gt;&amp;quot;viewCustomerDetails&amp;quot;&lt;/span&gt;,
         &lt;span class="str"&gt;&amp;quot;Customer/{ID}&amp;quot;&lt;/span&gt;,
        &lt;span class="str"&gt;&amp;quot;~/Customer.aspx&amp;quot;&lt;/span&gt;);
}

&lt;span class="kwrd"&gt;void&lt;/span&gt; Application_Start()
{
       RegisterRoutes(RouteTable.Routes);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;br /&gt;I like this feature and will use it in all of my Web apps, where I need to use Web Forms, I will mostly use the ASP.NET MVC framework ;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7229523" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author></entry><entry><title>Some features I love in VS 2010</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/fredriknormen/archive/2009/10/08/some-features-i-love-in-vs-2010.aspx" /><id>http://weblogs.asp.net/fredriknormen/archive/2009/10/08/some-features-i-love-in-vs-2010.aspx</id><published>2009-10-08T12:12:00Z</published><updated>2009-10-08T12:12:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;This post will not be so long, I want to write a little about some Visual Studio 2010 features I love. First of all the changes made to C# is great, the default value on parameters rocks! When I implement Frameworks, I often ended up with something like this:&lt;/P&gt;
&lt;P mce_keep="true"&gt;public void Log(string message)&lt;BR&gt;&lt;BR&gt;public void Log(string message, string category)&lt;/P&gt;
&lt;P mce_keep="true"&gt;public void Log(string message, string category, .......)&lt;/P&gt;
&lt;P mce_keep="true"&gt;The last method is the one that have the most of the code, the other method with few parameters, only calls the last one, and pass null or an empty string as values to the extra arguments:&lt;/P&gt;
&lt;P mce_keep="true"&gt;Log(message, null, ......)&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;&lt;EM&gt;Note: The code above is not taken from a real example, only used as pseudo code.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now with C# 4.0, we can instead set a default value on a argument, which will get rid of the extra methods, for example:&lt;BR&gt;&lt;BR&gt;public void Log(string message, string category = null, .....)&lt;/P&gt;
&lt;P mce_keep="true"&gt;The dynamic&amp;nbsp;feature in C# is ok, but at the moment I will not use it. When we use the dynamic when we declare a varible, it will be evaluated first at runtime. It's a nice feature when we want C# to use stuff from other dynamic languages.&lt;/P&gt;
&lt;P mce_keep="true"&gt;dynamic something = ....&lt;/P&gt;
&lt;P mce_keep="true"&gt;something.Hello();&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Entity Framework 4.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Will be great now when it will support POCO (Plain old clr object):&lt;/P&gt;
&lt;P mce_keep="true"&gt;public class Customer&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public string FirstName&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get { ... }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set&amp;nbsp;{ ... }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;There are so many other features improvements to EF, need a new blog post for that, but the POCO support and the&amp;nbsp;model first&amp;nbsp;approached is better supported than the first version.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;ASP.NET AJAX 4.0&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;I love the client-side binding, I have some blog post about it, so you can read about it here:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/09/16/asp-net-ajax-4-0-preview-5-working-with-converters-and-the-new-cdn.aspx"&gt;http://weblogs.asp.net/fredriknormen/archive/2009/09/16/asp-net-ajax-4-0-preview-5-working-with-converters-and-the-new-cdn.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/09/11/keep-the-first-empty-item-in-a-listbox-when-using-asp-net-ajax-4-0-preview-5-and-observer.aspx"&gt;http://weblogs.asp.net/fredriknormen/archive/2009/09/11/keep-the-first-empty-item-in-a-listbox-when-using-asp-net-ajax-4-0-preview-5-and-observer.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A href="http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx"&gt;http://weblogs.asp.net/fredriknormen/archive/2009/09/11/asp-net-ajax-4-0-preview-5-available.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Silverlight designer&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Studio 2010 have now enabled the Silverlight designer, it was not enabled in the previous Visual Studio, so we can now easier and faster create our Silverlight apps, and no need to run Expression Blend and VS at the same time.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Improvements for web developer&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Better Java-script intellisense. Easier to&amp;nbsp;add Server controls to the .aspx file. Something we need to add before was the runat="seerver" attribute, it's now directly added when we add a Server control in the source mode (not talking about to drag a control, it when we write the code).&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Code Contract&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;I&amp;nbsp;like design-by-contract, think everyone should read about it. We can now use code contract in our code. What I have heard, we need the VSTS version for static checking. You can read more avout Code contract here: &lt;A href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx"&gt;http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx&lt;/A&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7225498" width="1" height="1"&gt;</content><author><name>Fredrik N</name><uri>http://weblogs.asp.net/members/Fredrik-N.aspx</uri></author><category term="Visual Studio 2010" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/Visual+Studio+2010/default.aspx" /><category term=".NET 4.0" scheme="http://weblogs.asp.net/fredriknormen/archive/tags/.NET+4.0/default.aspx" /></entry></feed>