Rx is now an official and supported product
Head over to Channel9 to read more about the official release. The setup package (available here) contains the components for .NET 3.5 SP1, .NET 4, Silverlight 4 and Windows Phone 7.
Head over to Channel9 to read more about the official release. The setup package (available here) contains the components for .NET 3.5 SP1, .NET 4, Silverlight 4 and Windows Phone 7.
[Updated on 02 Jul 11 after the Rx official release]
I have to start this post with a clarification: “Ix” is not the name of an official product. I am just calling it so to highlight the benefits of this less known part of the Reactive Extensions or “Rx” (which is a real product by the way).
Interactive Extensions used to be part of the Rx library but they can now be downloaded separately. Rx is now officially released and the stable version can be downloaded from here. Ix is now packaged separately and its experimental release can be downloaded from here. Both of these components are also available on the main Nuget feed.
Even many developers who are using Rx are unaware of this interactive part of the library and I believe it deserves more attention. But let’s start with Rx, just in case you don’t know what it is.
Rx is a library developed by Microsoft, which allows you to write applications that react to events using a nice and clean implementation of the observable pattern. Rx started off as a Microsoft DevLabs incubation project but it proved to be very popular so its incubation period was ended in April 2011 and since then, it has been moved to the MSDN Data Developer Center.
I refer to the interactive part of the Rx product family as “Ix”, which deals with enumerable sequences (IEnumerable<T>) whereas Rx focuses on the observable sequences (Observable<T>).
If you have watched Inside the Rx video on Channel9 or read Bart De Smet’s blog post on this topic, you already know that enumerable sequences are the duals of the observable sequences. When the Rx team created the operators for the observable sequences, they also back ported some of those operators to the enumerable world and that is how Ix was born.
The following diagram shows the dependencies between major Rx and Ix components. Note that the reactive extensions come with a few more assemblies (related to async support, client profile and more) which are not displayed here.
So like Rx, Ix takes a dependency on:
- CoreEx: Providing the core functionality such as a selection of helpers for disposable objects, schedulers and concurrent data structures.
- System.Observable: Containing IObservable<T> and IObserver<T> interfaces. [Not applicable to .NET 4.0 as it is included in mscorlib 4.0]
The pre-release versions of the Rx product family consisted of various components such as System.Reactive, System.Interactive, CoreEx and System.Observable (for all runtimes except .NET 4.0). In the official release, the component structure is simplified and there are only two assemblies involved: System.Reactive and System.Interactive. All of the types required by those assemblies are now embedded in so for example, the IObservable and IObserver interfaces for runtimes other than .NET 4 now live inside System.Reactive. Same applies to the disposable and scheduler types.
If you are not using Rx family for whatever reason, it is now a good time to do so. I will go as far as saying:
If you are a .NET developer, then you should be using Rx and/or Ix in your projects or you are doing something wrong!
You might say I am taking it too far but I insist! If you are using Rx already, then you know what I am talking about. If you aren’t, you will know it when you start using it. Rx targets various platforms and frameworks including .NET (3.5, 4.0 for both client and full profiles), Silverlight (3, 4, 5), Windows Phone, Xbox and Javascript so you can use it in any .NET project.
These extensions can be downloaded by following the links on the product landing page on MSDN. You can also find a variety of Rx and Ix components on the official Nuget feed.
The primary type in Ix is the EnumerableEx type, which adds a long list of operators (in the form of extension methods) to IEnumerable<T>, plus a few operators for enumerable sequence of numbers (to support average, min, max, etc).When developers look at the list of operators provided by these extensions, most people ask “Why aren’t these included in .NET Framework anyway?”. I think (and hope) that this is just a matter of time before they make their way into the framework. Once you start using these extensions, you will soon find out that you cannot live without them, especially if you use LINQ frequently.
In the next post, I will briefly go through some of the Ix operators to show how it can help you in writing code that is easier to write and read.