Skip to content

Command

Duncan Jones edited this page Aug 1, 2021 · 8 revisions

Command

The Command class is part of the CQRS Support in this event sourcing library. It allows for the creation of a special event stream backed entity which represents a command which is then used to track the progress of that command.

You can instantiate a command in an Azure function via a bound parameter using the Command Attribute

        /// <summary>
        /// Apply accrued interest to an account
        /// </summary>
        /// <param name="accountnumber">
        /// The account number to use for the account to have any accrued interest applied.
        /// </param>
        /// <param name="cmdApplyAccruedInterest">
        /// The command orchestration that will perform the steps in turn
        /// </param>
        /// <remarks>
        /// This is a multi-step command, first -if needed- extend an overdraft to cover the 
        /// accrued interest then apply the interest itself
        /// </remarks>
        [FunctionName(nameof(ApplyAccruedInterestCommand))]
        public static async Task<HttpResponseMessage> ApplyAccruedInterestCommand(
                      [HttpTrigger(AuthorizationLevel.Function, "POST", Route = @"ApplyAccruedInterest/{accountnumber}")]HttpRequestMessage req,
                      string accountnumber,
                      [Command("Bank", "Apply Accrued Interest")] Command cmdApplyAccruedInterest)
        {

            // - - - - 8< - - - - - - - - 

Events

The events in the execution history of a command are:-

  • Created - This occurs when a new command instance is created
  • Parameter Value Set - A parameter that will be used in the execution of the command has been set or changed.
  • Fatal error occurred - An error has happened that prevents the command completing.
  • Command Step Initiated - A particular named step in processing the command has initiated.
  • Command Step Completed - A named step in the command orchestration has completed.
  • Completed - The command orchestration is complete.

In addition the command can have the following events relating to projection and classification execution that have happened on behalf of that command :-

  • Projection Requested - The command requested a projection to be run
  • Projection Value Returned - The projection completed and results were made available to the command
  • Classification Requested - The command requested a classification of an entity
  • Classification Result Returned - The classifier was run over the requested entity event stream

Projections

The built-in projections that can run over a command's event stream are:-

  • Parameter Values - Returns the set of parameters set for this command execution (as name-value pairs)
  • Execution State - Returns the current execution state of the command.

Classifications

The built-in classifications that can run over a command's event stream are:-

  • Command Completed - Has the command successfully completed its execution
  • Command In Error - Has the command been halted because it encountered a fatal error