public Task Handle(MoneyReceived message)
        {
            var balance = _database.GetAccountBalanceDto(message.Id);

            balance.Balance += message.Amount;
            _database.SaveAccountBalanceDto(balance);
            return(Task.FromResult(0));
        }
예제 #2
0
        private static void Main()
        {
            Console.WriteLine("CQRSlite Banking Account sample");

            // Infrastructure setup
            _database   = new InMemoryDatabase();
            _router     = new Router();
            _eventStore = new InMemoryEventStore(_router);

            var locator   = new ServiceLocator(_router, _eventStore, _database);
            var registrar = new RouteRegistrar(locator);

            registrar.RegisterHandlers(
                typeof(AccountCommandsHandler),
                typeof(BankAccountsListView)
                );

            // start using it
            Console.WriteLine("Create bank accounts");
            CreateAccountRequest("Frank");
            CreateAccountRequest("Peter");

            PayInRequest("Frank", 15);
            TransferRequest("Frank", "Peter", 10);
            PayOutRequest("Peter", 5);

            Console.WriteLine("First read model: List of available bank accounts");
            var list = _database.GetAccounts();

            foreach (var account in list)
            {
                var balance = _database.GetAccountBalanceDto(account.Id);
                Console.WriteLine($"Account {account.Name}: {balance.Balance}");
            }

            Console.WriteLine("Sample done.");
            Console.ReadLine();
        }