<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3109374999835349472</id><updated>2010-09-04T19:34:11.461+10:00</updated><title type='text'>Jorge Fioranelli</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.jorgef.net/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default?orderby=updated'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-1601336511344026018</id><published>2010-09-04T19:01:00.007+10:00</published><updated>2010-09-04T19:34:11.469+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.Net 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='Entity Framework'/><title type='text'>N-Tiers using POCOs and Entity Framework - Part Two: Model and Entities</title><content type='html'>&lt;p&gt;Following Domain Driven Design (DDD) principles [Evans, DDD], the domain should be represented by objects with state and behavior, using a rich object-oriented model. Additionally, in n-tier applications it is ideal to reuse as many objects as you could in order to reduce code duplication.&lt;br&gt;&lt;/p&gt; &lt;p&gt;However, the object’s behavior is usually very different in each tier; for example, in the business tier the behavior is often business-oriented and it shouldn’t be executed in the presentation tier.&lt;br&gt;&lt;/p&gt; &lt;p&gt;To solve this problem, we can use POCOs with only state (properties), and add behavior to them using extension methods in the business tier.&lt;/p&gt; &lt;p&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Model-Entities" border="0" alt="Model-Entities" src="http://lh5.ggpht.com/_3OJ07UNFNWY/TIHuEs0t5NI/AAAAAAAAAKI/0qIlvVfeVVw/ModelEntities10.png?imgmax=800" width="380" height="158"&gt; &lt;/p&gt; &lt;table style="border-bottom: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; display: block; float: none; margin-left: auto; border-top: #aaaaaa 1px solid; margin-right: auto; border-right: #aaaaaa 1px solid" cellspacing="2" cellpadding="2" width="90%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top"&gt;&lt;strong&gt;Note&lt;/strong&gt;: Although extension methods provide a good extensibility mechanism, they have some limitations. For example, they don’t support late-bound polymorphism (virtual methods).&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;In the following code snippet we can see the Order and Product POCOs, related each other through the Product and the Product_ID properties.&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;namespace Common.Domain.Entities&lt;br /&gt;{&lt;br /&gt;  public class Order&lt;br /&gt;  {&lt;br /&gt;    public int Id { get; set; }&lt;br /&gt;    public Product Product { get; set; }&lt;br /&gt;    public int Product_ID { get; set; }&lt;br /&gt;    public int Quantity { get; set; }&lt;br /&gt;    ...&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public class Product&lt;br /&gt;  {&lt;br /&gt;    public int Id { get; set; }&lt;br /&gt;    public string Description { get; set; }&lt;br /&gt;    public int Stock { get; set; }&lt;br /&gt;    ...&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;table style="border-bottom: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; display: block; float: none; margin-left: auto; border-top: #aaaaaa 1px solid; margin-right: auto; border-right: #aaaaaa 1px solid" cellspacing="2" cellpadding="2" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top"&gt;&lt;strong&gt;Note&lt;/strong&gt;: EF supports two types of associations: Independent Associations (Product property) and Foreign Key Associations (Product_ID property). While the first ones are the most popular because are more object-oriented, the second ones are very useful in “disconnected” scenarios (e.g. when you need to update the relationship and you don’t have access to the EF context).&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;And as we mentioned before, the behavior of both objects is added using the extension methods defined in the following classes.&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;namespace Business.Domain.Entities&lt;br /&gt;{&lt;br /&gt;  public static class OrderExtensions&lt;br /&gt;  {&lt;br /&gt;    public static void Confirm(this Order order) { ... }&lt;br /&gt;    public static void Cancel(this Order order) { ... }&lt;br /&gt;    ...&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public static class ProductExtensions&lt;br /&gt;  {&lt;br /&gt;    public static void SubstractStock(this Product product) { ... }&lt;br /&gt;    public static void RestoreStock(this Product product) { ... }&lt;br /&gt;    ...&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;This allows us to call the specific domain behavior using the entity instance.&lt;/p&gt;&lt;br /&gt;&lt;pre class="brush: csharp;"&gt;order.Confirm();&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;It is also important to mention that there are some scenarios where the entity does not match with the data that should be shown in the presentation layer, e.g. let’s say it is required to show the customer’s name and the description of the latest ten products that he or she ordered. In those cases it could be a better option to create a customized Data Transfer Object (DTO) in order to transfer over the wire only the data needed.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="DTO" border="0" alt="DTO" src="http://lh5.ggpht.com/_3OJ07UNFNWY/TIHuFiJp3EI/AAAAAAAAAKM/wwYsfNNTDjY/DTO%5B5%5D.png?imgmax=800" width="231" height="227"&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;table style="border-bottom: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; display: block; float: none; margin-left: auto; border-top: #aaaaaa 1px solid; margin-right: auto; border-right: #aaaaaa 1px solid" cellspacing="2" cellpadding="2" width="90%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top"&gt;&lt;strong&gt;Note&lt;/strong&gt;: If your architecture must support “cross-process change tracking”, I recommend you to use the “self-tracking entities” EF feature, an excellent feature designed for n-tier applications. Since it increases the amount of data that is sent over the wire, you should use this feature only if it is required.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;br /&gt;&lt;h2&gt;References:&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;Evans, DDD: Evans, Eric. Domain-Driven Design: Tackling Complexity in the Heart of Software, Boston, MA: Addison-Wesley 2004.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h2&gt;Posts in this series:&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;a href="http://blog.jorgef.net/2010/09/n-tiers-pocos-ef-1.html"&gt;Architecture&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.jorgef.net/2010/09/n-tiers-pocos-ef-2.html"&gt;Model and Entities&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-1601336511344026018?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/1601336511344026018/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=1601336511344026018' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/1601336511344026018'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/1601336511344026018'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2010/09/n-tiers-pocos-ef-2.html' title='N-Tiers using POCOs and Entity Framework - Part Two: Model and Entities'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-6370180792654247813</id><published>2010-09-01T18:56:00.001+10:00</published><updated>2010-09-04T19:22:02.121+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.Net 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='Entity Framework'/><title type='text'>N-Tiers using POCOs and Entity Framework - Part One: Architecture</title><content type='html'>&lt;p&gt;The ADO.NET Entity Framework comes with features like “persistence ignorance” and “POCO support” which allow the use of simple objects as persistent entities and the development of n-tier applications in an easier way. &lt;/p&gt; &lt;p&gt;The purpose of these post series is to show an example of an n-tier application that takes advantage of these features.&lt;/p&gt; &lt;p&gt;In n-tier architectures, each tier can be executed in a different process and potentially in a different server. In fact, every application that uses a database server and an internet browser has at least three tiers, so it could be considered an n-tier application. Nevertheless, in the .NET world it is very common to catalog as n-tier applications those in which the .NET code is separated by at least two processes, generally using technologies such as SOAP Web Services, .NET Remoting or Windows Communication Foundation (WCF).&lt;/p&gt; &lt;p&gt;The example application has the following architecture:&lt;/p&gt; &lt;p&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Architecture" border="0" alt="Architecture" src="http://lh6.ggpht.com/_3OJ07UNFNWY/THj6x0QascI/AAAAAAAAAJk/HjO-BCDq4LA/Architecture%5B16%5D.png?imgmax=800" width="465" height="342"&gt; &lt;/p&gt; &lt;p&gt;The application’s architecture is split into two tiers:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;The presentation tier, which has the responsibility to execute the user interface logic using the “Model-View-Controller” (MVC) pattern [Fowler, PEAA].  &lt;li&gt;The business tier, which contains all the business and data access logic. This tier uses the “Unit of Work” and “Repository” patterns [Fowler, PEAA] combined with an Object Relational Mapper (Entity Framework).&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;In this architecture, the Model and the Entities are represented by the Plain Old CLR Objects (POCOs) that are serialized and transported over the wire between both tiers.&lt;/p&gt; &lt;p&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Tiers" border="0" alt="Tiers" src="http://lh4.ggpht.com/_3OJ07UNFNWY/THj6zlnVCUI/AAAAAAAAAJw/ruU4RhcSARo/Tiers%5B6%5D.png?imgmax=800" width="304" height="114"&gt; &lt;/p&gt; &lt;table style="border-bottom: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; display: block; float: none; margin-left: auto; border-top: #aaaaaa 1px solid; margin-right: auto; border-right: #aaaaaa 1px solid" cellspacing="2" cellpadding="2" width="90%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" width="958"&gt;&lt;strong&gt;Note:&lt;/strong&gt; Plain Old CLR Objects (POCOs) are ordinary .NET classes without any infrastructure-related stuff. POCOs don’t have to inherit from a certain base class or to implement a specific interface. They are clean objects with persistence ignorance [Nilsson, ADDDP].&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;h2&gt;&amp;nbsp;&lt;/h2&gt; &lt;h2&gt;References:&lt;/h2&gt; &lt;ul&gt; &lt;li&gt;Fowler, PEAA: Fowler, Martin. Patterns of Enterprise Application Architecture, Boston, MA: Addison-Wesley 2003.  &lt;li&gt;Nilsson, ADDDP: Nilsson, Jimmy. Applying Domain-Driven Design and Patterns with examples in C# and .NET, Boston, MA: Addison-Wesley 2006. &lt;/li&gt;&lt;/ul&gt;&lt;br/&gt;&lt;h2&gt;Posts in this series:&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;a href="http://blog.jorgef.net/2010/09/n-tiers-pocos-ef-1.html"&gt;Architecture&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.jorgef.net/2010/09/n-tiers-pocos-ef-2.html"&gt;Model and Entities&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-6370180792654247813?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/6370180792654247813/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=6370180792654247813' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/6370180792654247813'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/6370180792654247813'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2010/09/n-tiers-pocos-ef-1.html' title='N-Tiers using POCOs and Entity Framework - Part One: Architecture'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-457674772949457302</id><published>2010-01-30T01:54:00.001+11:00</published><updated>2010-02-12T10:13:32.001+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='IronPython'/><title type='text'>WPF Dependency Properties in IronPython</title><content type='html'>&lt;p&gt;One of the best features added to WPF are &lt;a href="http://msdn.microsoft.com/en-us/library/ms752914.aspx"&gt;Dependency Properties&lt;/a&gt;. Dependency properties use a combination of a property and a static field (a class field in python). &lt;/p&gt;&lt;p&gt;As follows you will find an example:&lt;/p&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;import&lt;/span&gt; clr &lt;/p&gt;&lt;p&gt;clr.AddReference(&lt;span style="color:#800040;"&gt;"WindowsBase"&lt;/span&gt;)&lt;br /&gt;clr.AddReference(&lt;span style="color:#800040;"&gt;"PresentationCore"&lt;/span&gt;)&lt;br /&gt;clr.AddReference(&lt;span style="color:#800040;"&gt;"PresentationFramework"&lt;/span&gt;) &lt;/p&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; System.Windows &lt;span style="color:#0000ff;"&gt;import&lt;/span&gt; (&lt;br /&gt;    DependencyObject, DependencyProperty&lt;br /&gt;) &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Planning(DependencyObject):&lt;br /&gt;&lt;br /&gt;    _sessionProperty = &lt;span style="color:#0000ff;"&gt;None&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:#0000ff;"&gt;def&lt;/span&gt; __new__(cls):&lt;br /&gt;       &lt;span style="color:#0000ff;"&gt;if not&lt;/span&gt; Planning._sessionProperty:&lt;br /&gt;            Planning._sessionProperty = DependencyProperty.Register(&lt;br /&gt;                &lt;span style="color:#800040;"&gt;"session"&lt;/span&gt;, clr.GetClrType(Session), clr.GetClrType(Planning))   &lt;br /&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; DependencyObject.__new__(cls)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:#0000ff;"&gt;def&lt;/span&gt; getSession(self):&lt;br /&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; self.GetValue(Planning._sessionProperty)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:#0000ff;"&gt;def&lt;/span&gt; setSession(self, value):&lt;br /&gt;        self.SetValue(Planning._sessionProperty, value)&lt;br /&gt;&lt;br /&gt;    session = &lt;span style="color:#0000ff;"&gt;property&lt;/span&gt;(getSession, setSession)&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-457674772949457302?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/457674772949457302/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=457674772949457302' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/457674772949457302'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/457674772949457302'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2010/01/wpf-dependency-properties-in-ironpython.html' title='WPF Dependency Properties in IronPython'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-3039146601667405881</id><published>2010-02-03T02:25:00.001+11:00</published><updated>2010-02-03T02:25:03.169+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='IronPython'/><title type='text'>WPF Commands in IronPython</title><content type='html'>&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms752914.aspx"&gt;Dependency Properties&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/ms752308.aspx"&gt;Commands&lt;/a&gt; are very useful WPF features.&lt;/p&gt;  &lt;p&gt;In my last &lt;a href="http://blog.jorgef.com.ar/2010/01/wpf-dependency-properties-in-ironpython.html"&gt;post&lt;/a&gt; I wrote about how to use Dependency Properties in IronPython. In this post we will see how to implement and use the WPF RelayCommand (for more details see &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx"&gt;WPF Apps With The Model-View-ViewModel Design Pattern&lt;/a&gt;).&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;import&lt;/font&gt; clr &lt;/p&gt;  &lt;p&gt;clr.AddReference(&lt;font color="#800040"&gt;&amp;quot;WindowsBase&amp;quot;&lt;/font&gt;)     &lt;br /&gt;clr.AddReference(&lt;font color="#800040"&gt;&amp;quot;PresentationCore&amp;quot;&lt;/font&gt;)     &lt;br /&gt;clr.AddReference(&lt;font color="#800040"&gt;&amp;quot;PresentationFramework&amp;quot;&lt;/font&gt;) &lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;from&lt;/font&gt; System &lt;font color="#0000ff"&gt;import&lt;/font&gt; (    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; EventArgs    &lt;br /&gt;)&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;from&lt;/font&gt; System.Windows &lt;font color="#0000ff"&gt;import&lt;/font&gt; (     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; DependencyObject     &lt;br /&gt;) &lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;from&lt;/font&gt; System.Windows.Input &lt;font color="#0000ff"&gt;import&lt;/font&gt; (     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ICommand     &lt;br /&gt;)&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;class&lt;/font&gt; RelayCommand(ICommand):     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; __init__(self, executeFunction, canExecuteFunction):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; self._executeFunction = executeFunction     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; self._canExecuteFunction = canExecuteFunction     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; self._handlers = []     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; CanExecute(self, parameter):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;return&lt;/font&gt; self._canExecuteFunction(parameter)     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; add_CanExecuteChanged(self, handler):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; self._handlers.append(handler)     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; remove_CanExecuteChanged(self, handler):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; self._handlers.remove(handler)     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; canExecuteChanged(self):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; for handler in self._handlers:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; handler(self, EventArgs.Empty)     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; Execute(self, parameter):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; self._executeFunction(parameter)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; self.canExecuteChanged()&lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;class&lt;/font&gt; Planning(DependencyObject):     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; _sessionProperty = &lt;font color="#0000ff"&gt;None&lt;/font&gt;     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; __new__(cls):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;if not&lt;/font&gt; Planning._sessionProperty:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Planning._sessionProperty = DependencyProperty.Register(     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#800040"&gt;&amp;quot;session&amp;quot;&lt;/font&gt;, clr.GetClrType(Session), clr.GetClrType(Planning))&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;return&lt;/font&gt; DependencyObject.__new__(cls)    &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; __init__(self):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; self.loginCommand = RelayCommand(&lt;font color="#0000ff"&gt;lambda&lt;/font&gt; p : self.login(p), &lt;font color="#0000ff"&gt;lambda&lt;/font&gt; p : not self.session)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; login(self, user):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; self.session = Session(user)     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; getSession(self):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;return&lt;/font&gt; self.GetValue(Planning._sessionProperty)     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; setSession(self, value):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; self.SetValue(Planning._sessionProperty, value)     &lt;br /&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; session = &lt;font color="#0000ff"&gt;property&lt;/font&gt;(getSession, setSession)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-3039146601667405881?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/3039146601667405881/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=3039146601667405881' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/3039146601667405881'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/3039146601667405881'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2010/02/wpf-commands-in-ironpython.html' title='WPF Commands in IronPython'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-1193159843472134836</id><published>2009-12-28T10:26:00.001+11:00</published><updated>2009-12-28T10:26:31.184+11:00</updated><title type='text'>Using an IronPython object from C#</title><content type='html'>&lt;p&gt;The new keyword “dynamic” added to C# (.Net 4.0) allows you to interoperate with any dynamic language such as IronPython or IronRuby.&lt;/p&gt;  &lt;p&gt;This new feature bypasses any static type checking at compile time, assuming that any operation is allowed. But, if it is not allowed, an error will be showed at run time.&lt;/p&gt;  &lt;p&gt;For example, the following Customer “IronPython Class” is invoked from the C# code as a dynamic object:&lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;&lt;strong&gt;IronPython code (Sample.py)&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#008040"&gt;# Function (method) that creates a new Customer      &lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;def&lt;/font&gt; CreateCustomer(firstName, lastName):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;return&lt;/font&gt; Customer(firstName, lastName) &lt;/p&gt;  &lt;p&gt;&lt;font color="#008040"&gt;# Customer object &lt;/font&gt;    &lt;br /&gt;&lt;font color="#0000ff"&gt;class&lt;/font&gt; Customer(object):&amp;#160; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008040"&gt;# Initialization (constructor) &lt;/font&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; __init__(&lt;font color="#0000ff"&gt;self&lt;/font&gt;, firstName, lastName):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;self&lt;/font&gt;._firstName = firstName     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;self&lt;/font&gt;._lastName = lastName &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008040"&gt;# Function (method) that print the customer&lt;/font&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;def&lt;/font&gt; printNames(&lt;font color="#0000ff"&gt;self&lt;/font&gt;):     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;print&lt;/font&gt; &lt;font color="#0000ff"&gt;self&lt;/font&gt;._firstName + ' ' + &lt;font color="#0000ff"&gt;self&lt;/font&gt;._lastName&lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;&lt;strong&gt;C# code (Program.cs)&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; Microsoft.Scripting.Hosting;     &lt;br /&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; IronPython.Hosting;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#408080"&gt;Program&lt;/font&gt;     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;static void&lt;/font&gt; Main(&lt;font color="#0000ff"&gt;string&lt;/font&gt;[] args)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;  &lt;p&gt;&lt;font color="#408080"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ScriptRuntime&lt;/font&gt; py = &lt;font color="#408080"&gt;Python&lt;/font&gt;.CreateRuntime();     &lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; dynamic&lt;/font&gt; sample = py.UseFile(&lt;font color="#800000"&gt;&amp;quot;Sample.py&amp;quot;&lt;/font&gt;);     &lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; dynamic&lt;/font&gt; customer = sample.CreateCustomer(&lt;font color="#800040"&gt;&amp;quot;Paul&amp;quot;&lt;/font&gt;, &lt;font color="#804040"&gt;&amp;quot;Smith&amp;quot;&lt;/font&gt;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; customer.printNames();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;You can download the source code &lt;a href="http://files.jorgef.com.ar/code/Dynamic.zip"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-1193159843472134836?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/1193159843472134836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=1193159843472134836' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/1193159843472134836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/1193159843472134836'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/12/using-ironpython-object-from-c.html' title='Using an IronPython object from C#'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-6700267504149933497</id><published>2009-12-22T21:44:00.001+11:00</published><updated>2009-12-22T21:45:58.132+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.Net 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='PLINQ'/><title type='text'>Using PLINQ to improve performance</title><content type='html'>&lt;p&gt;The version 4.0 of .Net has a new feature called “Parallel LINQ” or PLINQ. If you use LINQ to filter or process a large amount of objects in memory and/or it is required a high-cost evaluation, PLINQ is for you.&lt;/p&gt;  &lt;p&gt;PLINQ segments the source in parts and it uses different threads in order to process each segment.&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt; validCustomers = allCustomers&lt;strong&gt;.&lt;font color="#400080"&gt;&lt;font color="#000040"&gt;AsParallel()&lt;/font&gt;         &lt;br /&gt;&lt;/font&gt;&lt;/strong&gt;&amp;#160; .Where(c =&amp;gt; c.IsValid())     &lt;br /&gt;&amp;#160; .ToArray();&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PLINQ" border="0" alt="PLINQ" src="http://lh4.ggpht.com/_3OJ07UNFNWY/SzCjJfg6zSI/AAAAAAAAAI4/aEDyd3pICdg/PLINQ1.png?imgmax=800" width="563" height="251" /&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://files.jorgef.com.ar/code/PLINQ.zip"&gt;Here&lt;/a&gt; you can download the sample code.&lt;/p&gt;  &lt;p&gt;For more details I recommend you to watch the Igor Ostrovsky &lt;a href="http://microsoftpdc.com/Sessions/FT21"&gt;presentation&lt;/a&gt; in the PDC 2009 webpage.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-6700267504149933497?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/6700267504149933497/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=6700267504149933497' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/6700267504149933497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/6700267504149933497'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/12/using-plinq-to-improve-performance.html' title='Using PLINQ to improve performance'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-1582992773101294286</id><published>2009-11-26T22:45:00.001+11:00</published><updated>2009-12-17T22:07:17.607+11:00</updated><title type='text'>WF Course</title><content type='html'>&lt;p&gt;Last week I was teaching a three days course about WF (Windows Workflow Foundation).&lt;/p&gt;  &lt;p&gt;The content was the following:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Day One&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="WF" border="0" alt="WF" align="right" src="http://lh4.ggpht.com/_3OJ07UNFNWY/Sw5qWq73J7I/AAAAAAAAAIY/J5-_1NLfQmY/WF%5B3%5D.png?imgmax=800" width="244" height="185" /&gt;&lt;/strong&gt;     &lt;br /&gt;Introduction     &lt;br /&gt;Parameters     &lt;br /&gt;Conditions     &lt;br /&gt;Persistence     &lt;br /&gt;WebServices     &lt;br /&gt;LocalServices&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Day Two&lt;/strong&gt;     &lt;br /&gt;Errors     &lt;br /&gt;FaultHandlers     &lt;br /&gt;Transactions     &lt;br /&gt;Compensation     &lt;br /&gt;Compensation + Transaction&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Day Three&lt;/strong&gt;     &lt;br /&gt;Parallel Execution     &lt;br /&gt;WCF     &lt;br /&gt;Tracking     &lt;br /&gt;Custom Activities     &lt;br /&gt;WF v4 Overview     &lt;br /&gt;Questions&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sites.google.com/site/jfioranelli/presentations/WindowsWorkflowFoundation.pptx"&gt;Here&lt;/a&gt; you can download the presentation (in Spanish).&lt;/p&gt;  &lt;p&gt;And here is the code: &lt;a href="http://sites.google.com/site/jfioranelli/code/WF-Day1.rar"&gt;DayOne&lt;/a&gt;, &lt;a href="http://sites.google.com/site/jfioranelli/code/WF-Day2.rar"&gt;DayTwo&lt;/a&gt; and &lt;a href="http://sites.google.com/site/jfioranelli/code/WF-Day3.rar"&gt;DayThree&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-1582992773101294286?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/1582992773101294286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=1582992773101294286' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/1582992773101294286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/1582992773101294286'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/11/wf-course.html' title='WF Course'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-2979461433988432106</id><published>2009-12-01T11:33:00.000+11:00</published><updated>2009-12-02T11:33:13.063+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.Net 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='Entity Framework'/><title type='text'>Entity Framework 4.0 - Foreign Key Relationships</title><content type='html'>&lt;p&gt;The current version of EF (v3.5) maps table relationships as properties, hiding database foreign-key columns. However, there are some scenarios where you don’t need the entire referenced object to do some operation, you only need its “Id” (foreign key).&lt;/p&gt;  &lt;p&gt;For example, in a web application it is very common to use combo-boxes in order to assign relationships. In these scenarios, after a post-back it is necessary to re-create the model and its relationships (using combo-boxes “selected values”). Since you don’t have the referenced objects, you must get them from the database or use “&lt;a href="http://blogs.msdn.com/alexj/archive/2009/06/19/tip-26-how-to-avoid-database-queries-using-stub-entities.aspx"&gt;Stub Entities&lt;/a&gt;” to simulate them.&lt;/p&gt;  &lt;p&gt;To solve this problem, the version 4.0 will also allow you to map foreign-key columns as properties, making it easier.&lt;/p&gt;  &lt;p&gt;More info: &lt;a title="http://blogs.msdn.com/adonet/archive/2009/11/06/foreign-key-relationships-in-the-entity-framework.aspx" href="http://blogs.msdn.com/adonet/archive/2009/11/06/foreign-key-relationships-in-the-entity-framework.aspx"&gt;http://blogs.msdn.com/adonet/archive/2009/11/06/foreign-key-relationships-in-the-entity-framework.aspx&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-2979461433988432106?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/2979461433988432106/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=2979461433988432106' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/2979461433988432106'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/2979461433988432106'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/12/entity-framework-40-foreign-key.html' title='Entity Framework 4.0 - Foreign Key Relationships'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-6316388744795236540</id><published>2009-09-09T00:49:00.000+10:00</published><updated>2009-10-19T22:41:35.899+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='IOC'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Using ServiceLocator to call a WCF Service</title><content type='html'>&lt;p&gt;In my last &lt;a href="http://blog.jorgef.com.ar/2009/08/simple-servicelocator-with-support-for.html"&gt;post&lt;/a&gt;, I published a simple ServiceLocator, it may help you to decouple the service consumer from service proxy.&lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;To do this, it is necessary to create a generic interface:&lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;public interface&lt;/font&gt; &lt;font color="#408080"&gt;IServiceClient&lt;/font&gt;&amp;lt;TServiceInterface&amp;gt; : &lt;font color="#408080"&gt;IDisposable &lt;/font&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;where&lt;/font&gt; TServiceInterface : &lt;font color="#0000ff"&gt;class&lt;/font&gt;     &lt;br /&gt;{     &lt;br /&gt;&amp;#160; TServiceInterface Service { &lt;font color="#0000ff"&gt;get&lt;/font&gt;; }     &lt;br /&gt;}&lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;And it is the implementation using the ClientBase of WCF:&lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;public class&lt;/font&gt; &lt;font color="#408080"&gt;ServiceClient&lt;/font&gt;&amp;lt;TServiceInterface&amp;gt; :     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#408080"&gt;ClientBase&lt;/font&gt;&amp;lt;TServiceInterface&amp;gt;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#408080"&gt;IServiceClient&lt;/font&gt;&amp;lt;TServiceInterface&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;where&lt;/font&gt; TServiceInterface : &lt;font color="#0000ff"&gt;class&lt;/font&gt;     &lt;br /&gt;{     &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; TServiceInterface Service     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;get&lt;/font&gt; { &lt;font color="#0000ff"&gt;return base&lt;/font&gt;.Channel; }     &lt;br /&gt;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;void&lt;/font&gt; &lt;font color="#408080"&gt;IDisposable&lt;/font&gt;.Dispose()     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;try&lt;/font&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;base&lt;/font&gt;.Close();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;catch&lt;/font&gt; (&lt;font color="#408080"&gt;CommunicationException&lt;/font&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;base&lt;/font&gt;.Abort();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;catch&lt;/font&gt; (&lt;font color="#408080"&gt;TimeoutException&lt;/font&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;base&lt;/font&gt;.Abort();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;catch&lt;/font&gt; (&lt;font color="#408080"&gt;Exception&lt;/font&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;base&lt;/font&gt;.Abort();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;throw&lt;/font&gt;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;Then, you can register and use the ServiceClient this way:&lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;&lt;font color="#008000"&gt;// Service Registration&lt;/font&gt;     &lt;br /&gt;&lt;font color="#408080"&gt;ServiceLocator&lt;/font&gt;.Register&amp;lt;&lt;font color="#408080"&gt;IServiceClient&lt;/font&gt;&amp;lt;&lt;font color="#408080"&gt;IServiceA&lt;/font&gt;&amp;gt;&amp;gt;(() =&amp;gt; &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#408080"&gt;ServiceClient&lt;/font&gt;&amp;lt;&lt;font color="#408080"&gt;IServiceA&lt;/font&gt;&amp;gt;());&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;    &lt;br /&gt;&lt;font color="#008000"&gt;// Service Resolving&lt;/font&gt;     &lt;br /&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; (&lt;font color="#0000ff"&gt;var&lt;/font&gt; client = &lt;font color="#408080"&gt;ServiceLocator&lt;/font&gt;.Resolve&amp;lt;&lt;font color="#408080"&gt;IServiceClient&lt;/font&gt;&amp;lt;&lt;font color="#408080"&gt;IServiceA&lt;/font&gt;&amp;gt;&amp;gt;())     &lt;br /&gt;{     &lt;br /&gt;&amp;#160; client.Service.Operation();     &lt;br /&gt;}&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-6316388744795236540?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/6316388744795236540/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=6316388744795236540' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/6316388744795236540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/6316388744795236540'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/09/using-servicelocator-to-call-wcf.html' title='Using ServiceLocator to call a WCF Service'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-3445358562622509286</id><published>2009-10-14T22:44:00.001+11:00</published><updated>2009-10-14T22:44:49.228+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.Net 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='Entity Framework'/><title type='text'>POCO in Entity Framework 4.0</title><content type='html'>&lt;p&gt;The new version (4.0) of Entity Framework allows us to use “Plain Old CLR Objects” as entities. In the current version (3.5) every entity must inherit from EntityObject, but in the new version it is possible to use a simple POCO:&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;public class&lt;/font&gt; &lt;font color="#408080"&gt;Order&lt;/font&gt;     &lt;br /&gt;{     &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#408080"&gt;Guid&lt;/font&gt; Id { &lt;font color="#0000ff"&gt;get&lt;/font&gt;; &lt;font color="#0000ff"&gt;set&lt;/font&gt;; }     &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#408080"&gt;Product&lt;/font&gt; Product { &lt;font color="#0000ff"&gt;get&lt;/font&gt;; &lt;font color="#0000ff"&gt;set&lt;/font&gt;; }     &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;public int&lt;/font&gt; Quantity { &lt;font color="#0000ff"&gt;get&lt;/font&gt;; &lt;font color="#0000ff"&gt;set&lt;/font&gt;; }&amp;#160; &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;In order to use this new feature it is necessary to follow these three steps:    &lt;br /&gt;1. Create the edmx file (ModelEntities).&amp;#160; &lt;br /&gt;2. Turn off the code generation removing the value of the “Custom Tool” property.     &lt;br /&gt;3. Create the context this way:&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;public class&lt;/font&gt; &lt;font color="#408080"&gt;ModelContext&lt;/font&gt; : &lt;font color="#408080"&gt;ObjectContext&lt;/font&gt;     &lt;br /&gt;{&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; ModelContext() : &lt;font color="#0000ff"&gt;base&lt;/font&gt;(&lt;font color="#800000"&gt;&amp;quot;name=ModelEntities&amp;quot;&lt;/font&gt;, &lt;font color="#800000"&gt;&amp;quot;ModelEntities&amp;quot;&lt;/font&gt;)&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#408080"&gt;ObjectSet&lt;/font&gt;&amp;lt;&lt;font color="#408080"&gt;Order&lt;/font&gt;&amp;gt; Orders     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;get&lt;/font&gt; { &lt;font color="#0000ff"&gt;return base&lt;/font&gt;.CreateObjectSet&amp;lt;&lt;font color="#408080"&gt;Order&lt;/font&gt;&amp;gt;(); }     &lt;br /&gt;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;More information:    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx"&gt;POCO in the Entity Framework: Part 1 - The Experience&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://blogs.msdn.com/adonet/archive/2009/05/28/poco-in-the-entity-framework-part-2-complex-types-deferred-loading-and-explicit-loading.aspx"&gt;POCO in the Entity Framework: Part 2 – Complex Types, Deferred Loading and Explicit Loading&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://blogs.msdn.com/adonet/archive/2009/06/10/poco-in-the-entity-framework-part-3-change-tracking-with-poco.aspx"&gt;POCO in the Entity Framework: Part 3 – Change Tracking with POCO&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-3445358562622509286?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/3445358562622509286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=3445358562622509286' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/3445358562622509286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/3445358562622509286'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/10/poco-in-entity-framework-40.html' title='POCO in Entity Framework 4.0'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-7679470580892150223</id><published>2009-10-11T13:03:00.000+11:00</published><updated>2009-10-12T05:53:46.225+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.Net 4.0'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Default Endpoints in WCF 4.0</title><content type='html'>&lt;p&gt;One of the hardest things in WCF is its configuration. When you try to host a service without an endpoint declared in the configuration, an exception is thrown (a classic mistake).&lt;/p&gt;  &lt;p&gt;But this will change with the new version of the framework (in fact it has already changed in the beta 1).&lt;/p&gt;  &lt;p&gt;When you are hosting a service without any endpoint configured, the ServiceHost will read the service’s Uri and will create a default endpoint choosing one of de following bindings:    &lt;br /&gt;- http: basicHttpBinding     &lt;br /&gt;- net.tcp: netTcpBinding     &lt;br /&gt;- net.pipe: netNamedPipeBinding     &lt;br /&gt;- net.msmq: netMsmqBinding&lt;/p&gt;  &lt;p&gt;More information: &lt;a href="http://msdn.microsoft.com/en-us/library/ee354381.aspx#_Simplified_Configuration"&gt;A Developer’s Introduction to Windows Communication Foundation (WCF) .NET 4 Beta 1&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-7679470580892150223?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/7679470580892150223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=7679470580892150223' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/7679470580892150223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/7679470580892150223'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/10/default-endpoints-in-wcf-40.html' title='Default Endpoints in WCF 4.0'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-4841769080958910344</id><published>2009-09-29T10:53:00.000+10:00</published><updated>2009-10-11T11:53:24.476+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mocks'/><category scheme='http://www.blogger.com/atom/ns#' term='IOC'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Mocking WCF Services</title><content type='html'>&lt;p&gt;In my last &lt;a href="http://blog.jorgef.com.ar/2009/09/using-servicelocator-to-call-wcf.html"&gt;post&lt;/a&gt; I showed how to decouple the service consumer from the service proxy using the ServiceLocator pattern.&lt;/p&gt;  &lt;p&gt;In order to mock the WCF service, it is necessary to create the following ServiceClientStub:&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;public class&lt;/font&gt; &lt;font color="#408080"&gt;ServiceClientStub&lt;/font&gt;&amp;lt;TServiceInterface&amp;gt; : &lt;font color="#408080"&gt;IServiceClient&lt;/font&gt;&amp;lt;TServiceInterface&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;where&lt;/font&gt; TServiceInterface : &lt;font color="#0000ff"&gt;class&lt;/font&gt;     &lt;br /&gt;{    &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;private&lt;/font&gt; TServiceInterface serviceMock; &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;public &lt;/font&gt;ServiceClientStub(TServiceInterface serviceMock)    &lt;br /&gt;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;this&lt;/font&gt;.serviceMock = serviceMock;    &lt;br /&gt;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;public &lt;/font&gt;TServiceInterface Service&amp;#160; &lt;br /&gt;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;get&lt;/font&gt; { &lt;font color="#0000ff"&gt;return&lt;/font&gt; serviceMock; }    &lt;br /&gt;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;public void&lt;/font&gt; Dispose() { }    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;This allows you to test the service consumer without the service implementation (using &lt;a href="http://code.google.com/p/moq/"&gt;Moq&lt;/a&gt;):&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt; result = ...    &lt;br /&gt;&lt;font color="#0000ff"&gt;var&lt;/font&gt; mock = &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#408080"&gt;Mock&lt;/font&gt;&amp;lt;&lt;font color="#408080"&gt;IServiceA&lt;/font&gt;&amp;gt;();    &lt;br /&gt;mock.Setup(s =&amp;gt; s.Operation()).Returns(result);    &lt;br /&gt;&lt;font color="#408080"&gt;ServiceLocator&lt;/font&gt;.Register&amp;lt;&lt;font color="#408080"&gt;IServiceClient&lt;/font&gt;&amp;lt;&lt;font color="#408080"&gt;IServiceA&lt;/font&gt;&amp;gt;&amp;gt;(    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; () =&amp;gt; &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#408080"&gt;ServiceClientStub&lt;/font&gt;&amp;lt;&lt;font color="#408080"&gt;IServiceA&lt;/font&gt;&amp;gt;(mock.Object));&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-4841769080958910344?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/4841769080958910344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=4841769080958910344' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/4841769080958910344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/4841769080958910344'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/09/mocking-wcf-services.html' title='Mocking WCF Services'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-7739634343880908477</id><published>2009-08-19T22:00:00.000+10:00</published><updated>2009-10-09T23:01:44.498+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='IOC'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>A simple ServiceLocator with support for WCF, Web and Thread contexts</title><content type='html'>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;Last week I wrote a very simple ServiceLocator that supports single and multiple instances. It has three different containers:&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;- WCF: It supports single instances on the same OperationContext.    &lt;br /&gt;- Web: It supports single instances on the same HttpContext.     &lt;br /&gt;- Thread: It supports single instances on the same Thread. &lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;Every container implements the ISingleInstanceContainer interface:&lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;interface&lt;/font&gt; &lt;font color="#408080"&gt;ISingleInstanceContainer&lt;/font&gt;     &lt;br /&gt;{     &lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;#160; bool&lt;/font&gt; IsSuitable { &lt;font color="#0000ff"&gt;get&lt;/font&gt;; }     &lt;br /&gt;&amp;#160; T Register&amp;lt;T&amp;gt;(T instance);     &lt;br /&gt;&amp;#160; T Resolve&amp;lt;T&amp;gt;();     &lt;br /&gt;}&lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;The IsSuitable method evaluates if the context is suitable for every container:&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#408080"&gt;SingleInstanceWcfContainer&lt;/font&gt; : &lt;font color="#408080"&gt;ISingleInstanceContainer &lt;/font&gt;    &lt;br /&gt;{     &lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;#160; public bool&lt;/font&gt; IsSuitable     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160; get&lt;/font&gt; { &lt;font color="#0000ff"&gt;return&lt;/font&gt; &lt;font color="#408080"&gt;OperationContext&lt;/font&gt;.Current != &lt;font color="#0000ff"&gt;null&lt;/font&gt;; }     &lt;br /&gt;&amp;#160; }     &lt;br /&gt;&amp;#160; ...     &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#408080"&gt;SingleInstanceWebContainer&lt;/font&gt; : &lt;font color="#408080"&gt;ISingleInstanceContainer&lt;/font&gt;     &lt;br /&gt;{     &lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;#160; public bool&lt;/font&gt; IsSuitable     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160; get&lt;/font&gt; { &lt;font color="#0000ff"&gt;return&lt;/font&gt; &lt;font color="#408080"&gt;HttpContext&lt;/font&gt;.Current != &lt;font color="#0000ff"&gt;null&lt;/font&gt;; }&amp;#160; &lt;br /&gt;&amp;#160; }     &lt;br /&gt;&amp;#160; ...     &lt;br /&gt;} &lt;/p&gt;  &lt;br /&gt;  &lt;p&gt;In the following example, you can see how to register the ServiceA as “multiple instances” and the ServiceB as “single instance”:&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font color="#008000"&gt;// Multiple Instances Registration&lt;/font&gt;     &lt;br /&gt;&lt;font color="#408080"&gt;ServiceLocator&lt;/font&gt;.Register&amp;lt;&lt;font color="#408080"&gt;IServiceA&lt;/font&gt;&amp;gt;&lt;iservicea&gt;(() =&amp;gt; &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#408080"&gt;ServiceA&lt;/font&gt;());     &lt;br /&gt;    &lt;br /&gt;&lt;font color="#008000"&gt;// Single Instance Registration &lt;/font&gt;    &lt;br /&gt;&lt;font color="#408080"&gt;ServiceLocator&lt;/font&gt;.Register&amp;lt;&lt;font color="#408080"&gt;IServiceB&lt;/font&gt;&amp;gt;&lt;iserviceb&gt;(() =&amp;gt; &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#408080"&gt;ServiceB&lt;/font&gt;()).SingleInstance();     &lt;br /&gt;    &lt;br /&gt;&lt;font color="#008000"&gt;// Resolving Instances &lt;/font&gt;    &lt;br /&gt;&lt;font color="#408080"&gt;IServiceA &lt;/font&gt;serviceA = &lt;font color="#408080"&gt;ServiceLocator&lt;/font&gt;.Resolve&amp;lt;&lt;font color="#408080"&gt;IServiceA&lt;/font&gt;&amp;gt;&lt;iservicea&gt;();     &lt;br /&gt;&lt;font color="#408080"&gt;IServiceB &lt;/font&gt;serviceB = &lt;font color="#408080"&gt;ServiceLocator&lt;/font&gt;.Resolve&amp;lt;&lt;font color="#408080"&gt;IServiceB&lt;/font&gt;&amp;gt;&lt;iserviceb&gt;(); &lt;/p&gt;  &lt;br /&gt;&lt;a href="http://files.jorgef.com.ar/code/ServiceLocator.zip"&gt;Here&lt;/a&gt; you can download the code.   &lt;br /&gt;.     &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-7739634343880908477?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/7739634343880908477/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=7739634343880908477' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/7739634343880908477'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/7739634343880908477'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/08/simple-servicelocator-with-support-for.html' title='A simple ServiceLocator with support for WCF, Web and Thread contexts'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-8379574379445769007</id><published>2009-07-23T21:18:00.002+10:00</published><updated>2009-07-24T01:51:30.502+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC'/><category scheme='http://www.blogger.com/atom/ns#' term='Mocks'/><title type='text'>Mocking Views</title><content type='html'>&lt;p&gt;In my last &lt;a href="http://blog.jorgef.com.ar/2009/06/simple-mvc-implementation-for-aspnet.html"&gt;post&lt;/a&gt;, I've shown how to implement a simple MVC over ASP.NET.&lt;/p&gt;  &lt;p&gt;As you can see in the picture, every View implements an interface which exposes the events and methods of the View.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_3OJ07UNFNWY/SmhHDRA1ByI/AAAAAAAAAII/eYq7WBBcOhE/s1600-h/View5.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="View" border="0" alt="View" src="http://lh6.ggpht.com/_3OJ07UNFNWY/SmhHELg1aSI/AAAAAAAAAIM/Hm1Glj5VidY/View_thumb3.png?imgmax=800" width="128" height="175" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;The Controller uses the View’s interface, so it is possible to mock the View in order to test the Controller without the aspx page running.&lt;/p&gt;  &lt;p&gt;In the example of the last &lt;a href="http://blog.jorgef.com.ar/2009/06/simple-mvc-implementation-for-aspnet.html"&gt;post&lt;/a&gt;, the View’s interface exposes these members: &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; &lt;span style="color: #008080"&gt;ICustomersView&lt;/span&gt;     &lt;br /&gt;{     &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;#160; event&lt;/span&gt; &lt;span style="color: #008080"&gt;EventHandler&lt;/span&gt;&amp;lt;&lt;span style="color: #008080"&gt;GenericEventArgs&lt;/span&gt;&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;&amp;gt; FindCustomer;     &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;#160; void&lt;/span&gt; FillCustomers(&lt;span style="color: #008080"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color: #008080"&gt;Customer&lt;/span&gt;&amp;gt; customers);     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;So, you can mock the View and raise the FindCustomer event this way (I am using the &lt;a href="http://code.google.com/p/moq/"&gt;MOQ&lt;/a&gt; library):&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: #008080"&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="color: #008080"&gt;Mock&lt;/span&gt;&amp;lt;&lt;span style="color: #008080"&gt;ICustomerView&lt;/span&gt;&amp;gt; mock = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #008080"&gt;Mock&lt;/span&gt;&amp;lt;&lt;span style="color: #008080"&gt;ICustomerView&lt;/span&gt;&amp;gt;();&lt;/p&gt;  &lt;p&gt;&lt;span style="color: #008080"&gt;CustomersController&lt;/span&gt; controller = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #008080"&gt;CustomersController&lt;/span&gt;(mock.Object);&lt;/p&gt;  &lt;p&gt;mock.Raise(v =&amp;gt; v.FindCustomer+= &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;, &lt;/p&gt;  &lt;p&gt;&lt;span style="color: #0000ff"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new&lt;/span&gt; &lt;span style="color: #008080"&gt;GenericEventArgs&lt;/span&gt;&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;(searchPattern));&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-8379574379445769007?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/8379574379445769007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=8379574379445769007' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/8379574379445769007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/8379574379445769007'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/07/mocking-views.html' title='Mocking Views'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-6603648244709676086</id><published>2009-06-30T23:06:00.000+10:00</published><updated>2009-07-07T23:05:32.037+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC'/><title type='text'>A simple MVC implementation for ASP.NET (not ASP.NET MVC)</title><content type='html'>&lt;p&gt;Recently I have designed an architecture which supports the MVC pattern over the ASP.NET platform for an existing application. &lt;/p&gt;  &lt;p&gt;It is well known that new &lt;a href="http://www.asp.net/mvc/"&gt;ASP.NET MVC Framework&lt;/a&gt; is the best option to implement the MVC pattern, but it is also true that is difficult to adapt existing applications to this framework. So, I have designed an alternative and very simple solution in order to reach the same goal: MVC over ASP.NET.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://lh6.ggpht.com/_3OJ07UNFNWY/SlHj5H4AaNI/AAAAAAAAAIA/PuJd5AYZQo4/s1600-h/CustomerMVC%5B7%5D.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="CustomerMVC" src="http://lh3.ggpht.com/_3OJ07UNFNWY/SlHj5ykKfhI/AAAAAAAAAIE/dVWxSW2YQUI/CustomerMVC_thumb%5B3%5D.png?imgmax=800" width="240" height="168" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In the architecture designed, every View implements an interface which acts as contract between the View and the Controller. This interface exposes the events and methods of the View. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;internal&lt;/font&gt; &lt;font color="#0000ff"&gt;interface&lt;/font&gt; &lt;font color="#008080"&gt;ICustomersView&lt;/font&gt;     &lt;br /&gt;{     &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;event&lt;/font&gt;&amp;#160;&lt;font color="#008080"&gt;EventHandler&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;GenericEventArgs&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&amp;gt;&amp;gt; FindCustomer;     &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;void&lt;/font&gt; FillCustomers(&lt;font color="#008080"&gt;IList&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;&amp;gt; customers);     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The Controller has to attach itself to the events and call to the methods of the View Interface. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;internal&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#008080"&gt;CustomersController&lt;/font&gt; : &lt;font color="#008080"&gt;ControllerBase&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;ICustomerView&lt;/font&gt;&amp;gt;     &lt;br /&gt;{ &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; CustomersController(&lt;font color="#008080"&gt;ICustomersView&lt;/font&gt; view) : &lt;font color="#0000ff"&gt;base&lt;/font&gt;(view)     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; view.FindCustomers += &lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;EventHandler&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;GenericEventArgs&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&amp;gt;&amp;gt;(view_FindCustomers);     &lt;br /&gt;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; view_FindCustomers(&lt;font color="#0000ff"&gt;object&lt;/font&gt; sender, GenericEventArgs e)     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008080"&gt;IList&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;&amp;gt;&lt;customer&gt; customers = FindCustomers(e.Argument);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; View.FillCustomers(customers);     &lt;br /&gt;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;private&lt;/font&gt; &lt;font color="#008080"&gt;IList&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;&amp;gt;&lt;customer&gt; FindCustomers(&lt;font color="#0000ff"&gt;string&lt;/font&gt; customersSearchPattern)     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008000"&gt;// Use the model in order to find customers&amp;#160; &lt;br /&gt;&lt;/font&gt;&amp;#160; }&lt;/p&gt; }   &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;As you can see, the Controller receives the interface of the View and it doesn't know nothing about the View Implementation, so you can test the Controller using a mocked View.&lt;/p&gt;  &lt;p&gt;Then, you need to create the ASP.NET WebForm that implements the ICustomerView interface.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;partial&lt;/font&gt; &lt;font color="#0000ff"&gt;class&lt;/font&gt; &lt;font color="#008080"&gt;CustomersView&lt;/font&gt; :     &lt;br /&gt;&lt;font color="#008080"&gt;&amp;#160; ViewBase&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;CustomersController&lt;/font&gt;, &lt;font color="#008080"&gt;ICustomersView&lt;/font&gt;&amp;gt;, &lt;font color="#008080"&gt;ICustomerView&lt;/font&gt;     &lt;br /&gt;{&lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;event&lt;/font&gt; &lt;font color="#008080"&gt;EventHandler&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;GenericEventArgs&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&amp;gt;&amp;gt; FindCustomers; &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;public void&lt;/font&gt; FillCustomers(&lt;font color="#008080"&gt;IList&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;Customer&lt;/font&gt;&amp;gt; customers)     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; customersGrid.DataSource = customers;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; customersGrid.DataBind();     &lt;br /&gt;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;protected&lt;/font&gt; &lt;font color="#0000ff"&gt;void&lt;/font&gt; OnFindCustomers(&lt;font color="#008080"&gt;GenericEventArgs&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&amp;gt; args)     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if(FindCustomers != &lt;font color="#0000ff"&gt;null&lt;/font&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; FindCustomer(&lt;font color="#0000ff"&gt;this&lt;/font&gt;, args)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;protected void&lt;/font&gt; btnSearch_Click(&lt;font color="#0000ff"&gt;object&lt;/font&gt; sender, &lt;font color="#008080"&gt;EventArgs&lt;/font&gt; e)     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; OnFindCustomer(&lt;font color="#0000ff"&gt;new&lt;/font&gt; &lt;font color="#008080"&gt;GenericEventArgs&lt;/font&gt;&amp;lt;&lt;font color="#0000ff"&gt;string&lt;/font&gt;&amp;gt;(txtSearch.Text));     &lt;br /&gt;&amp;#160; } &lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Finally, the classes that you need to implement this architecture are the following:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;internal abstract partial class&lt;/font&gt; &lt;font color="#008080"&gt;ViewBase&lt;/font&gt;&amp;lt;TController, TViewInterface&amp;gt;:     &lt;br /&gt;&lt;font color="#008080"&gt;&amp;#160; Page&lt;/font&gt;     &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;where&lt;/font&gt; TViewInterface : &lt;font color="#0000ff"&gt;class&lt;/font&gt;     &lt;br /&gt;{ &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; ViewBase()     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008080"&gt;Type&lt;/font&gt; controllerType = &lt;font color="#0000ff"&gt;typeof&lt;/font&gt;(TController);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#008080"&gt;Activator&lt;/font&gt;.CreateInstance(controllerType, &lt;font color="#0000ff"&gt;this as&lt;/font&gt; TViewInterface);     &lt;br /&gt;&amp;#160; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;internal abstract class&lt;/font&gt; &lt;font color="#008080"&gt;ControllerBase&lt;/font&gt;&amp;lt;TViewInteface&amp;gt;     &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;where&lt;/font&gt; TViewInteface : &lt;font color="#0000ff"&gt;class&lt;/font&gt;     &lt;br /&gt;{ &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; TViewInteface View { &lt;font color="#0000ff"&gt;set; get;&lt;/font&gt; } &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; ControllerBase(TViewInteface view)     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; View = view;     &lt;br /&gt;&amp;#160; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;internal class&lt;/font&gt; &lt;font color="#008080"&gt;GenericEventArgs&lt;/font&gt;&amp;lt;TArgument&amp;gt; : System.&lt;font color="#008080"&gt;EventArgs&lt;/font&gt;     &lt;br /&gt;{     &lt;br /&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; GenericEventArgs()     &lt;br /&gt;&amp;#160; {     &lt;br /&gt;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; GenericEventArgs(TArgument argument)     &lt;br /&gt;&amp;#160; {&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Argument = argument;     &lt;br /&gt;&amp;#160; }&amp;#160; &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;font color="#0000ff"&gt;public&lt;/font&gt; TArgument Argument {&lt;font color="#0000ff"&gt; get; set;&lt;/font&gt; } &lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-6603648244709676086?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/6603648244709676086/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=6603648244709676086' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/6603648244709676086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/6603648244709676086'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/06/simple-mvc-implementation-for-aspnet.html' title='A simple MVC implementation for ASP.NET (not ASP.NET MVC)'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-4393047204601109499</id><published>2009-05-22T21:57:00.008+10:00</published><updated>2009-05-22T22:18:08.550+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DDD'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>DDD with WCF</title><content type='html'>Most books and articles explain how to use DDD with "one-server" architecture. But when you try to design a distributed architecture (ui and business layer), things get harder.&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;It is generally accepted that it's better not to distribute your application (see &lt;a href="http://www.theserverside.com/news/thread.tss?thread_id=25355"&gt;Martin Fowler's First Law of Distribution&lt;/a&gt;), but sometimes it is necessary.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;In my opinion WCF services are "application services" of DDD. They provide access to the business layer.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;br&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 400px; DISPLAY: block; HEIGHT: 168px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5338620903209485730" border="0" alt="" src="http://4.bp.blogspot.com/_3OJ07UNFNWY/ShaXbR5GxaI/AAAAAAAAAH0/ticM4oAlu7I/s400/AppServices.png" /&gt;&lt;br /&gt;The main problem of this architecture is that entities must live only on the business layer, because entities have methods that musn't be executed on the ui layer.&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;To solve it, it is necesary to create datacontracts (DTOs) in order to pass information between both layers and to map them with each entity.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-4393047204601109499?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/4393047204601109499/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=4393047204601109499' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/4393047204601109499'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/4393047204601109499'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/05/ddd-with-wcf.html' title='DDD with WCF'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_3OJ07UNFNWY/ShaXbR5GxaI/AAAAAAAAAH0/ticM4oAlu7I/s72-c/AppServices.png' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-3314820887542282539</id><published>2009-05-14T21:28:00.010+10:00</published><updated>2009-05-20T21:29:21.278+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Event'/><category scheme='http://www.blogger.com/atom/ns#' term='Alt.Net'/><title type='text'>Alt.Net in Buenos Aires</title><content type='html'>Last saturday I participated in the first alt.net open space organized in Argentina.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;These were the discussions:&lt;/p&gt;&lt;p&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 400px; DISPLAY: block; HEIGHT: 268px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5335643736204290466" border="0" alt="" src="http://2.bp.blogspot.com/_3OJ07UNFNWY/SgwDtWh-qaI/AAAAAAAAAHM/K7G5scdpI6Y/s400/AltNetBoard.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;I took part in the following subjects:&lt;br /&gt;- SOA and ESB&lt;br /&gt;- OpenSource in Argentina&lt;br /&gt;- ORM Techniques&lt;br /&gt;- DDD with WCF and EF&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 400px; DISPLAY: block; HEIGHT: 300px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5335641410527398546" border="0" alt="" src="http://3.bp.blogspot.com/_3OJ07UNFNWY/SgwBl-tZipI/AAAAAAAAAHE/wGV0yla572g/s400/3518803450_c15d191944.jpg" /&gt; &lt;p align="center"&gt;Zaiden, Rodolfo and I talking with Martin Salias &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;It was a very good experience. Thanks to the attenders, and specially to the organizers (Carlos Peix, Martin Salias and Miguel Saez).&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-3314820887542282539?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/3314820887542282539/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=3314820887542282539' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/3314820887542282539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/3314820887542282539'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/05/altnet-argentina.html' title='Alt.Net in Buenos Aires'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_3OJ07UNFNWY/SgwDtWh-qaI/AAAAAAAAAHM/K7G5scdpI6Y/s72-c/AltNetBoard.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-2562151424303748594</id><published>2009-04-24T21:09:00.000+10:00</published><updated>2009-05-20T21:27:28.378+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Event'/><category scheme='http://www.blogger.com/atom/ns#' term='Agile'/><title type='text'>Agile at ManageIt Event</title><content type='html'>Last tuesday I took part as speaker in the session "Management of development teams", during the event "Manage IT" (UADE).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 400px; DISPLAY: block; HEIGHT: 230px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5337863531737081618" border="0" alt="" src="http://2.bp.blogspot.com/_3OJ07UNFNWY/ShPmmdSzZxI/AAAAAAAAAHc/tZl8Dyu3iFc/s400/ManageIT1.jpg" /&gt;&lt;br /&gt;In this session Rodolfo Finochietti, Nicolás Mohamed, Mariano Sanchez and I talked about our experiences using agile methodologies in different Lagash projects.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 400px; DISPLAY: block; HEIGHT: 225px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5337863791211482370" border="0" alt="" src="http://4.bp.blogspot.com/_3OJ07UNFNWY/ShPm1j6UjQI/AAAAAAAAAHk/VNF7VbsTHuI/s400/ManageIT2.jpg" /&gt;&lt;br /&gt;The agenda was the following:&lt;br /&gt;- Introduction&lt;br /&gt;- Iterations&lt;br /&gt;- Planning&lt;br /&gt;- Scrum Board y Burndown Chart&lt;br /&gt;- Testing&lt;br /&gt;- Daily Meetings&lt;br /&gt;- Retrospectives&lt;br /&gt;&lt;br /&gt;&lt;a href="http://files.jorgef.com.ar/presentations/ManageIT.pptx"&gt;Here&lt;/a&gt; you can download the presentation (in Spanish).&lt;br /&gt;&lt;br /&gt;Thanks to the attendants.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-2562151424303748594?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/2562151424303748594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=2562151424303748594' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/2562151424303748594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/2562151424303748594'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/05/agile-at-manageit-event.html' title='Agile at ManageIt Event'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_3OJ07UNFNWY/ShPmmdSzZxI/AAAAAAAAAHc/tZl8Dyu3iFc/s72-c/ManageIT1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-6668286908823917836</id><published>2009-01-17T21:16:00.001+11:00</published><updated>2009-05-11T21:53:50.421+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WebCast'/><category scheme='http://www.blogger.com/atom/ns#' term='CloudServices'/><category scheme='http://www.blogger.com/atom/ns#' term='Azure'/><title type='text'>Webcast about CloudServices</title><content type='html'>Yesterday &lt;a href="http://weblogs.shockbyte.com.ar/rodolfof"&gt;Rodolfo Finochietti&lt;/a&gt; and I have participated as speakers in the Microsoft Webcast "Extending the Application Platform with Cloud Services".&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_3OJ07UNFNWY/SggKKjVpgEI/AAAAAAAAAG8/NNkEoBlwwzE/s1600-h/servicesPlatform.jpg"&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 400px; DISPLAY: block; HEIGHT: 184px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5334524935021363266" border="0" alt="" src="http://2.bp.blogspot.com/_3OJ07UNFNWY/SggKKjVpgEI/AAAAAAAAAG8/NNkEoBlwwzE/s400/servicesPlatform.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;We presented the following points:&lt;br /&gt;- Azure Services&lt;br /&gt;- Access Control&lt;br /&gt;- Sql DataServices&lt;br /&gt;- Service Bus&lt;br /&gt;- CRM Online&lt;br /&gt;&lt;br /&gt;The presentation is available in &lt;a href="http://files.jorgef.com.ar/presentations/DSOA03_English.pptx"&gt;English&lt;/a&gt; and &lt;a href="http://files.jorgef.com.ar/presentations/DSOA03_Spanish.pptx"&gt;Spanish&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Thanks to the attenders.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-6668286908823917836?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/6668286908823917836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=6668286908823917836' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/6668286908823917836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/6668286908823917836'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2009/01/webcast-about-cloudservices.html' title='Webcast about CloudServices'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_3OJ07UNFNWY/SggKKjVpgEI/AAAAAAAAAG8/NNkEoBlwwzE/s72-c/servicesPlatform.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-521961607519428778</id><published>2008-10-20T23:05:00.018+11:00</published><updated>2009-05-11T21:43:16.275+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='UnitTests'/><category scheme='http://www.blogger.com/atom/ns#' term='Mocks'/><category scheme='http://www.blogger.com/atom/ns#' term='Videos'/><title type='text'>Using NMock2</title><content type='html'>&lt;span style="font-family:arial;"&gt;In unit testing, sometimes it is needed to isolate the dependencies in order to test a specific part of the application.&lt;br /&gt;&lt;br /&gt;One way to do that is using mock objects. They simulate the behavior of real objects and is not needed the entire application for the test.&lt;br /&gt;&lt;br /&gt;For example, in a Restaurant, the Waiter's job depends on the Cook's job . So, when you test the Waiter's job, you will test the job of the two employees.&lt;br /&gt;&lt;br /&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 400px; DISPLAY: block; HEIGHT: 195px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5262200940707791794" border="0" alt="" src="http://3.bp.blogspot.com/_3OJ07UNFNWY/SQcX4A-dQ7I/AAAAAAAAAEA/xXn6JvQ2k_E/s400/nmock1.gif" /&gt;&lt;br /&gt;If you want to test only de Waiter's job, you need to create a mock object in order to simulate the other employee's jobs.&lt;br /&gt;&lt;br /&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 400px; DISPLAY: block; HEIGHT: 195px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5262201080277213186" border="0" alt="" src="http://3.bp.blogspot.com/_3OJ07UNFNWY/SQcYAI6ZoAI/AAAAAAAAAEI/gJ4zzmJiVYU/s400/nmock2.gif" /&gt;&lt;br /&gt;NMock2 is one option to create mock objects. It can be downloaded from &lt;a href="http://www.nmock.org/"&gt;http://www.nmock.org/&lt;/a&gt;. As follows you will find the code to create the mock of the Cook using NMock2:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;table style="BORDER-BOTTOM: #cccccc thin solid; BORDER-LEFT: #cccccc thin solid; BORDER-TOP: #cccccc thin solid; BORDER-RIGHT: #cccccc thin solid"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;p&gt;&lt;span style="color:#009900;"&gt;// Create the order and dishes for the test&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#339999;"&gt;Order&lt;/span&gt; order = CreateOrder();&lt;br /&gt;&lt;span style="color:#339999;"&gt;List&lt;/span&gt;&lt;&lt;span style="color:#339999;"&gt;Dish&lt;/span&gt;&gt; dishes = CreateDishes(order); &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color:#009900;"&gt;// Create the mock of the Cook&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#339999;"&gt;Mockery&lt;/span&gt; mockery = &lt;span style="color:#000099;"&gt;new&lt;/span&gt; &lt;span style="color:#339999;"&gt;Mockery&lt;/span&gt;();&lt;br /&gt;&lt;span style="color:#339999;"&gt;ICook&lt;/span&gt; cook = mockery.NewMock&lt;&lt;span style="color:#339999;"&gt;ICook&lt;/span&gt;&gt;();&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;span style="color:#339999;"&gt;Expect&lt;/span&gt;.Once.On(cook).Method(&lt;span style="color:#cc0000;"&gt;"GetDishes"&lt;/span&gt;).With(order)&lt;br /&gt;.Will(&lt;span style="color:#339999;"&gt;Return&lt;/span&gt;.Value(dishes));&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;span style="color:#009900;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;&lt;span style="color:#009900;"&gt;// Asign the mock object as Cook of the restaurant &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#339999;"&gt;Restaurant&lt;/span&gt;.Cook = cook;&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;&lt;span style="color:#009900;"&gt;// Send the order to the Waiter&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#339999;"&gt;Waiter&lt;/span&gt; waiter = new &lt;span style="color:#339999;"&gt;Waiter&lt;/span&gt;();&lt;br /&gt;waiter.ProcessOrder(order); &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;tr&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;The previous code builds a mock that expects one execution of the GetDishes method with the order as a parameter, and it must return the list of dishes specified.&lt;br /&gt;&lt;br /&gt;So, when this test is executed, the Waiter uses the mock of the Cook, which returns the dishes that we have created.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For more details about creating mocks, you can watch the &lt;a title="Utilizando NMock2 con las Pruebas Unitarias de Visual Studio" href="http://video.msn.com/video.aspx?vid=27745472-0367-4ffd-a0f6-91b1ce3f0fb3" target="_new"&gt;video&lt;/a&gt; (in Spanish language) with the entire explanation and download &lt;a href="http://files.jorgef.com.ar/presentations/NMock2.zip"&gt;the presentation and code&lt;/a&gt; (in Spanish language).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;embed id="hjsho9cb" height="364" type="application/x-shockwave-flash" pluginspage="http://macromedia.com/go/getflashplayer" width="432" src="http://images.video.msn.com/flash/soapbox1_1.swf" allowfullscreen="true" allowscriptaccess="always" flashvars="c=v&amp;amp;v=27745472-0367-4ffd-a0f6-91b1ce3f0fb3&amp;amp;ifs=true&amp;amp;fr=msnvideo&amp;amp;mkt=en-US"&gt;&lt;/embed&gt;&lt;noembed&gt;&lt;/noembed&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Thanks to &lt;a href="http://blogs.msdn.com/masaez/"&gt;Miguel&lt;/a&gt; and &lt;a href="http://weblogs.shockbyte.com.ar/rodolfof/"&gt;Rodolfo&lt;/a&gt; for helping me with the video.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-521961607519428778?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/521961607519428778/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=521961607519428778' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/521961607519428778'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/521961607519428778'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2008/10/using-nmock2.html' title='Using NMock2'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_3OJ07UNFNWY/SQcX4A-dQ7I/AAAAAAAAAEA/xXn6JvQ2k_E/s72-c/nmock1.gif' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-6490299241336427227</id><published>2008-09-12T11:16:00.011+10:00</published><updated>2008-10-29T01:19:06.376+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Event'/><category scheme='http://www.blogger.com/atom/ns#' term='Technight'/><category scheme='http://www.blogger.com/atom/ns#' term='Interoperability'/><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Technight about Interoperability in WCF</title><content type='html'>&lt;span style="font-family:arial;"&gt;I have recently participated as speaker at the Technight about "Interoperability in WCF" together with Rodolfo Finochietti and Ariel Krakovski. The event took place on 29 August in Microsoft Argentina. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5244943247720101602" style="FLOAT: center; MARGIN: 0px 0px 10px 10px; CURSOR: hand" alt="" src="http://4.bp.blogspot.com/_3OJ07UNFNWY/SMnIGEtwtuI/AAAAAAAAABM/CKKRbd1dJZs/s320/WCF_Everywhere.png" border="0" /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The agenda was the following:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;- WCF Extensibility&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;- Web Services Interoperability&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;- Contracts and Versioning&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;- Problems&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;- REST&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;- ADO.NET Data Services&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;- LINQ&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;- High Performace Computing&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;- SQL Server&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;- POP3 &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;Samples and the presentation can be downloaded from &lt;a href="http://weblogs.shockbyte.com.ar/rodolfof/archive/2008/09/01/technight-interoperability-in-wcf.aspx"&gt;Rodolfo's weblog&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Thanks to all the attendants and to &lt;a href="http://weblogs.shockbyte.com.ar/rodolfof/"&gt;Rodolfo&lt;/a&gt;, Ariel and &lt;a href="http://blogs.msdn.com/masaez/"&gt;Miguel&lt;/a&gt;.&lt;/span&gt;&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-6490299241336427227?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/6490299241336427227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=6490299241336427227' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/6490299241336427227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/6490299241336427227'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2008/09/technight-about-interoperability-in-wcf.html' title='Technight about Interoperability in WCF'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_3OJ07UNFNWY/SMnIGEtwtuI/AAAAAAAAABM/CKKRbd1dJZs/s72-c/WCF_Everywhere.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-3324060536222943802</id><published>2008-09-21T06:17:00.023+10:00</published><updated>2008-10-29T00:16:24.928+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Trace'/><category scheme='http://www.blogger.com/atom/ns#' term='Design for operations'/><category scheme='http://www.blogger.com/atom/ns#' term='EventLog'/><category scheme='http://www.blogger.com/atom/ns#' term='WMI'/><category scheme='http://www.blogger.com/atom/ns#' term='Debug'/><category scheme='http://www.blogger.com/atom/ns#' term='Instumentation'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance Counters'/><title type='text'>Never forget to log</title><content type='html'>&lt;span style="font-family:arial;"&gt;Most software problems appear during implementation phases. When software is used in production environments, it's very common to see problems that you've never seen before. And when problems appear, there isn't time to reproduce them and to debug the code. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;There are different ways to log information in .net, these are the most used: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;- &lt;a href="http://www.jorgef.com.ar/2008/09/using-eventlog.html"&gt;Event Log&lt;/a&gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;- Trace / Debug &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;- Performance Counters &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;- WMI &lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img id="BLOGGER_PHOTO_ID_5262191568509749298" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 400px; CURSOR: hand; HEIGHT: 227px; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_3OJ07UNFNWY/SQcPWe0USDI/AAAAAAAAADw/CobiVe7py-4/s400/neverforgettolog.gif" border="0" /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_3OJ07UNFNWY/SMWSw3grP7I/AAAAAAAAAAQ/dbJtNWZmZCU/s1600-h/neverforgettolog.png"&gt;&lt;/a&gt;&lt;p&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;If you use logging, you will be able to diagnose problems and might &lt;/span&gt;&lt;span style="font-family:arial;"&gt;find errors wich couldn't be yours (until this happens, the problem is always yours). &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-3324060536222943802?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/3324060536222943802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=3324060536222943802' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/3324060536222943802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/3324060536222943802'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2008/09/never-forget-to-log.html' title='Never forget to log'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_3OJ07UNFNWY/SQcPWe0USDI/AAAAAAAAADw/CobiVe7py-4/s72-c/neverforgettolog.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3109374999835349472.post-4315345915649317738</id><published>2008-10-14T08:21:00.016+11:00</published><updated>2008-10-28T22:14:38.896+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design for operations'/><category scheme='http://www.blogger.com/atom/ns#' term='EventLog'/><category scheme='http://www.blogger.com/atom/ns#' term='Instumentation'/><title type='text'>Using the EventLog</title><content type='html'>&lt;span style="font-family:arial;"&gt;Many applications report errors with the EventLog because it provides a simple and centralized way to log. If you use the EventLog you won't have to worry about the size or location of the log.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;Some Tips:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Use the EventLog not only for errors.&lt;/strong&gt; Warnings and other messages are useful in order to understand the application behavior in production environments.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;If the Source hasn't been created yet, it will be created with the first entry.&lt;/strong&gt; That operation needs special permissions so, if the application doesn't run with administrator permissions, you must create the Source previously (see &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.eventloginstaller.aspx"&gt;EventLogInstaller class&lt;/a&gt;).&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Use some mechanism in order to filter the type of message you want to log&lt;/strong&gt;. If not, you will have the EventLog full of messages that you don't need. (see &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.traceswitch.aspx"&gt;TraceSwitch class&lt;/a&gt;).&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Don't forget to use the Event ID.&lt;/strong&gt; There are many management applications (i.e. MOM/SCOM) that use this information to take different actions.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;You should document every entry. &lt;/strong&gt;It will be useful when you are not there to give support.&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;For more details see the &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx"&gt;EventLog class documentation&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3109374999835349472-4315345915649317738?l=blog.jorgef.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.jorgef.net/feeds/4315345915649317738/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3109374999835349472&amp;postID=4315345915649317738' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/4315345915649317738'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3109374999835349472/posts/default/4315345915649317738'/><link rel='alternate' type='text/html' href='http://blog.jorgef.net/2008/09/using-eventlog.html' title='Using the EventLog'/><author><name>Jorge Fioranelli</name><uri>http://www.blogger.com/profile/14401934479103471928</uri><email>jorge.fioranelli@readify.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16784859560575309240'/></author><thr:total>0</thr:total></entry></feed>