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

<channel>
	<title>Chris Patterson&#039;s Blog</title>
	<atom:link href="http://lostechies.com/chrispatterson/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/chrispatterson</link>
	<description>Just another LosTechies site</description>
	<lastBuildDate>Thu, 28 Mar 2013 23:52:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>Implementing Routing Slip with MassTransit</title>
		<link>http://lostechies.com/chrispatterson/2013/03/28/implementing-routing-slip-with-masstransit/</link>
		<comments>http://lostechies.com/chrispatterson/2013/03/28/implementing-routing-slip-with-masstransit/#comments</comments>
		<pubDate>Thu, 28 Mar 2013 23:49:00 +0000</pubDate>
		<dc:creator>Chris Patterson</dc:creator>
				<category><![CDATA[masstransit]]></category>

		<guid isPermaLink="false">http://lostechies.com/chrispatterson/?p=106</guid>
		<description><![CDATA[This article introduces MassTransit.Courier, a new project that implements the routing slip pattern on top of MassTransit, a free, open-source, and lightweight message bus for the .NET platform. Introduction When sagas were originally conceived in MassTransit, they were inspired by&#160;&#8230; <a href="http://lostechies.com/chrispatterson/2013/03/28/implementing-routing-slip-with-masstransit/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>This article introduces <a href="https://github.com/MassTransit/MassTransit-Courier">MassTransit.Courier</a>, a new project that implements the routing slip pattern on top of <a href="http://masstransit-project.com/">MassTransit</a>, a free, <a href="https://github.com/MassTransit/MassTransit">open-source</a>, and lightweight message bus for the .NET platform.</em></p>
<h2>Introduction</h2>
<p>When sagas were originally conceived in MassTransit, they were inspired by an <a href="http://rgoarchitects.bit.ly/4xNwpp">excerpt</a> from Chapter 5 in the book <a href="http://www.manning.com/rotem/">SOA Patterns</a> by <a href="http://arnon.me/">Arnon Rotem-Gal Oz</a>. Over the past few months, the community has <s>argued</s> discussed how the use of the word saga has led to confusion and how early implementations included in both NServiceBus and MassTransit do not actually align with the <a href="http://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf">original paper</a> published in 1987 by Princeton University and written by Hector Garcia-Molina and Kenneth Salem in which the term was coined.</p>
<p>With MassTransit Courier, the intent is to provide a mechanism for creating and executing distributed transactions with fault compensation that can be used alongside the existing MassTransit sagas for monitoring and recovery.</p>
<h2>Background</h2>
<p>Over the past few years building distributed systems using MassTransit, a pattern I consistently see repeated is the orchestration of multiple services into a single business transaction. Using the existing MassTransit saga support to manage the state of the transaction, the actual processing steps are created as autonomous services that are invoked by the saga using command messages. Command completion is observed using an event or response message by the saga, at which point the next processing step is invoked. When the saga has invoked the final service the business transaction is complete.</p>
<p>As the processing required within a business transaction changes with evolving business requirements, a new version of the saga is required that includes the newly created processing steps. Knowledge of the new services becomes part of the saga, as well as the logic to identify which services need to be invoked for each transaction. The saga becomes rich with knowledge, and with great knowledge comes great responsibility (after all, knowledge is power right?). Now, instead of only orchestrating the transaction, the saga is responsible for identifying which services to invoke based on the content of the transaction. Another concern was the level of database contention on the saga tables. With every service invocation being initiated by the saga, combined with the saga observing service events and responses, the saga tables gets very busy.</p>
<p>Beyond the complexity of increasing saga responsibilities, more recently the business has requested the ability to selectively route a message through a series of services based on the content of the message. In addition to being able to dynamically route messages, the business needs to allow new services to be created and added to the inventory of available services. And this should be possible without modifying a central control point that dispatches messages to each service.</p>
<p>Like most things in computer science, this problem has already been solved.</p>
<h2>The Routing Slip Pattern</h2>
<p>A routing slip specifies a sequence of processing steps for a message. As each processing step completes, the routing slip is forwarded to the next step. When all the processing steps have completed, the routing slip is complete.</p>
<p>A key advantage to using a routing slip is it allows the processing steps to vary for each message. Depending upon the content of the message, the routing slip creator can selectively add processing steps to the routing slip. This dynamic behavior is in contrast to a more explicit behavior defined by a state machine or sequential workflow that is statically defined (either through the use of code, a DSL, or something like Windows Workflow).</p>
<h2>MassTransit Courier</h2>
<p>MassTransit Courier is a framework that implements the routing slip pattern. Leveraging a durable messaging transport and the advanced saga features of MassTransit, MassTransit Courier provides a powerful set of components to simplify the use of routing slips in distributed applications. Combining the routing slip pattern with a <a href="https://github.com/phatboyg/Automatonymous">state machine such as Automatonymous</a> results in a reliable, recoverable, and supportable approach for coordinating and monitoring message processing across multiple services.</p>
<p>In addition to the basic routing slip pattern, MassTransit Courier also supports <a href="http://en.wikipedia.org/wiki/Compensation_%28engineering%29">compensations</a> which allow processing steps to store process-related data so that reversible operations can be undone, using either a traditional rollback mechanism or by applying an offsetting operation. For example, a processing step that holds a seat for a patron could release the held seat when compensated.</p>
<p>MassTransit Courier is free software and is covered by the same open source license as MassTransit (Apache 2.0). You can install <a href="https://github.com/MassTransit/MassTransit-Courier">MassTransit.Courier</a> into your existing solution using <a href="http://nuget.org/packages/masstransit.courier">NuGet</a>.</p>
<h2>Activities</h2>
<p>In MassTransit Courier, an <em>Activity</em> refers to a processing step that can be added to a routing slip. To create an activity, create a class that implements the <em>Activity</em> interface.</p>
<pre><code>public class DownloadImageActivity :
    Activity&lt;DownloadImageArguments, DownloadImageLog&gt;
{
}
</code></pre>
<p>The <em>Activity</em> interface is generic with two arguments. The first argument specifies the activity’s input type and the second argument specifies the activity’s log type. In the example shown above, <em>DownloadImageArguments</em> is the input type and <em>DownloadImageLog</em> is the log type. Both arguments must be interface types so that the implementations can be dynamically created.</p>
<h3>Implementing an Activity</h3>
<p>An activity must implement two interface methods, <em>Execute</em> and <em>Compensate</em>. The <em>Execute</em> method is called while the routing slip is executing activities and the <em>Compensate</em> method is called when a routing slip faults and needs to be compensated.</p>
<p>When the <em>Execute</em> method is called, an <em>execution</em> argument is passed containing the activity arguments, the routing slip <em>TrackingNumber</em>, and methods to mark the activity as completed or faulted. The actual routing slip message, as well as any details of the underlying infrastructure, are excluded from the <em>execution</em> argument to prevent coupling between the activity and the implementation. An example <em>Execute</em> method is shown below.</p>
<pre><code>ExecutionResult Execute(Execution&lt;DownloadImageArguments&gt; execution)
{
    DownloadImageArguments args = execution.Arguments;
    string imageSavePath = Path.Combine(args.WorkPath, 
        execution.TrackingNumber.ToString());

    _httpClient.GetAndSave(args.ImageUri, imageSavePath);

    return execution.Completed(new DownloadImageLogImpl(imageSavePath));
}
</code></pre>
<p>Once activity processing is complete, the activity returns an <em>ExecutionResult</em> to the host. If the activity executes successfully, the activity can elect to store compensation data in an activity log which is passed to the <em>Completed</em> method on the <em>execution</em> argument. If the activity chooses not to store any compensation data, the activity log argument is not required. In addition to compensation data, the activity can add or modify variables stored in the routing slip for use by subsequent activities.</p>
<blockquote>
<p>In the example above, the activity creates an instance of a private class that implements the <em>DownloadImageLog</em> interface and stores the log information in the object properties. The object is then passed to the <em>Completed</em> method for storage in the routing slip before sending the routing slip to the next activity. </p>
</blockquote>
<p>When an activity fails, the <em>Compensate</em> method is called for previously executed activities in the routing slip that stored compensation data. If an activity does not store any compensation data, the <em>Compensate</em> method is never called. The compensation method for the example above is shown below.</p>
<pre><code>CompensationResult Compensate(Compensation&lt;DownloadImageLog&gt; compensation)
{
    DownloadImageLog log = compensation.Log;
    File.Delete(log.ImageSavePath);

    return compensation.Compensated();
}
</code></pre>
<p>Using the activity log data, the activity compensates by removing the downloaded image from the work directory. Once the activity has compensated the previous execution, it returns a <em>CompensationResult</em> by calling the <em>Compensated</em> method. If the compensating actions could not be performed (either via logic or an exception) and the inability to compensate results in a failure state, the <em>Failed</em> method can be used instead, optionally specifying an <em>Exception</em>.</p>
<h2>Building a Routing Slip</h2>
<p>Developers are discouraged from directly implementing the <em>RoutingSlip</em> message type and should instead use a <em>RoutingSlipBuilder</em> to create a routing slip. The <em>RoutingSlipBuilder</em> encapsulates the creation of the routing slip and includes methods to add activities, activity logs, and variables to the routing slip. For example, to create a routing slip with two activities and an additional variable, a developer would write:</p>
<pre><code>var builder = new RoutingSlipBuilder(NewId.NextGuid());
builder.AddActivity(“DownloadImage”, “rabbitmq://localhost/execute_downloadimage”, new
    {
        ImageUri = new Uri(“http://images.google.com/someImage.jpg”)
    });
builder.AddActivity(“FilterImage”, “rabbitmq://localhost/execute_filterimage”);
builder.AddVariable(“WorkPath”, “\\dfs\work”);

var routingSlip = builder.Build();
</code></pre>
<p>Each activity requires a name for display purposes and a URI specifying the execution address. The execution address is where the routing slip should be sent to execute the activity. For each activity, arguments can be specified that are stored and presented to the activity via the activity arguments interface type specify by the first argument of the <em>Activity</em> interface. The activities added to the routing slip are combined into an <em>Itinerary</em>, which is the list of activities to be executed, and stored in the routing slip.</p>
<blockquote>
<p>Managing the inventory of available activities, as well as their names and execution addresses, is the responsibility of the application and is not part of the MassTransit Courier. Since activities are application specific, and the business logic to determine which activities to execute and in what order is part of the application domain, the details are left to the application developer.</p>
</blockquote>
<p>Once built, the routing slip is executed, which sends it to the first activity’s execute URI. To make it easy and to ensure that source information is included, an extension method to <em>IServiceBus</em> is available, the usage of which is shown below.</p>
<pre><code>bus.Execute(routingSlip); // pretty exciting, eh?
</code></pre>
<p>It should be pointed out that if the URI for the first activity is invalid or cannot be reached, an exception will be thrown by the <em>Execute</em> method.</p>
<h2>Hosting Activities in MassTransit</h2>
<p>To host an activity in a MassTransit service bus instance, the configuration namespace has been extended to include two additional subscription methods (thanks to the power of extension methods and a flexible configuration syntax, no changes to MassTransit were required). Shown below is the configuration used to host an activity.</p>
<pre><code>var executeUri = new Uri(“rabbitmq://localhost/execute_example”);
var compensateUri = new Uri(“rabbitmq://localhost/compensate_example”);

IServiceBus compensateBus = ServiceBusFactory.New(x =&gt;
    {
        x.ReceiveFrom(compensateUri);
        x.Subscribe(s =&gt; s.CompensateActivityHost&lt;ExampleActivity, ExampleLog&gt;(
            _ =&gt; new ExampleActivity());
    });

IServiceBus executeBus = ServiceBusFactory.New(x =&gt;
    {
        x.ReceiveFrom(executeUri);
        x.Subscribe(s =&gt; s.ExecuteActivityHost&lt;ExampleActivity, ExampleArguments&gt;(
            compensateUri,
             _ =&gt; new ExampleActivity());
    });
</code></pre>
<p>In the above example two service bus instances are created, each with their own input queue. For execution, the routing slip is sent to the execution URI, and for compensation the routing slip is sent to the compensation URI. The actual URIs used are up to the application developer, the example merely shows the recommended approach so that the two addresses are easily distinguished. The URIs <strong>must</strong> be different!</p>
<h2>Monitoring Routing Slips</h2>
<p>During routing slip execution, events are published when the routing slip completes or faults. Every event message includes the <em>TrackingNumber</em> as well as a <em>Timestamp</em> (in UTC, of course) indicating when the event occurred:</p>
<ul>
<li>RoutingSlipCompleted</li>
<li>RoutingSlipFaulted</li>
<li>RoutingSlipCompensationFailed</li>
</ul>
<p>Additional events are published for each activity, including:</p>
<ul>
<li>RoutingSlipActivityCompleted</li>
<li>RoutingSlipActivityFaulted</li>
<li>RoutingSlipActivityCompensated</li>
<li>RoutingSlipActivityCompensationFailed</li>
</ul>
<p>By observing these events, an application can monitor and track the state of a routing slip. To maintain the current state, an Automatonymous state machine could be created. To maintain history, events could be stored in a database and then queried using the <em>TrackingNumber</em> of the <em>RoutingSlip</em>.</p>
<h2>Wrapping Up</h2>
<p>MassTransit Courier is a great way to compose dynamic processing steps into a routing slip that can be executed, monitored, and compensated in the event of a fault. When used in combination with the existing saga features of MassTransit, it is possible to coordinate a distributed set of services into a reliable and supportable system.</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/chrispatterson/2013/03/28/implementing-routing-slip-with-masstransit/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>IDisposable, Done Right</title>
		<link>http://lostechies.com/chrispatterson/2012/11/29/idisposable-done-right/</link>
		<comments>http://lostechies.com/chrispatterson/2012/11/29/idisposable-done-right/#comments</comments>
		<pubDate>Thu, 29 Nov 2012 12:59:06 +0000</pubDate>
		<dc:creator>Chris Patterson</dc:creator>
				<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://lostechies.com/chrispatterson/?p=103</guid>
		<description><![CDATA[IDisposable is a standard interface in the .NET framework that facilitates the deterministic release of unmanaged resources. Since the Common Language Runtime (CLR) uses Garbage Collection (GC) to manage the lifecycle of objects created on the heap, it is not&#160;&#8230; <a href="http://lostechies.com/chrispatterson/2012/11/29/idisposable-done-right/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><em>IDisposable</em> is a standard interface in the .NET framework that facilitates the deterministic release of unmanaged resources. Since the Common Language Runtime (CLR) uses Garbage Collection (GC) to manage the lifecycle of objects created on the heap, it is not possible to control the release and recovery of heap objects. While there are methods to force the GC to collect unreferenced objects, it is not guaranteed to clear all objects, and it is highly inefficient for an application to force garbage collection as part of the service control flow.</p>
<h2>Implementing <em>IDisposable</em></h2>
<p>Despite <em>IDisposable</em> having only a single method named <em>Dispose</em> to implement, it is commonly implemented incorrectly. After reading this blog post it should be clear how and when to implement <em>IDisposable</em>, as well as how to ensure that resources are properly disposed when <em>bad things happen</em> (also knows as <em>exceptions</em>).</p>
<p>First, the <em>IDisposable</em> interface definition:</p>
<pre><code>public interface IDisposable
{
    void Dispose();
}
</code></pre>
<p>Next, the proper way to implement <em>IDisposable</em> every single time it is implemented:</p>
<pre><code>public class DisposableClass :
    IDisposable
{
    bool _disposed;

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    ~DisposableClass()
    {
        Dispose(false);
    }

    protected virtual void Dispose(bool disposing)
    {
        if (_disposed)
            return;

        if (disposing)
        {
            // free other managed objects that implement
            // IDisposable only
        }

        // release any unmanaged objects
        // set the object references to null

        _disposed = true;
    }
}
</code></pre>
<p>The pattern above for implementing <em>IDisposable</em> ensures that all references are properly disposed and released. Using the finalizer, along with the associated dispose methods, will ensure that in every case references will be properly released. There are some subtle things going on in the code, however, as described below.</p>
<h3>Dispose()</h3>
<p>The implementation of the <em>Dispose</em> method calls the <em>Dispose(bool disposing)</em> method, passing <em>true</em>, which indicates that the object is being <em>disposed</em>. This method is never automatically called by the CLR, it is only called explicitly by the owner of the object (which in some cases may be another framework, such as ASP.NET or MassTransit, or an object container, such as Autofac or StructureMap).</p>
<h3>~DisposableClass</h3>
<p>Immediately before the GC releases an object instance, it calls the object’s finalizer. Since an object’s finalizer is only called by the GC, and the GC only calls an objects finalizer when there are no other references to the object, it is clear that the <em>Dispose</em> method will never be called on the object. In this case, the object should release any managed or unmanaged references, allowing the GC to release those objects as well. Since the same object references are being released as those that are released when <em>Dispose</em> is called, this method calls the <em>Dispose(bool disposing)</em> method passing <em>false</em>, indicating that the references objects <em>Dispose</em> method should <em>not</em> be called.</p>
<h3>Dispose(bool)</h3>
<p>All object references and unmanaged resources are released in this method. However, the argument indicates whether or not the <em>Dispose</em> method should be called on any managed object references. If the argument is <em>false</em>, the references to managed objects that implement <em>IDisposable</em> should be set to <em>null</em>, however, the <em>Dispose</em> method on those objects should <em>not</em> be called. The reason being that the owning objects <em>Dispose</em> method was not called (<em>Dispose(false)</em> is only called by the finalizer, and not the <em>Dispose</em> method.</p>
<h2>Overriding <em>Dispose</em></h2>
<p>In the example above, the <em>Dispose(bool disposing)</em> method is declared as <em>protected virtual</em>. This is to allow classes that inherit from this class to participate in the disposable of the object without impacting the behavior of the base class. In this case, a subclass should override the method as shown below.</p>
<pre><code>public class SubDisposableClass : 
    DisposableClass
{
    private bool _disposed;

    // a finalizer is not necessary, as it is inherited from
    // the base class

    protected override void Dispose(bool disposing)
    {
        if (!_disposed)
        {
            if (disposing)
            {
                // free other managed objects that implement
                // IDisposable only
            }

            // release any unmanaged objects
            // set object references to null

            _disposed = true;
        }

        base.Dispose(disposing);
    }
}
</code></pre>
<p>The subclass overrides the method, releasing (and optionally disposing) object references first, and then calling the base method. This ensures that objects are released in the proper order (at least between the subclass and the base class, the proper order of releasing/disposing objects within the subclass itself is the responsibility of the developer).</p>
<h2>Exceptions, Happen</h2>
<p>Prior to .NET 2.0, if an object’s finalizer threw an exception, that exception was swallowed by the runtime. Since .NET 2.0, however, throwing an exception from a finalizer will cause the application to crash, and that’s bad. Therefore, it is important that a finalizer never throw an exception.</p>
<p>But what about the <em>Dispose</em> method, should it be allowed to throw an exception? The short answer, is <em>no</em>. Except when the answer is yes, which is almost never. Therefore, it is important to wrap any areas of the Dispose(bool disposing) method that could throw an exception in a try/catch block as shown below.</p>
<pre><code>protected virtual void Dispose(bool disposing)
{
    if (_disposed)
        return;

    if (disposing)
    {
        _session.Dispose();
    }

    try
    {
        _channelFactory.Close();
    }
    catch (Exception ex)
    {
        _log.Warn(ex);

        try
        {
            _channelFactory.Abort();
        }
        catch (Exception cex)
        {
            _log.Warn(cex);
        }
    }

    _session = null;
    _channelFactory = null;

    _disposed = true;
}
</code></pre>
<p>In the example, <strong><em>session</em> is a reference to an NHibernate <em>ISession</em> and <em></strong>channelFactory</em> is a reference to a WCF <em>IChannelFactory</em>. An NHibernate <em>ISession</em> implements <em>IDisposable</em>, so the owner must call <em>Dispose</em> on it when the object is no longer needed. In the case of the <em>IChannelFactory</em> reference, there is no <em>Dispose</em> method, however, the object must be closed (and subsequently aborted in case of an exception). Because either of these methods can throw an exception, it is important to catch the exception (and, as shown above, log it for troubleshooting or perhaps just ignore it) so that it doesn’t cause either the <em>Dispose</em> method or the object’s finalizer to propagate the exception.</p>
<h2>Constructor Exceptions</h2>
<p>On a related topic, when an object’s constructor throws an exception, the runtime considers the object to have never existed. And while the GC will release any object allocated by the constructor, it will <em>not</em> call the <em>Dispose</em> method on any disposable objects. Therefore, if an object is creating references to managed objects in the constructor (or even more importantly, unmanaged objects that consume limited system resources, such as file handles, socket handles, or threads), it should be sure to dispose of those resources in the case of a constructor exception by using a try/catch block.</p>
<blockquote><p>While one might be tempted to call _Dispose_ from the constructor to handle an exception, don’t do it. When the constructor throws an exception, technically the object does not exist. Calling methods, particularly virtual methods, should be avoided.</p></blockquote>
<p>Of course, in the case of managed objects such as an <em>ISession</em>, it is better to take the object as a dependency on the constructor and have it passed into the object by an object factory (such as a dependency injection container, such as Autofac) and let the object factory manage the lifecycle of the dependency.</p>
<h2>Container Lifecycle Management</h2>
<p>Dependency injection containers are powerful tools, handling object creation and lifecycle management on behalf of the developer. However, it is important to have a clear understanding of how to use the container in the context of an application framework.</p>
<p>For example, ASP.NET has a request lifecycle for every HTTP request received by the server. To support this lifecycle, containers typically have integration libraries that hook into the framework to ensure proper object disposal. For instance, Autofac has a number of integration libraries for ASP.NET, ASP.NET MVC, ASP.NET Web API, and various other application frameworks. These libraries, when configured into the stack as HttpModules, ensure that objects are properly disposed when each request completes.</p>
<h2>Conclusion</h2>
<p>The reason for <em>IDisposable</em> is deterministic release of references by an object (something that used to happen manually with unmanaged languages by calling <em>delete</em> on an object). Implementing it both properly and consistently helps create applications that have predictable resource usage and more easy to troubleshoot. Therefore, consider the example above as a reference point for how objects should be disposed.</p>
<p>References:<br />
- <a href="http://code.google.com/p/autofac/source/browse/#hg%2FCore%2FSource%2FAutofac.Integration.Web">Autofac Web Integration</a><br />
- <a href="http://msdn.microsoft.com/en-us/library/b1yfkh5e%28v=vs.100%29.aspx">Microsoft Documentation</a></p>
<p>Bonus:<br />
- <a href="https://blogs.relayhealth.com/wp-content/uploads/2012/11/DisposeTemplates.DotSettings.zip">Resharper Template</a></p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/chrispatterson/2012/11/29/idisposable-done-right/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>Separating Concerns &#8211; Part 1: Libraries</title>
		<link>http://lostechies.com/chrispatterson/2012/11/22/separating-concerns-part-1-libraries/</link>
		<comments>http://lostechies.com/chrispatterson/2012/11/22/separating-concerns-part-1-libraries/#comments</comments>
		<pubDate>Thu, 22 Nov 2012 17:21:23 +0000</pubDate>
		<dc:creator>Chris Patterson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lostechies.com/chrispatterson/?p=101</guid>
		<description><![CDATA[Introduction In large applications, particularly in enterprise applications, separation of concerns is critical to ease maintainability. Without proper separation of concerns, applications become too large and too complex, which in turn makes maintenance and enhancement extremely difficult. Separating application concerns&#160;&#8230; <a href="http://lostechies.com/chrispatterson/2012/11/22/separating-concerns-part-1-libraries/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>In large applications, particularly in enterprise applications, <a href="http://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a> is critical to ease maintainability. Without proper separation of concerns, applications become too large and too complex, which in turn makes maintenance and enhancement extremely difficult. Separating application concerns leads to high <a href="http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29">cohesion</a>, allowing developers to better understand code behavior which leads to easier code maintenance.</p>
<h3>History</h3>
<p>In the previous decade, architects designed applications using an <a href="http://en.wikipedia.org/wiki/Multitier_architecture">n-tier approach</a>, separating the application into horizontal layers such as user interface, business logic, and data access. This approach is incomplete, however, as it fails to address partitioning applications vertically. Unrelated concerns are commingled, resulting in a confusing architecture which lacks clearly defined boundaries and has low cohesion.</p>
<p>The other problem with an n-tier architecture is how it is organized from top to bottom, with the topmost layer being the presentation layer or user interface, and the bottommost layer representing the persistence layer or database. Instead of thinking of the architecture as horizontal layers, think of them as rings, as described by the <a href="http://jeffreypalermo.com/blog/the-onion-architecture-part-1/">Onion Architecture</a> described by <a href="http://jeffreypalermo.com/">Jeffrey Palermo</a>. (<em>While Jeffrey proposed the pattern name, the architectural patterns have been defined previously by others.</em>)</p>
<h2>Separating Concerns</h2>
<p>Given that a separation of concerns and increasing cohesion are the goals, there are several mechanisms towards achieving them. The solutions that follow include the use of libraries, services, and frameworks as ways to reach these goals.</p>
<h2>The Library</h2>
<p>A <a href="http://en.wikipedia.org/wiki/Library_%28computing%29">library</a> is a set of functions used to build software applications. Rather than requiring an application to be a single project containing every source file, most programming languages provide a means to segregate functionality into libraries. While the facility name varies, a partial list of which includes <em>package</em>, <em>module</em>, <em>gem</em>, <em>jar</em>, and <em>assembly</em>, the result is enabling developers to separate functions physically from the main application project, improving both cohesion and maintainability.</p>
<h3>Core, the new Manager</h3>
<p>A library should not be a collection of unrelated functions, it should contain related functions so that it is highly cohesive. An application developer should be able to select a library for use based on its name and purpose, rather than having to pour through the source code to find the function or functions needed. A library should have a descriptive name and contain a cohesive set of functions towards a singular purpose or responsibility.</p>
<blockquote>
<p>Creating a library named <em>Core</em> containing a large set of unrelated functions is separation of the sake of separation, and that library should not be treated as a library but as part of the application — it should not be reused by other applications.</p>
</blockquote>
<h3>Coupling (aka, the Path of Pain)</h3>
<p>When an industry analyst shares their observations about code reuse in the enterprise, the findings indicate that actual code reuse is very low. A main reason that code reuse is so low is tight coupling. <a href="http://en.wikipedia.org/wiki/Coupling_%28computer_science%29">Coupling</a> refers to how two libraries (or functions) rely on each other. When a library relies upon another library, the library relied on is referred to as a dependency. When an application relies on a library, it implicitly relies on the library’s dependencies as well. In many larger applications, this can lead straight to <a href="http://en.wikipedia.org/wiki/Dependency_hell">dependency hell</a>.</p>
<p>Since tight coupling can lead to serious maintenance issues during an application’s lifecycle, limiting dependencies should be first and foremost in application and library design. If a function is to be moved from an application to a library, and that function must bring with it a dependency that was not previously required by the target library, the cost of adding the new dependency to the library must be considered. Too often, particularly in the enterprise where code is only reviewed internally by a single development team, poor choices are made when creating libraries. Functions are routinely moved out of the main project and placed into arbitrary libraries with little thought given to the additional dependencies of the library.</p>
<h3>An Example</h3>
<p>As an example, a web application has a set of functions for validating email addresses. The simplest validation methods may only depend upon regular expression functions, which are part of every modern language runtime used today. A more complete validation of an email address may check that the domain is actually valid and has a properly registered MX record in DNS. However, validating the domain involves sending a request to a service and waiting for the response indicating a valid domain before the email address is determined to be valid.</p>
<p>There are many things wrong in this example. First, the email validation function has a dependency on a domain validation function. Due to the fact that the set of valid domains is continuously changing, the domain validation function itself has a dependency on a domain name service. Of course, the domain name service depends upon a network domain name service, which may subsequently depend upon an internet service as well. By calling one library function, the application has managed to send a request to another machine and block a thread waiting for a response.</p>
<p>In the case of an error, the disposition of the email address is then unknown. Is it a valid email address that could not be validated due to a network error? Or is it a valid email address but flagged as invalid because the domain name could not be validated due to an internal DNS server not allowing external domains to be returned?</p>
<p>The coupling in the email validation library is clearly a problem, but what happens as the business requirements evolve over the life of the application? Consider the situation where new accounts are being created by spammers from other countries. To combat the spam accounts, email addresses must now be validated to ensure that the IP address originates from within the United States. The email validation function now has a new dependency, a geolocation service that returns the physical address of a domain. However, the service requires the use of separate endpoints for testing and production. The email address validation function is now dependent upon two services and configuration data to determine which service endpoint to use.</p>
<p>At this point, it is obvious that the complexity of validating an email address is not something that can be accomplished in a library function.</p>
<p>This article will continue with Part 2 on services.</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/chrispatterson/2012/11/22/separating-concerns-part-1-libraries/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Interview on .NET Rocks Episode 798 Published</title>
		<link>http://lostechies.com/chrispatterson/2012/08/30/interview-on-net-rocks-episode-798-published/</link>
		<comments>http://lostechies.com/chrispatterson/2012/08/30/interview-on-net-rocks-episode-798-published/#comments</comments>
		<pubDate>Thu, 30 Aug 2012 17:15:51 +0000</pubDate>
		<dc:creator>Chris Patterson</dc:creator>
				<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://lostechies.com/chrispatterson/?p=99</guid>
		<description><![CDATA[Last weekend, the guys from .NET Rocks! interviewed me for the show, and the show is now available from the usual outlets (iTunes, etc.). You can read the summary on their web site, as well as listen to the show!&#160;&#8230; <a href="http://lostechies.com/chrispatterson/2012/08/30/interview-on-net-rocks-episode-798-published/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Last weekend, the guys from .NET Rocks! interviewed me for the show, and the show is now available from the usual outlets (iTunes, etc.). You can read the <a href="http://www.dotnetrocks.com/default.aspx?showNum=798">summary on their web site</a>, as well as listen to the show! It was a fun discussion that covered a variety of topics, including MassTransit, Topshelf, Magnum, and other open source themes.</p>
<p><a href="http://www.dotnetrocks.com/default.aspx?showNum=798">Check it out!</a></p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/chrispatterson/2012/08/30/interview-on-net-rocks-episode-798-published/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rebooting Topshelf for Version 3</title>
		<link>http://lostechies.com/chrispatterson/2012/07/23/rebooting-topshelf-for-version-3/</link>
		<comments>http://lostechies.com/chrispatterson/2012/07/23/rebooting-topshelf-for-version-3/#comments</comments>
		<pubDate>Mon, 23 Jul 2012 15:16:41 +0000</pubDate>
		<dc:creator>Chris Patterson</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[topshelf]]></category>

		<guid isPermaLink="false">http://lostechies.com/chrispatterson/?p=97</guid>
		<description><![CDATA[When we created Topshelf, one of the prime directives was ease of use. It had to be easy for the developer to add a reference and create a service. To keep it easy, we had another prime directive: the developer&#160;&#8230; <a href="http://lostechies.com/chrispatterson/2012/07/23/rebooting-topshelf-for-version-3/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When we created Topshelf, one of the prime directives was ease of use. It had to be easy for the developer to add a reference and create a service. To keep it easy, we had another prime directive: the developer should only be required to reference a single assembly to get Topshelf to work. And that assembly should have no dependencies.</p>
<h2>Why?</h2>
<p>Before NuGet, using open source was difficult for .NET developers. With so many different versions of assemblies and no single point of distribution, it was a continuous effort to get a solution with multiple open source dependencies to build properly. Fast forward to today, the NuGet world, and developers can simply add a reference using the NuGet package manager and all the dependencies come along for the ride. The migration of the community towards NuGet has made the directive of one assembly significantly less important.</p>
<p>This evolution of the open source community requires authors to re-imagine their products to fit properly in this new world. In order to keep Topshelf the best and easiest way to create Windows services, we are planning to do just that &#8212; re-imagine the model for Topshelf going forward.</p>
<p>With the release of Topshelf 3.0, the main NuGet package will contain only the functionality necessary to create, install, and control your own service. By focusing on this single goal, the highest level of safety and stability can be attained. This allows allows us to keep the footprint of Topshelf as small as possible, reducing the surface area around your mission-critical services that are running on it.</p>
<p>Once we have the main Topshelf assembly stable and production tested, we will revisit the other features of Topshelf and look at how it they fit into the new direction. Some features may be discarded while others may be changed to be more operationally sustainable. These features, however, will not be included in the main package. Instead, they will sit on top of the stable and proved Topshelf assembly, ensuring that the core functionality remains solid.</p>
<h2>When?</h2>
<p>I’ll be posting a prerelease version of 3.0 on the main NuGet feed in the next few days. This version will continue to support both .NET 3.5 and .NET 4.0, as well as .NET 4.5 once it is generally available (the 4.x version should work with 4.5 until then). The previous v2.x code branches will be renamed from (develop/master) for retention (v2_develop/v2_master).</p>
<p>Migration from previous versions should be fairly painless as the API is nearly identical. There are a few minor tweaks and some additional options for using the new features (such as the ability to control the host from the service, including the ability to stop the service &#8212; a very requested feature), most of the settings such as service name and such are now entirely optional, with the default using the namespace of the hosting assembly for the service name.</p>
<p>That&#8217;s the current roadmap for Topshelf. Hopefully you&#8217;ll agree that this reboot makes sense, as the current codebase has completely outgrown what is needed to host a simple service. Using this additive approach should make it easier to build features on top of the solid core Topshelf service, without comprising the integrity of the base service host functionality.</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/chrispatterson/2012/07/23/rebooting-topshelf-for-version-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Benchmarque &#8211; Comparative Benchmarking for .NET</title>
		<link>http://lostechies.com/chrispatterson/2012/07/18/benchmarque-comparative-benchmarking-for-net/</link>
		<comments>http://lostechies.com/chrispatterson/2012/07/18/benchmarque-comparative-benchmarking-for-net/#comments</comments>
		<pubDate>Wed, 18 Jul 2012 16:51:19 +0000</pubDate>
		<dc:creator>Chris Patterson</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://lostechies.com/chrispatterson/?p=95</guid>
		<description><![CDATA[Last night, I announced that the first release of my benchmarking library Benchmarque was available on NuGet. This morning, I&#8217;d like to share with you what the library is, and how it to use it. What is Benchmarque? Benchmarque (pronounced&#160;&#8230; <a href="http://lostechies.com/chrispatterson/2012/07/18/benchmarque-comparative-benchmarking-for-net/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Last night, I <a href="https://twitter.com/phatboyg/status/225429499758641152">announced</a> that the first release of my benchmarking library Benchmarque was available on NuGet. This morning, I&#8217;d like to share with you what the library is, and how it to use it.</p>
<h2>What is Benchmarque?</h2>
<p>Benchmarque (pronounced <a href="http://www.bizmarkie.com/">bench-mar-key</a>) allows you to create comparative benchmarks using .NET. An example of a comparative benchmark would be evaluating two or more approaches to performing an operation, such as whether for(), foreach(), or LINQ is faster at enumerating an array of items. While this example often falls into the over-optimization category, there are many related algorithms that may warrant comparison when cycles matter.</p>
<h2>How do I use it?</h2>
<p>To understand how to use Benchmarque, let&#8217;s work through an example. First, start Visual Studio 2010 Service Pack 1 with NuGet 2.0 installed and create a new class library project using the .NET 4.0 runtime. Once created, we&#8217;re going to define an interface for our benchmark.</p>
<p><script src="https://gist.github.com/3137095.js?file=AppendText.cs"></script><noscript>
<pre><code class="language-c# c#">public interface AppendText
{
    string Append(params string[] args);
}</code></pre>
<p></noscript></p>
<p>In this benchmark, we are going to compare the performance of the different ways to append text into a single string. Now that we have the interface defining the behavior we want to benchmark, we need to create a few implementations that perform the operation.</p>
<p>First, the good old concatenation operator.</p>
<p><script src="https://gist.github.com/3137095.js?file=ConcatAppendText.cs"></script><noscript>
<pre><code class="language-c# c#">public class ConcatAppendText :
    AppendText
{
    public string Append(params string[] args)
    {
        string result = string.Empty;

        for (int i = 0; i &lt; args.Length; i++)
        {
            result += args[i];
        }

        return result;
    }
}</code></pre>
<p></noscript></p>
<p>Next, we&#8217;ll use a StringBuilder to handle the work.</p>
<p><script src="https://gist.github.com/3137095.js?file=StringBuilderAppendText.cs"></script><noscript>
<pre><code class="language-c# c#">public class StringBuilderAppendText :
    AppendText
{
    public string Append(params string[] args)
    {
        var builder = new StringBuilder();

        for (int i = 0; i &lt; args.Length; i++)
        {
            builder.Append(args[i]);
        }
        return builder.ToString();
    }
}</code></pre>
<p></noscript></p>
<p>And last, we&#8217;ll try to use string.Join with an empty separator.</p>
<p><script src="https://gist.github.com/3137095.js?file=JoinAppendText2.cs"></script><noscript>
<pre><code class="language-c# c#">public class JoinAppendText :
    AppendText
{
    public string Append(params string[] args)
    {
        return string.Join(&quot;&quot;, args);
    }
}</code></pre>
<p></noscript></p>
<p>With our three implementations ready to benchmark, we now need to create an actual benchmark. We&#8217;ll take a list of names, and call the interface with those names. Before we can do that, however, it&#8217;s time to add Benchmarque to the project. Using the NuGet package manager, install Benchmarque to your class library project.</p>
<p><img src="http://blog.phatboyg.com/wp-content/uploads/2012/07/BenchmarqueInstall.png" alt="Installing from Package Manager" width="582" height="258" border="0" /></p>
<p>Once installed, we can create our benchmark class as shown below.</p>
<p><script src="https://gist.github.com/3137095.js?file=NameAppendBenchmark.cs"></script><noscript>
<pre><code class="language-c# c#">public class NameAppendBenchmark :
    Benchmark&lt;AppendText&gt;
{
    static readonly string[] Names = new[]
        {
            &quot;Adam&quot;, &quot;Betty&quot;, &quot;Charles&quot;, &quot;David&quot;,
            &quot;Edward&quot;, &quot;Frodo&quot;, &quot;Gandalf&quot;, &quot;Henry&quot;,
            &quot;Ida&quot;, &quot;John&quot;, &quot;King&quot;, &quot;Larry&quot;, &quot;Morpheus&quot;,
            &quot;Neo&quot;, &quot;Peter&quot;, &quot;Quinn&quot;, &quot;Ralphie&quot;, &quot;Samwise&quot;,
            &quot;Trinity&quot;, &quot;Umma&quot;, &quot;Vincent&quot;, &quot;Wanda&quot;
        };

    public void WarmUp(AppendText instance)
    {
        instance.Append(Names);
    }

    public void Shutdown(AppendText instance)
    {
    }

    public void Run(AppendText instance, int iterationCount)
    {
        for (int i = 0; i &lt; iterationCount; i++)
        {
            string result = instance.Append(Names);
        }
    }

    public IEnumerable&lt;int&gt; Iterations
    {
        get { return new[] {1000, 10000}; }
    }
}</code></pre>
<p></noscript></p>
<p>A benchmark includes three methods that involve the execution of the benchmark, along with a property that returns the iteration counts for each run. WarmUp is called with the implementation to allow any one-time initialization of the implementation to be established. This allow should include a few runs through the test to allow the runtime to JIT any code to ensure the benchmark only includes actual execution time (versus assembly load and JIT time). The Run method is then called with each of the iteration counts to actually run the benchmark. Once complete, the Shutdown method is called to dispose of any resources used by the implementation.</p>
<p>The benchmark runner (Benchmarque.Console, which is installed in the tools folder by NuGet) will run the benchmark with each implementation and measure the time taken. To run the benchmark, we need to open the NuGet Package Manager Console, change to the assembly folder, and start the benchmark using Start-Benchmark as shown below.</p>
<p><img src="http://blog.phatboyg.com/wp-content/uploads/2012/07/PackageManagerConsoleMenu.png" alt="Open the package manager console" width="600" height="92" border="0" /></p>
<p>Once open, change to the folder for the assembly to benchmark.</p>
<p><img src="http://blog.phatboyg.com/wp-content/uploads/2012/07/BenchmarqueConsoleCD.png" alt="Change to the output folder" width="463" height="196" border="0" /></p>
<p>And now, we&#8217;re going to run the actual benchmark and view the results.</p>
<p><img src="http://blog.phatboyg.com/wp-content/uploads/2012/07/BenchmarqueResults.png" alt="Results of benchmark" width="600" height="251" border="0" /></p>
<p>First, Start-Benchmark is a Powershell function that is added by the init.ps1 that&#8217;s included in the NuGet package. It handles the execution of the benchmark using the console runner. Once complete, the output of the benchmark is displayed in the console window.</p>
<p>As shown above, the results of the test execution are ordered with the fastest implementation first, followed by the remaining implementations with the difference and how many times slower it is displayed. The output is pretty basic at this point, without a lot of other calculations displayed. Additional items may be added as some point. For now, it&#8217;s enough to give me the answers I need when trying different approaches to the same problem.</p>
<p>The library is open source (I&#8217;ll put the Apache 2 documents in place at some point), so feel free to use, abuse, modify, and enhance as needed! </p>
<p><em>One request: If anyone is a Powershell megastar and can modify the Benchmarque.psm1 so that if no argument is specified, it looks through the solution for the projects that are referencing Benchmarque, and automatically running the benchmarks in those assemblies so they don&#8217;t have to be specified explicitly.</em></p>
<p><em><br /></em></p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/chrispatterson/2012/07/18/benchmarque-comparative-benchmarking-for-net/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>MassTransit v2.5.3 Now Supports the TPL</title>
		<link>http://lostechies.com/chrispatterson/2012/07/06/masstransit-v2-5-3-now-supports-the-tpl/</link>
		<comments>http://lostechies.com/chrispatterson/2012/07/06/masstransit-v2-5-3-now-supports-the-tpl/#comments</comments>
		<pubDate>Fri, 06 Jul 2012 18:12:05 +0000</pubDate>
		<dc:creator>Chris Patterson</dc:creator>
				<category><![CDATA[masstransit]]></category>
		<category><![CDATA[signalR]]></category>

		<guid isPermaLink="false">http://lostechies.com/chrispatterson/?p=89</guid>
		<description><![CDATA[As I&#8217;ve started to use MassTransit with SignalR, one of the things that annoyed me was the hoops I had to jump through to get a nice asynchronous request from SignalR into MassTransit. There was a lot of plumbing since&#160;&#8230; <a href="http://lostechies.com/chrispatterson/2012/07/06/masstransit-v2-5-3-now-supports-the-tpl/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;ve started to use MassTransit with SignalR, one of the things that annoyed me was the hoops I had to jump through to get a nice asynchronous request from SignalR into MassTransit. There was a lot of plumbing since the MT did not support the TPL.</p>
<p>Well, I&#8217;ve changed that. With version 2.5.3 (a prerelease version on NuGet), you can now get a really nice clean syntax to return tasks from server-side SignalR hubs (and other calls that expect a Task return value.</p>
<p><script src="https://gist.github.com/3061985.js?file=First.cs"></script><noscript>
<pre><code class="language-c# c#">public class Location :
    Hub
{
    public Task GetLocation(string truckId)
    {
        Task task = null;
        Bus.Instance.PublishRequestAsync(new GetLocation { TruckId = truckId }, x =&gt;
        {
            task = x.Handle(message =&gt; {});
            x.SetTimeout(30.Seconds());
        });

        return task;
    }
}</code></pre>
<p></noscript></p>
<p>Shown above is a SignalR hub that sends a request message off to some service. The LocationResult handler that is added within the closure returns a Task&lt;LocationResult&gt;, which can be returned to SignalR allowing the server-side code to remain asynchronous. If additional work needed to be done to transform the message to another type or do perform some type of validation, a .ContinueWith() could be added to the task to return the proper result type.</p>
<p><script src="https://gist.github.com/3061985.js?file=Second.cs"></script><noscript>
<pre><code class="language-c# c#">public class Location :
    Hub
{
    public Task GetLocation(string truckId)
    {
        Task task = null;
        Bus.Instance.PublishRequestAsync(new GetLocation { TruckId = truckId }, x =&gt;
        {
            task = x.Handle(message =&gt; {});
            x.SetTimeout(30.Seconds());
        });

        return task.ContinueWith(t =&gt; new LocationView(...));
    }

    public class LocationView
    {
        public string TruckId { get; set; }
        public string Location { get; set; }
    }
}</code></pre>
<p></noscript></p>
<p>If the request times out, the task for the handler will be cancelled, so be sure to take that into account.</p>
<p>Pretty power stuff eh?</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/chrispatterson/2012/07/06/masstransit-v2-5-3-now-supports-the-tpl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Received my 4th Visual C# MVP Award!</title>
		<link>http://lostechies.com/chrispatterson/2012/07/02/received-my-4th-visual-c-mvp-award/</link>
		<comments>http://lostechies.com/chrispatterson/2012/07/02/received-my-4th-visual-c-mvp-award/#comments</comments>
		<pubDate>Mon, 02 Jul 2012 13:21:50 +0000</pubDate>
		<dc:creator>Chris Patterson</dc:creator>
				<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://lostechies.com/chrispatterson/?p=87</guid>
		<description><![CDATA[I&#8217;m happy to announce that I have been awarded the 2012 Microsoft® MVP award for my technical contributions to the Visual C# community over the past year. This is the fourth consecutive year that I have received the award, and I&#160;&#8230; <a href="http://lostechies.com/chrispatterson/2012/07/02/received-my-4th-visual-c-mvp-award/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m happy to announce that I have been awarded the 2012 Microsoft® MVP award for my technical contributions to the Visual C# community over the past year. This is the fourth consecutive year that I have received the award, and I greatly appreciate the recognition. I would also like to thank everyone who has supported me over the past year, allowing me the time to prepare interesting content, travel to amazing conferences (including my first trip to Sweden last year), and deliver engaging presentations to the software development community.</p>
<p><img src="http://blog.phatboyg.com/wp-content/uploads/2012/07/mvplogo.jpeg" alt="Mvplogo" width="600" height="115" border="0" /></p>
<p>As I look back at the past three years, the most rewarding benefit of being an MVP awardee is communication with the product teams at Microsoft. Being able to discuss product goals, features, and roadmaps with the actual development teams is extremely valuable. When I look at how Microsoft has evolved over the past couple of years alone, I see a company that is embracing open source (look at the full ASP.NET web stack) and retooling their development products to facility greater sharing of open source libraries (NuGet, for example). I look forward to even more interaction with the teams over the next year as the Windows platform adapts to the changing modalities in personal computing.</p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/chrispatterson/2012/07/02/received-my-4th-visual-c-mvp-award/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Odoyule Rules Engine for .NET</title>
		<link>http://lostechies.com/chrispatterson/2012/04/11/odoyule-rules-engine-for-net/</link>
		<comments>http://lostechies.com/chrispatterson/2012/04/11/odoyule-rules-engine-for-net/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 16:16:16 +0000</pubDate>
		<dc:creator>Chris Patterson</dc:creator>
				<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://lostechies.com/chrispatterson/?p=85</guid>
		<description><![CDATA[So I&#8217;ve been writing a rules engine for .NET for many years (on and off, but mostly off unfortunately). Lately, I picked it up again and yesterday published an early version on NuGet (OdoyuleRules). The implementation at this point is&#160;&#8230; <a href="http://lostechies.com/chrispatterson/2012/04/11/odoyule-rules-engine-for-net/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been writing a rules engine for .NET for many years (on and off, but mostly off unfortunately). Lately, I picked it up again and yesterday published an early version on NuGet (OdoyuleRules). The implementation at this point is capable of pretty extensive matching, but testing is light at this point so there are probably some rough edges.</p>
<p>One of my favorite features is the visualization of the RETE graph once the engine has been loaded with rules. An example is shown below.</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="http://blog.phatboyg.com/wp-content/uploads/2012/04/OdoyuleRulesVisualization.png" border="0" alt="OdoyuleRulesVisualization" width="640" height="305" /></p>
<p> </p>
<p>You can download the Visualizer and install it in Visual Studio 2010 (unzip the contents to your My Document/Visual Studio 2010/Visualizers folder). Then, mouse over a reference to a rules engine while debugging and you should be able to select and display the RETE graph of the engine.</p>
<p>Download the visualizer assemblies here: <a title="OdoyuleRulesVisualizer.zip" href="http://blog.phatboyg.com/wp-content/uploads/2012/04/OdoyuleRulesVisualizer.zip">OdoyuleRulesVisualizer.zip</a></p>
<p>The project is hosted on GitHub, at <a href="http://phatboyg.github.com/OdoyuleRules">http://phatboyg.github.com/OdoyuleRules</a></p>
<p>Enjoy!</p>
<p> </p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/chrispatterson/2012/04/11/odoyule-rules-engine-for-net/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>References on the Actor Programming Model</title>
		<link>http://lostechies.com/chrispatterson/2011/11/26/references-on-the-actor-programming-model/</link>
		<comments>http://lostechies.com/chrispatterson/2011/11/26/references-on-the-actor-programming-model/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 20:22:56 +0000</pubDate>
		<dc:creator>Chris Patterson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lostechies.com/chrispatterson/?p=83</guid>
		<description><![CDATA[The actor programming model is a software development method that encourages the decomposition of applications into autonomous components which are self-contained and operate asynchronously and independently from one another. This model is well aligned with the nondeterministic nature of distributed&#160;&#8230; <a href="http://lostechies.com/chrispatterson/2011/11/26/references-on-the-actor-programming-model/">Continue&#160;reading&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The actor programming model is a software development method that encourages the decomposition of applications into autonomous components which are self-contained and operate asynchronously and independently from one another. This model is well aligned with the nondeterministic nature of distributed systems, including mobile systems, interactive systems, and the internet.</p>
<p>As I mentioned previously, I didn&#8217;t invent it. I&#8217;m merely leveraging the information obtained from a number of sources and applying it in a way that I think makes it easier to build certain types of applications. Applications that can benefit from a highly concurrent actor-based programming model include reactive systems &#8212; ones that respond to nondeterministic external events. Since many applications can be described as &#8220;a program that responds to external events&#8221; it only makes sense that the actor programming model can be applied to many domains.</p>
<p>Here are some papers that I&#8217;ve read on the actor model, some of which have influenced me in how I think about concurrent programming and others that have merely provided background information or depicted ways in which concurrent programming should not be approached.</p>
<p><a href="http://www.google.com/url?sa=t&amp;rct=j&amp;q=actors%20rajesh%20karmani&amp;source=web&amp;cd=5&amp;ved=0CD8QFjAE&amp;url=http%3A%2F%2Fwww.cs.ucla.edu%2F~palsberg%2Fcourse%2Fcs239%2Fpapers%2Fkarmani-agha.pdf&amp;ei=1EjRToveNYTo2QW8jL2fDw&amp;usg=AFQjCNFGRhp1lee0PTWR-P-zoZh53PlPPg">Actors</a>, Rajesh K. Karmani, Gul Agha</p>
<p><a href="http://hdl.handle.net/1721.1/1692">Actors: A Model of Concurrent Computation In Distributed Systems</a>, Gul A. Agha (out of print)</p>
<p><a href="http://www.google.com/url?sa=t&amp;rct=j&amp;q=actor%20languages%20for%20specification%20of%20parallel%20computations&amp;source=web&amp;cd=2&amp;sqi=2&amp;ved=0CCcQFjAB&amp;url=http%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fdownload%3Fdoi%3D10.1.1.54.8636%26rep%3Drep1%26type%3Dpdf&amp;ei=yUTRTsagJ-Gi2gWq--ySDw&amp;usg=AFQjCNG9xXGsndDiaOg4e1IXmidFT6_QyA">Actor Languages for Specification of Parallel Computations</a>, Gul Agha, Wooyoung Kim, Rajendra Panwar</p>
<p><a href="http://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;ved=0CCwQFjAA&amp;url=http%3A%2F%2Fosl.cs.illinois.edu%2Fdocs%2Fhp92%2Fhp.pdf&amp;ei=OEbRTvPvKILS2gXg3cy6Dw&amp;usg=AFQjCNHnqFN88E0QqQhuMq8hIWvJXMlJbQ">An Actor-Based Framework for Heterogeneous Computing Systems</a>, Gul Agha, Rajendra Panwar</p>
<p><a href="http://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;ved=0CB0QFjAA&amp;url=http%3A%2F%2Flamp.epfl.ch%2F~phaller%2Fdoc%2Fhaller07actorsunify.pdf&amp;ei=dkbRTsjhEKrs2AXi96nMDw&amp;usg=AFQjCNEGCiUihzxt1xrjfocx_qanRATegw">Actors that Unify Threads and Events</a>, Philipp Haller, Martin Odersky</p>
<p><a href="http://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;ved=0CCAQFjAA&amp;url=http%3A%2F%2Flamp.epfl.ch%2F~phaller%2Fdoc%2Fhaller10-Translucent_functions.pdf&amp;ei=qkbRToTHIsWC2wXUsrmaDw&amp;usg=AFQjCNHfk44fbCGvf3ZDzI0BLkfNxITyDA">Lightweight Language Support for Type-Based, Concurrent Event Processing</a>, Philipp Haller</p>
<p><a href="http://www.google.com/url?sa=t&amp;rct=j&amp;q=compilation%20of%20a%20highly%20parallel%20actor-based%20language&amp;source=web&amp;cd=3&amp;sqi=2&amp;ved=0CDUQFjAC&amp;url=http%3A%2F%2Fosl.cs.illinois.edu%2Fdocs%2Fhal-compilation92%2Fhal-compilation.pdf&amp;ei=TEnRTrbUK6Hq2QXarNm1Dw&amp;usg=AFQjCNFRI9bn7Cl-b8AkWmcIceFl5kQ8tQ">Compilation of a Highly Parallel Actor-Based Language</a>, WooYoung Kim, Gul Agha</p>
<p>These are some of the more involved works from which I&#8217;ve found many useful bits of information. I&#8217;ve got them permanently stored in <a href="http://www.goodiware.com/goodreader.html">GoodReader</a> so I can keep looking back to them (and my associated annotations as well). Hopefully anyone looking to build systems using the actor model (and hopefully, using Stact if you&#8217;re on the .NET platform) can get a better understanding of the model by reviewing these papers.</p>
<p> </p>
<p><font color="#B4B4B4" size="-2">Post Footer automatically generated by <a href="http://www.freetimefoto.com/add_post_footer_plugin_wordpress" style="color: #B4B4B4; text-decoration:underline;">Add Post Footer Plugin</a> for wordpress.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://lostechies.com/chrispatterson/2011/11/26/references-on-the-actor-programming-model/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
