<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Barry Jones &#187; Useful MVC Resources &#8211; Barry Jones</title>
	<atom:link href="http://www.barryjones.me.uk/tag/pattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.barryjones.me.uk</link>
	<description>General Ramblings</description>
	<lastBuildDate>Mon, 06 Sep 2010 10:05:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Useful MVC Resources</title>
		<link>http://www.barryjones.me.uk/2010/09/useful-mvc-resources/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=useful-mvc-resources</link>
		<comments>http://www.barryjones.me.uk/2010/09/useful-mvc-resources/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 08:00:03 +0000</pubDate>
		<dc:creator>Barry Jones</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Pattern]]></category>
		<category><![CDATA[Resources]]></category>

		<guid isPermaLink="false">http://www.barryjones.me.uk/?p=234</guid>
		<description><![CDATA[While learning anything new there are times when you stumble upon information on the Internet that really seems to help. Here a list of links and websites that have helped me get a better understanding of the Microsoft&#8217;s MVC .NET Framework, it&#8217;s architecture and how to use it. But first the pattern: Martin Fowlers Discussion [...]]]></description>
			<content:encoded><![CDATA[<p>While learning anything new there are times when you stumble upon information on the Internet that really seems to help. Here a list of links and websites that have helped me get a better understanding of the <em>Microsoft&#8217;s <acronym title="Model View Controller">MVC</acronym> .NET Framework</em>, it&#8217;s architecture and how to use it.<span id="more-234"></span></p>
<p>But first the pattern: <a title="MVC Pattern Description" href="http://martinfowler.com/eaaDev/uiArchs.html" target="_blank">Martin Fowlers Discussion of the MVC Pattern</a>.</p>
<h3>General MVC Resources</h3>
<p>These links are websites with lots of various information about <em><acronym title="Model View Controller">MVC</acronym></em>, with no specific focus.</p>
<ul>
<li><a title="Microsoft MVC Website" href="http://www.asp.net/mvc" target="_blank">Microsoft&#8217;s MVC Framework Website</a></li>
<li><a title="Scott Hanselman on MVC" href="http://www.hanselman.com/blog/CategoryView.aspx?category=ASP.NET+MVC" target="_blank">All of Scott Hanselman&#8217;s MVC Posts</a></li>
<li><a title="Scott Gu" href="http://weblogs.asp.net/Scottgu" target="_blank">Scott Guthrie for eveything .NET</a></li>
<li><a title="MSDN MVC Introduction" href="http://msdn.microsoft.com/en-us/magazine/cc337884.aspx" target="_blank">An introduction to MVC</a></li>
<li><a title="MSDN MVC Resources" href="http://msdn.microsoft.com/en-us/library/dd394709%28VS.100%29.aspx" target="_blank">A list of MSDN resources for learning the details of the MVC Framework</a></li>
</ul>
<h3>Architecture and Pipeline</h3>
<p>A very good description of the full request response pipeline in MVC.NET, this is for version 1.0 but the information is still useful.</p>
<ul>
<li><a title="MVC Architecture" href="http://dotnetslackers.com/articles/aspnet/AnArchitecturalViewOfTheASPNETMVCFramework.aspx" target="_blank">Architectural Overview of MVC Framework</a></li>
<li><a title="MVC Pipeline Lifecycle" href="http://blog.codeville.net/2007/11/20/aspnet-mvc-pipeline-lifecycle/" target="_blank">V1.0 Request/Response Pipeline Overview</a></li>
</ul>
<h3>Model Binding Information</h3>
<ul>
<li><a title="MVC Model Binders" href="http://blog.maartenballiauw.be/post/2008/10/02/Using-the-ASPNET-MVC-ModelBinder-attribute-Second-part.aspx" target="_blank">Creating a Model Binder</a></li>
<li><a title="IModelBinder implementation" href="http://panteravb.com/blog/posts/2008/10/2/imodelbinder-with-autobinder.ashx" target="_blank">IModelBinder Autobinding</a></li>
</ul>
<h3>Routing</h3>
<ul>
<li><a title="MSDN description of MVC Routing" href="http://msdn.microsoft.com/en-us/library/cc668201%28VS.100%29.aspx" target="_blank">MSDN Review of the MVC Routing Process</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.barryjones.me.uk/2010/09/useful-mvc-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically Populate DTOs</title>
		<link>http://www.barryjones.me.uk/2009/10/automatically-populate-dtos/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automatically-populate-dtos</link>
		<comments>http://www.barryjones.me.uk/2009/10/automatically-populate-dtos/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 20:07:09 +0000</pubDate>
		<dc:creator>Barry Jones</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[DTO]]></category>
		<category><![CDATA[Pattern]]></category>

		<guid isPermaLink="false">http://carl.barryjones.me.uk/?p=15</guid>
		<description><![CDATA[The lowly DTO, a pattern described by Martin Fowler that enables you to reduce the number of API calls you make across a remote boundary; it allows this by grouping all the data in to a new data type and returning that instead. I have however found that this pattern can cause you to write [...]]]></description>
			<content:encoded><![CDATA[<p>The lowly <a title="DTO Pattern" href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"><acronym title="Data Transfer Object">DTO</acronym></a>, a pattern described by <a title="Martin Fowler" href="http://martinfowler.com/" target="_blank">Martin Fowler</a> that enables you to reduce the number of API calls you make across a remote boundary; it allows this by grouping all the data in to a new data type and returning that instead. I have however found that this pattern can cause you to write a lot of code that is nothing more than property setting. The code provided in this post (<a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/BarryJones.DataTransferObjects.zip">here</a>) allows you to automate the population of these <acronym title="Data Transfer Object">DTO</acronym>s saving you time, so you can get on with something more important like drinking coffee.<span id="more-15"></span></p>
<h2>Automating DTO Population</h2>
<p>First of all grab yourself a copy of the <a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/BarryJones.DataTransferObjects.zip">source</a> code. A general overview of the process is; you specify — using attributes — the mappings between your business objects and your data transfer objects. These attributes can describe simple properties, complex properties and collections. After that is done, throw the object at the converter and Bob&#8217;s your uncle!</p>
<h3>Mapping DTO Properties with Attributes</h3>
<p>There are two attributes DTOSimpleMapper and DTOCollectionMapper; the basic signature of the attributes is shown below.</p>
<pre class="code">[DTOSimpleMapper(params string[] fields)]
[DTOCollectionMapper(Type ofType, string fromField)]</pre>
<pre class="code">[DTOSimpleMapper("FromProperty.Child.Identifier")]
public int ConvertedProperty;</pre>
<p>The ‘fields’ and ‘fromField’ parameters describe the property on the origin object that is to be converted. The destination for the conversion is always the property the attribute is decorating. The fields are represented as a string where the field is a child property the ‘.’ notation can be used to indicate this. I.e. &#8220;Parent.Child.Child&#8221;.<br />
The params string[] parameters on both attributes can be used to describe more complex conversions, when the converting types have multiple properties the conversion can be described by passing in an array of strings which define the from and to properties. I.e:</p>
<pre class="code">[DTOSimpleMapper("Prop1.Prop2=Identifier", "Prop2.Prop1=Name")]</pre>
<p>The first parameter on the DTOCollectionMapper tells the converter what the destination array elements are:</p>
<pre class="code">[DTOCollectionMapper(typeof(string), "FromProperty"]
public string[] ConvertedCollection;</pre>
<p>The converter will work with any collection that implements IEnumerable. As with the simple mapper, the property name can describe more complex conversions. This is useful where you have a generic <acronym title="Data Transfer Object">DTO</acronym> that is used to describe many elements:</p>
<pre class="code">[DTOCollectionMapper(typeof(IdentifiedElement), "FromPoperty", "Identifier=Identifier",
"Child.Name=Name")]
public List Children;</pre>
<p>Finally where the conversions are more complex the type for the property can describe its own conversion:</p>
<pre class="code">Public class RelatedChildDTO {
     [DTOSimpleMapper("Identifier")] public int Identifier;
     [DTOSimpleMapper("Name")] public string Name;
}
Public class ParentDTO {
     [DTOSimpleMapper("Child")]
     public RelatedChildDTO Child;
}</pre>
<p>With the above example the converter will check the type of instance it is creating and use the attributes described on that type to perform the conversion.</p>
<h2>Conditional Population</h2>
<p>Both of the attributes allow for Type conditional conversions as well, both are overloaded with a type property that is checked in the conversion process and only performed when the origin type is the same:</p>
<pre class="code">[DTOSimpleMapper(typeof(ConditionalBusinessObject), "FromProperty")]
public string ConvertedProperty;</pre>
<h2>Automatic Conversion</h2>
<p>Now you have described the way objects are converted we are left with actual conversion, the library has a Converter class with a simple static method called Convert. This method takes an instance of an origin object and a type for the destination object.</p>
<pre class="code">BusinessObject bus = new BusinessObject();
// set business properties
DTO dto = (DTO)Convertor.Convert(bus, typeof(DTO));</pre>
<p>The result of this method call is that the <acronym title="Data Transfer Object">DTO</acronym> is created and populated using the attributes, the conversion is done!<br />
Here is the <a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/BarryJones.DataTransferObjects.zip">source code</a>, it contains test classes which should give you a better idea of how it all works, enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryjones.me.uk/2009/10/automatically-populate-dtos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

