Jaa


Commerce Foundation Operation Sequence Extensibility Point

Microsoft Multi-Channel Commerce Foundation provides the following extensibility options:

  1. 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.

  2. 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.

  3. 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.

  4. 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:

  1. Implementing the public IOperationSequenceComponent interface

  2. 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.

Dd464335.11c2a851-81ca-4f36-af70-14b336996407(en-US,CS.90).gif

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

Extending Commerce Foundation

Commerce Foundation Request and Response Extensibility Point

Commerce Foundation Commerce Entity Extensibility Point

Commerce Foundation Metadata Extensibility Point