How to write functionality using DDD / CQRS

前端 未结 4 1171
既然无缘
既然无缘 2020-12-17 01:58

I have a bank account domain as listed below. There can be SavingsAccount, LoanAccount, FixedAccount and so on. One user can have multiple accounts. I need to add a new fun

4条回答
  •  鱼传尺愫
    2020-12-17 02:09

    I'd rename 'AccountFactory' to AccountRepository and put an extra method in it GetAccountsForUser( int userId ) which retrieves all Accounts for a specific user.

    If AccountManipulator is a webservice, then this class will use the AccountRepository, like this:

    public class AccountManipulator
    {
    
       public void FreezeAccount( int accountNr )
       {
            var repository = new AccountRepository();
            var account = repository.GetAccount(accountNr);
            account.Freeze();
            repository.Save(account);        
       }
    
       public ICollection GetAccountsForUser( int userId )
       {
            var repository = new AccountRepository();
            return repository.GetAccountsForUser (userId);
       }
    
    }
    

提交回复
热议问题