Beispiel #1
0
        public async Task Process(RegisterInput message)
        {
            Customer customer = new Customer(message.PIN, message.Name);

            Account account = new Account();

            account.Open(customer.Id, new Credit(account.Id, message.InitialAmount));
            customer.Register(account.Id);

            var customerEvents = customer.GetEvents();
            var accountEvents  = account.GetEvents();

            await bus.Publish(customerEvents);

            await bus.Publish(accountEvents);

            //
            // To ensure the Customer and Account are created in the database
            // we wait for the records be available in the following queries
            // with retry
            //

            bool consumerReady = await RetryGet(async() => await customerReadOnlyRepository.Get(customer.Id)) &&
                                 await RetryGet(async() => await accountReadOnlyRepository.Get(account.Id));

            if (!consumerReady)
            {
                customer = null;
                account  = null;

                //
                // TODO: Throw exception, monitor the inconsistencies and fail fast.
                //
            }

            CustomerOutput customerOutput = responseConverter.Map <CustomerOutput>(customer);
            AccountOutput  accountOutput  = responseConverter.Map <AccountOutput>(account);
            RegisterOutput output         = new RegisterOutput(customerOutput, accountOutput);

            outputBoundary.Populate(output);
        }
        public async Task Process(RegisterInput input)
        {
            Customer customer = new Customer(input.PIN, input.Name);

            Account account = new Account(customer.Id);
            Credit  credit  = new Credit(account.Id, input.InitialAmount);

            account.Deposit(credit);

            customer.Register(account.Id);

            await customerWriteOnlyRepository.Add(customer);

            await accountWriteOnlyRepository.Add(account, credit);

            CustomerOutput customerOutput = outputConverter.Map <CustomerOutput>(customer);
            AccountOutput  accountOutput  = outputConverter.Map <AccountOutput>(account);
            RegisterOutput output         = new RegisterOutput(customerOutput, accountOutput);

            outputBoundary.Populate(output);
        }