Service APIs Client-Service Interactions Request and Response Management Service Implementation Service Infrastructures Service Evolution

Command Invoker

Equivalent requests may be received through multiple web services with different API styles. The service owner would like to have the option of processing the request synchronously or asynchronously.
How can web services with different APIs reuse common domain logic while enabling both synchronous and asynchronous request processing?
Web services often contain logic that directs how Domain Models and database tables are used to process requests. This logic is frequently duplicated across web services. Operation Scripts can be used to alleviate duplicate code, but developers may still require a way to invoke common domain logic from multiple web services that use different Service API styles or Client/Service Interaction Styles.
Create command objects that fully encapsulate common request processing logic. Instantiate and invoke these commands from within the web service, or forward them to an asynchronous background process.
Command Invoker: Create command objects that fully encapsulate common request processing logic. Instantiate and invoke these commands from within the web service, or forward them to an asynchronous background process.
With the Command Invoker pattern, all domain logic is extracted from the web service and moved to Command objects. The code that is left over in the web service does very little. In its simplest form, the service selects, instantiates, and populates a command object with request data, then calls a method on the command to initiate request processing. The service might also instantiate a command and forward it to a background request processor (e.g. daemon, Windows service) for deferred processing. In this scenario, the background process typically invokes the command through a well-known method (e.g. Execute) on the command's interface. Another option is to simply forward the raw request to a background processor. In this case, the background process must interpret the request's meaning, select and instantiate the appropriate command, then execute the command.