Commerce Foundation Operation Sequence Extensibility Point
Microsoft Multi-Channel Commerce Foundation provides the following extensibility options:
To extend the Microsoft Multi-Channel Commerce Foundation operations you can implement one or more operation sequence components and register them in the corresponding operation configuration section.
To replace an operation implementation provided by the Microsoft Multi-Channel Commerce Foundation you can remove the Microsoft Multi-Channel Commerce Foundation operation component registration from the corresponding configuration section and replace it with information that references your own implementation.
To introduce a new operation into Microsoft Multi-Channel Commerce Foundation you can create a new operation section in the configuration file that maps to the combination of the Request and Model types that represent this operation and within the newly created section specify the appropriate operation components.
To extend the behavior of an existing Microsoft Multi-Channel Commerce Foundation operation sequence component, you can create a new class that derives from an existing operation sequence component class. Commerce Server 2009 providers expose the IOperationSequenceComponent.Execute() method as virtual. Behaviors are extended by overriding the Execute() method of the base class.
Details of a particular implementation are specific to each individual Microsoft Multi-Channel Commerce Foundation operation. Here are a few recommendations for custom component design.
Creating New Operation Sequence Components
Developers can create new operation sequence components either by:
Implementing the public IOperationSequenceComponent interface
Deriving from the public OperationSequenceComponent class
When developers use the IOperationSequenceComponent interface, the operation parameter and response types will need casted to the proper operation and response type. The following is an example of a component that is used during a QueryOperation.
public class MyOperationSequenceComponent : IOperationSequenceComponent
{
public void Execute(
Microsoft.Commerce.Contracts.Messages.Operation operation,
OperationCacheDictionary operationCache,
Microsoft.Commerce.Contracts.Messages.OperationResponse response)
{
if ( operation is QueryOperation )
{
// Do something...
}
}
}
The alternative is to derive from the OperationSequenceComponent class.
This class exposes strongly type overrides that can be used. Also, the base class provides all of the input parameter checks and tracing needed to be implemented by all components. The following re-implements the previous component using the OperationSequenceComponent base class.
public class MyOperationSequenceComponent : OperationSequenceComponent
{
public override void ExecuteQuery(
CommerceQueryOperation queryOperation,
OperationCacheDictionary operationCache,
CommerceQueryOperationResponse response)
{
// Do Something
}
}
This approach also exposes a virtual Execute method providing accesses to the generic IOperationSequenceComponent interface implementation if needed (you would use this if you were implementing a new operation).
public class MyOperationSequenceComponent : OperationSequenceComponent
{
public override void Execute(
CommerceOperation operation,
OperationCacheDictionary operationCache,
CommerceOperationResponse response)
{
base.Execute(operation, operationCache, response);
}
}
Verify an Action Is Being Performed
Each operation request instantiates and invokes all associated operation components. For performance reasons each component should examine the Request object early in its execution; if there is no relevant action for this specific request then it should return immediately.
The following code snippet demonstrates this approach in a hypothetical implementation of a Product Query dynamic cross-sell operation sequence component. The Execute method of this class first checks whether a cross-sell has been requested; if not, the method returns immediately.
public class DynamicCrossSellLoader : OperationSequenceComponent
{
public override void ExecuteQuery(
CommerceQueryOperation queryOperation,
OperationCacheDictionary operationCache,
CommerceQueryOperationResponse response)
{
List<CommerceRelatedOperation> queryCrossSellRelatedItems =
queryOperation.RelatedOperations.GetRelatedOperations<CommerceQueryRelatedItem>(CrossSells);
if (queryCrossSellRelatedItems == null || queryCrossSellRelatedItems.Count == 0)
{
return;
}
// The rest of the method implementation follows...
}
}
See Also
Other Resources
Commerce Foundation Operation Sequences
Commerce Foundation Request and Response Extensibility Point