title: Understanding the Command pattern in a DDD context
body: <p>I was recently reading this article here: <a href="https://cuttingedge.it/blogs/steven/pivot/entry.php?id=100" rel="nofollow noreferrer">https://cuttingedge.it/blogs/steven/pivot/entry.php?id=100</a>.  It appears to talk about using commands (<a href="http://www.dofactory.com/net/command-design-pattern" rel="nofollow noreferrer">http://www.dofactory.com/net/command-design-pattern</a>) instead of application services.</p>
  
  <p>Please see the code below:</p>
  
  <pre><code>public sealed class ShipmentController
  {
      private readonly ICommandDispatcher dispatcher;
  
      public void ShipOrder(ShipOrder cmd) =&gt; dispatcher.Dispatch(cmd);
  }
  
  sealed class CommandDispatcher : ICommandDispatcher
  {
      private readonly Container container;
  
      public void Dispatch(dynamic cmd) =&gt; GetHandler(cmd.GetType()).Handle(cmd);
  
      private dynamic GetHandler(Type type) =&gt;
          container.GetInstance(typeof(ICommandHandler&lt;&gt;).MakeGenericType(type));
  }
  </code></pre>
  
  <p>which replaces code like this: <a href="http://www.zankavtaskin.com/2013/11/applied-domain-driven-design-ddd-part-6.html" rel="nofollow noreferrer">http://www.zankavtaskin.com/2013/11/applied-domain-driven-design-ddd-part-6.html</a></p>
  
  <p>I have three questions:</p>
  
  <p>1) Is this saying that you should have one command per command request in the Application Service Layer? Wouldn't this result in class explosion e.g. if you have 100 commands?</p>
  
  <p>2) What do you do with CQRS queries? Do you create regular application services for these?</p>
  
  <p>3) What do you do with scenarios where you extract from the database (say an order); perform a command on the Order e.g. CalculateTax and then persist to the database? I assume the flow would be (is this right):</p>
  
  <pre><code>MVC 
  Application Service (to extract order from database)
  Command (Application Service calls CalculateTaxCommand)
  </code></pre>