Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 0.58 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class InvokeCommandAction<TEntity, TCommand>
  2.         where TEntity : IAggregate
  3.         where TCommand : class, ICommand<TEntity>
  4. {
  5.         private readonly ICommandInvoker _invoker;
  6.  
  7.         public InvokeCommandAction(ICommandInvoker invoker)
  8.         {
  9.                 _invoker = invoker;
  10.         }
  11.  
  12.         public CommandResult<TEntity> Execute(TCommand command)
  13.         {
  14.                 var result = new CommandResult<TEntity>
  15.                                                  {
  16.                                                          AggregateId = command.Id,
  17.                                                          Success = true
  18.                                                  };
  19.                 try
  20.                 {
  21.                         _invoker.Invoke(command);
  22.                 }
  23.                 catch (Exception exc)
  24.                 {
  25.                         result.Success = false;
  26.                         result.RegisterError(exc.Message);
  27.                 }
  28.                
  29.                 return result;
  30.         }
  31. }