Reactive Extensions helps developers write asynchronous and event based operations in a much simpler way. The user must specify a SynchronizationContext to which the Rx messages are sent. For e.g: If you are using a console app, you should specify the Context as
Rx is a library for composing asynchronous and event based programs using observable collections. The library revolves around the concept of “Reactive programming”. Reactive programming or reactive programs is not a new concept, we have been using reactive programming before in our applications by registering to an event handler or a call back on an asynchronous operation.
All these operations were performed by specifying delegates or methods that are called at unpredictable times. i.e. the functions were called based on an action or a change in the existing data type or code. But we can also think that these operations are performed when data is passed to them as an item in a sequence. For e.g. a sequence of button click events are passed to the method OnButtonClick(). Every time the function gets an input it performs some operation.
Rx is a superset of the standard LINQ sequence operators that exposes asynchronous and event based computations as push based observable collections via the .NET 4.0 interfaces IObservable and IObserver. These interfaces form the heart of Rx.
IObservable interface represents the class that sends notifications (the provider); the IObserver interface represents the class that receives them (the observer). T represents the class that provides the notification information.
publicinterfaceIObservable<out T>
{
IDisposable Subscribe(IObserver observer);
}
The provider object implements the IObservable that has a single method Subscribe, which indicates that an observer wants to receive push-based notifications. Callers to the method pass an instance of the observer.
publicinterfaceIObserver<in T>
{
void OnCompleted();
void OnError(Exception error);
void OnNext(T value);
}
The provider sends the following three kinds of notifications to the observer by calling IObserver<(Of <(T>)>) methods:
The current data. The provider can call the IObserver , OnNext method to pass the observer a T object that has current data, changed data, or fresh data.
An error condition. The provider can call the IObserver, OnError method to notify the observer that some error condition has occurred.
No further data. The provider can call the IObserver, OnCompleted method to notify the observer that it has finished sending notifications.
I have created a simple example to demonstrate the usage of IObservable and IObserver interfaces and the observer pattern implementation.
Setting the Field’s EditorStyle property to a XamEditor control allows inline editing and updating of properties much easier inside a XamDataGrid. You can choose from a wide range of Editors from Infragisitcs and use it as the EditorStyle.
For editing a currency value in my Grid I have declared the FieldSettings as
Working with FluentValidation makes my validation code cleaner and easier to integrate with the main application. I started removing my Enterprise library validation attributes and created Validators for my entities. The next major step was to integrate it with WPF. I have mentioned in one of my earlier posts on how to achieve this by implementing IDataErrorInfo on the business entities. Well, I had to follow the same approach for the FluentValidation classes also.
Here’s some sample code on the POC.
My BaseEntity class remains almost same, but with less code and looks clean