How to pass the data between sequence components

The message handler consists of one or more sequence components. Very often there is a need to pass some data to the next component in a sequence.

In each sequence component (derived from OperationSequenceComponent class) in one of overriden methods ( ExecuteQuery, for instance) we have CommerceOperationDictionary class as parameter. It is string-object dictionary that is used to store any data within the executing message handler scope.

To learn more refer to the MSDN link

Sample use case: Reading data from several config sections in sequence.

We have two sequence components:

1. CustomConfigDataLoader : OperationSequenceComponent

public class CustomConfigDataLoader: OperationSequenceComponent
{
public override ExecuteQuery(
	CommerceQueryOperation queryOperation,
	OperationCacheDictionary operationCache,
	CommerceQueryOperationResponse response)
	{
		// do some stuff of configuration loading
		// as an example, get the profile web service url and put it into cache
		operationCache.Add("profileWebServiceUrl", profileWebServiceUrl);
	}
}

then in UserProfileSearcher class we retrieve the url from the cache:

public override ExecuteQuery(CommerceQueryOperation queryOperation, OperationCacheDictionary operationCache, CommerceQueryOperationResponse response)
{
object obj;
string profileWebServiceUrl = String.Empty;
if (operationCache.TryGetValue("profileWebService", out obj))
{
profileWebServiceUrl = obj as string;
}
var context = ProfileManagementContext.Create(profileWebServiceUrl);
//... do some stuff with profiles data
}
}

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.