public Result <object> When(CreateProductCatalog cmd)
        {
            while (true)
            {
                var productCatalog = _factory.Create <ProductCatalogAggregate>(cmd.Id);

                try
                {
                    _eventStore.AppendToStream <ProductCatalogAggregate>(cmd.Id, productCatalog.Version,
                                                                         productCatalog.Changes);
                    return(new Result <object>(null, new List <Exception>()));
                }
                catch (EventStoreConcurrencyException ex)
                {
                    HandleConcurrencyException(ex, productCatalog);
                    return(new Result <object>(null, new List <Exception>()
                    {
                        ex
                    }));
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
        public CommandEvent When(CreateProductCatalog cmd)
        {
            var productCatalog = _factory.Create <ProductCatalogAggregate>(cmd.Id);

            try
            {
                _eventStore.AppendToStream <ProductCatalogAggregate>(cmd.Id, productCatalog.Version,
                                                                     productCatalog.Changes, productCatalog.DomainEvents.ToArray());

                return(new CommandEvent(OperationStatus.Success));
            }
            catch (EventStoreConcurrencyException ex)
            {
                HandleConcurrencyException(ex, productCatalog);
                return(new CommandEvent(OperationStatus.Success));
            }
            catch (Exception)
            {
                throw;
            }
        }