public Task <TCommandResult> Dispatch <TCommand, TCommandResult>(TCommand command) where TCommand : class where TCommandResult : class { var commandHandler = commandHandlerFactory.Create <TCommand, TCommandResult>(command); try { return(commandHandler.Handle(command)); } finally { commandHandlerFactory.Destroy(commandHandler); } }
public CommandResult <TReturn> Execute <TCommand, TReturn>(TCommand command) { ICommandHandler <TCommand, TReturn> handler = _commandHandlerFactory.Create <TCommand, TReturn>(); try { var returnValue = handler.Handle(command); return(CommandResult <TReturn> .Executed(returnValue)); } finally { _commandHandlerFactory.Destroy(handler); } }