Pages

December 16, 2010

Rx.NET Subject useful for connecting decoupled components

Rx has a nifty abstraction called Subject shipped as part of the System.Reactive assembly.

It's basically a buffer with channel like capabilities rolling up an Obsever/Observable pattern into a single class.

In cases where you have two or more classes that don't really know about each other but sometimes need to be connected (ie output of one should go into input of another), you can can inject an instance of a Subject class into both components, and then have them send messages. Subject provides a standard Rx.NET friendly API to push/pull messages, this makes it quite powerful as you can use the full expressive power of Rx.NET to consume message from Subjects in different scenarios (one-to-one, one-to-many, filtering, Join, etc) .





1 comment :

Madeth said...

I have never realized before how powerful Rx.NET can be. I have been trying to connect decoupled components and unfortunately, I didn't have luck with that. Let me know how it works out for you.

form an llc