/// <summary> /// Establishes a command context. /// </summary> /// <param name="command">The command.</param> /// <param name="clock">The clock used by the command and any events that result.</param> public static CommandContext Establish(ICommand command, IClock clock = null) { var current = Current; if (current == null) { current = new CommandContext { // override the domain clock if a clock is provided Clock = clock ?? Domain.Clock.Current }; CallContext.LogicalSetData(callContextKey, current.Id); contexts.GetOrAdd(current.Id, current); } else { current.Clock = Domain.Clock.Latest( clock, current.Clock); } current.commandStack.Push(new CommandStackFrame { Command = command, Clock = current.Clock }); return current; }