Getting Started with the Foundation API

This topic provides a set of high level recommendations for working with the Microsoft Commerce Server 2009 R2 Foundation API. Any site code that makes calls to the Commerce Server 2007 API will continue to work normally without any modifications, but will not be able to take advantage of Commerce Server 2009 R2 functionality.

For detailed information about developing with the Commerce Server Foundation API, see Developing with the Multi-Channel Commerce Foundation.

This topic contains the following sub-sections:

  • Create an HttpModule

  • Create a ManagerBase Base Class

  • Create Manager Classes Deriving from ManagerBase

  • Create Wrapper Classes for Updatable Commerce Entities

  • Migrate Site Code and Tune for Performance

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 (Create, Update, Delete and Query) 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 required 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.