Living .NET...

Musings on .NET, and the like - Manoj G [MVP, Connected Systems Developer]

Patterns in .NET : Citing the Chain of Responsibility pattern

Chain of Responsibility basically involves “chaining” a set of objects between a sender and receiver, where each object in the chain does some processing on the message that is sent between the sender and the receiver.

 

In the .NET Framework, one area where this pattern manifests is the Remoting infrastructure. In Remoting, a remote method call actually translates to a message exchange between the client and the server. When the message passes between client and the server object, it goes through a series of message sinks, which are objects which implement the IMessageSink interface. Here’s how the interface looks like (attributes have been elided for clarity):

 

public interface IMessageSink
{
      IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink);
      
      IMessage SyncProcessMessage(IMessage msg);

      IMessageSink NextSink { 
get; }
}

 

The important thing to notice here is that each message sink has a reference to the next sink in the chain. Each sink forwards the message to the next sink in the chain and the last sink to handle the message would be the StackBuilderSink. The client and the server are actually unaware of the intermediate processing; the remote call appears no different from a local (intra-appdomain) call. This scheme forms the basis of the Aspect framework built around the ContextBoundObject. In fact, I suppose, all aspect frameworks would eventually use a realization of the Chain of Responsibility pattern. 

 

PS: It has been quite a while since I posted on patterns topic and I apologize for that.

Posted: Thu, Sep 29 2005 22:24 by Manoj G | with no comments
Filed under:
Leave a Comment

(required) 

(required) 

(optional)

(required)