ASP.NET Site Code Migration Tips
This topic provides a set of high level recommendations for migrating an existing ASP.NET site from Commerce Server 2007 to use the new Microsoft Multi-Channel Commerce Foundation. All site code that uses existing Commerce Server 2007 APIs will continue to work normally without any modifications.
Create an HttpModule
Create a HttpModule to initialize a Context object and cache it in HttpContext.Current.Items during the BeginRequest event. This object will act as a top-level wrapper for all OperationService calls. Fundamentally, all OperationService calls are split into a QueueRequest and RetrieveResponse public methods. QueueRequest returns a token to the caller. This token is provided to RetrieveResponse to get the result of the operation. This allows multiple OperationService calls to be batched together into a single MultiOperation, and also caches the responses to each Request
Create a ManagerBase base class
Create a ManagerBase base class that encapsulates CRUD operations for specific commerce entities. Simplify retrieval of relationships by requiring that derived manager classes know how to create related queries to populate relationships. This allows presentation to just request the relationship by name, rather than create the operation on its own. Keep an internal cache of Context request tokens so that multiple requests for the same entity do not result in multiple OperationService calls. Ensure that Update operations update the internal cache automatically with the updated commerce entity by using the ReturnModel, ReturnModelQueries. If requests are made to populate new relationships, ensure that the union of all requests are used to execute a new OperationSerivce query.
Create manager classes deriving from ManagerBase
Expose a simplified API for simple operation queries such as GetProduct(), QueueProductQuery(), RetrieveProductQueryResponse() so that the presentation does not need to track Context request tokens. Override methods of the ManagerBase if any entity-specific behaviors are needed. Expose manager classes as a property of the Context
Create wrapper classes for updatable commerce entities
Track properties that have changed, and only send those properties as part of the Update operation model. Track related items that are added/removed/modified, and convert the added/removed/modified items into related operations
Migrate site code and tune for performance
Trace calls in the ManagerBase that require duplicate OperationService calls. This usually occurs when calls to GetXXX() are made that request different relationships (i.e. GetProduct(…, {“ChildProducts”}), GetProduct(…, {“Variants”})). Eliminate duplicate OperationService calls by either (a) enforcing a list of require relationships on the Manager class in the page OnInit event, or (b) using QueueProductQuery with the list of required relationships early in the page lifecycle.