function CommandStack(eventBus, injector) {

  /**
   * A map of all registered command handlers.
   *
   * @type {CommandHandlerMap}
   */
  this._handlerMap = {};

  /**
   * A stack containing all re/undoable actions on the diagram
   *
   * @type {CommandStackAction[]}
   */
  this._stack = [];

  /**
   * The current index on the stack
   *
   * @type {number}
   */
  this._stackIdx = -1;

  /**
   * Current active commandStack execution
   *
   * @type {CurrentExecution}
   */
  this._currentExecution = {
    actions: [],
    dirty: [],
    trigger: null
  };

  /**
   * @type {Injector}
   */
  this._injector = injector;

  /**
   * @type EventBus
   */
  this._eventBus = eventBus;

  /**
   * @type { number }
   */
  this._uid = 1;

  eventBus.on([
    'diagram.destroy',
    'diagram.clear'
  ], function() {
    this.clear(false);
  }, this);
}
A service that offers un- and redoable execution of commands.

The command stack is responsible for executing modeling actions
in a un- and redoable manner. To do this it delegates the actual
command execution to {@link CommandHandler}s.

Command handlers provide {@link CommandHandler#execute(ctx)} and
{@link CommandHandler#revert(ctx)} methods to un- and redo a command
identified by a command context.


## Life-Cycle events

In the process the command stack fires a number of life-cycle events
that other components to participate in the command execution.

   * preExecute
   * preExecuted
   * execute
   * executed
   * postExecute
   * postExecuted
   * revert
   * reverted

A special event is used for validating, whether a command can be
performed prior to its execution.

   * canExecute

Each of the events is fired as `commandStack.{eventName}` and
`commandStack.{commandName}.{eventName}`, respectively. This gives
components fine grained control on where to hook into.

The event object fired transports `command`, the name of the
command and `context`, the command context.


## Creating Command Handlers

Command handlers should provide the {@link CommandHandler#execute(ctx)}
and {@link CommandHandler#revert(ctx)} methods to implement
redoing and undoing of a command.

A command handler _must_ ensure undo is performed properly in order
not to break the undo chain. It must also return the shapes that
got changed during the `execute` and `revert` operations.

Command handlers may execute other modeling operations (and thus
commands) in their `preExecute(d)` and `postExecute(d)` phases. The command
stack will properly group all commands together into a logical unit
that may be re- and undone atomically.

Command handlers must not execute other commands from within their
core implementation (`execute`, `revert`).


## Change Tracking

During the execution of the CommandStack it will keep track of all
elements that have been touched during the command's execution.

At the end of the CommandStack execution it will notify interested
components via an 'elements.changed' event with all the dirty
elements.

The event can be picked up by components that are interested in the fact
that elements have been changed. One use case for this is updating
their graphical representation after moving / resizing or deletion.

@see CommandHandler

@param {EventBus} eventBus
@param {Injector} injector