1

I have a personal finance 3-layer application setup as: UI, BLL, and DAL. My domain looks like:

// Write Model
public class Account
{
    public Account(AccountId id)
    {
        _id = id;
    }

    public AddSubAccount(Account account)
    {
        // add subaccount to this account
    }

    // more business logic methods for accounts

    private AccountId _id;
    private List<Account> _subAccounts = new List<Account>();
}

// Read Model
public class AccountDTO
{
    public AccountDTO(AccountId id, IEnumerable<AccountDTO> subAccounts, decimal balance)
    {
        Id = id;
        SubAccounts = subAccounts;
        Balance = balance;
    }

    public AccountId Id { get; }
    public IEnumerable<AccountDTO> SubAccounts;
    public decimal Balance { get; }
}

Then I have an IAccountRepository that handles retrieving AccountDTO and saving/deleting Account.

The client then uses this like:

// client -- view all accounts
var accounts = accountRepo.GetAllAccounts();

// client -- remove
var account = accountRepo.GetById(accountId);
accountRepo.Remove(account.Id);

// client -- add subaccount
var parentAccount = new Account(parentAccountId);
var subAccount = new Account(subAccountId);
parentAccount.AddSubAccount(subAccount);
accountRepo.Update(parentAccount);

The issue is, some of my accounts are investment accounts and I want them to be calculated (daily, weekly, yearly) to reflect an accurate portfolio value. Therefore, instead of just returning an AccountDTO with the balance of the transaction contributions, I need to use the daily quotes for a portfolio of funds to then compute what the balance on the account should be.

I've read that the write model should handle this logic so the query/read model is fast. However, I'm not sure where to store this data. Would it make sense to cache this in the database? I've read this is bad unless you have millions of rows.

Or, should I just save the contributions/transactions and daily quotes in the database and then re-calculate this every-time? If I go with this route, I would assume I need a domain service in-between the repository and client?

  • Down-voter care to comment? – keelerjr12 Oct 5 '18 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.