Some Rx goodness

The observer pattern

In .NET 4 Microsoft introduced the IObserver<T> and IObservable<T> interfaces. These interfaces give you a generic way of providing push-based notification, which is also known as the observer pattern. The provider (IObservable<T>) must implement a Subscribe method, which lets the caller indicate it wants to receive push-based notifications. The caller passes an instance of the observer. The observer (IObserver<T>) must implement three methods (OnNext, OnError and OnCompleted) which the provider calls to send different kinds of notifications.

For slightly more detail and some simple examples, take a look at the interfaces for IObservable<T> andIObserver<T> in the msdn documentation.

A quick and high level overview of Rx

The Reactive Extensions libraries from Microsoft provide implementations of the interfaces outlined above. Rx uses LINQ to allow incredibly powerful but simple and declarative solutions to complex problems, when dealing with sequences of events. It is available as a number of different packages on NuGet. To install them all, look for Rx-Main. There is also an “Extensions for Reactive Extensions” package available on NuGet, called Rxx. This provides many more useful Reactive LINQ extensions that aren’t in the main Rx library from Microsoft.

View original

Blog at

Up ↑