title: Reuse command for object in a command for a collection of objects
body: <p>I have a CommandHandler that implements some logic for an object and commits context (in my case RavenDb IDocumentSession). I need to implement the same logic for a collection of objects. The first idea is to create a new CommandHandler which would call the first CommandHandler for each object in the foreach. But it would result in N database roundtrips.  </p>
  
  <p>The best idea I came to was to create a base CommandHandler with the logic itself but without context commit. Something like this:</p>
  
  <pre><code>internal class AuditProductCommandHandler : AuditProductCommandHandlerBase, ICommandHandler&lt;AuditProductCommand&gt;
  {
      private readonly IDocumentSession _documentSession;
  
      public AuditProductCommandHandler(IDocumentSession documentSession)
      {
          _documentSession = documentSession;
      }
  
      public void Execute(AuditProductCommand command)
      {
          AuditProduct(command.Product);
  
          _documentSession.SaveChanges();
      }
  }
  
  internal class AuditProductsCommandHandler : AuditProductCommandHandlerBase, ICommandHandler&lt;AuditProductsCommand&gt;
  {
      private readonly IDocumentSession _documentSession;
  
      public AuditProductsCommandHandler(IDocumentSession documentSession)
      {
          _documentSession = documentSession;
      }
  
      public void Execute(AuditProductsCommand command)
      {
          foreach (var product in command.Products)
          {
              AuditProduct(product);
          }
  
          _documentSession.SaveChanges();
      }
  }
  
  internal class AuditProductCommandHandlerBase
  {
      protected void AuditProduct(Product product)
      {
        //logic itself 
      }
  }
  </code></pre>
  
  <p>For some reason I feel uncomfortable about this solution. Are there any better options?</p>