Skip to content

Requests and Commands

As discussed previously, Requests and Commands are messages that ask for something to be done or tell the system to do something.

Requests

A Request is a message that asks for something to be returned. A request is analogous to the “GET” method in HTTP/REST or a method that does not return void. When you send a request to Greyhound, it will return a Response<T> where T is the expected result type, defined by the generic parameter of the request type.

Commands

A Command is a message that tells the system to do something. A command is analogous to “POST”, “PUT”, or “DELETE” in HTTP/REST or a method that returns void. When you send a command to Greyhound, it will return a non-generic Response.

Create a Request or Command

To create a request type, create a public record which inherits from UserRequest<T> where T is the expected result type.

To create a command type, create a public record which inherits from UserCommand.

The record’s properties should be the parameters needed to fulfill the request or command. Additionally, as the last required parameter, include an IPrincipal RequestedBy property. This will be given to the UserRequest<T> or UserCommand constructor and is required. It is important for security and auditing, so it should be included in all requests and commands. By convention, this parameter should always be the last required parameter, but optional parameters can follow it.

The name of the request or command should typically start with a verb, then a noun, and end with the word “Request” or “Command”, e.g. GetEmployeeRequest or MergeLocationsCommand. You are requesting something from the application or commanding the system to perform an action.

Examples