0

I am developing framework for MVC application. As part of framework, I have created a dummy application. I am following Onion Architecture and SOLID principle with CQRS. This is my first project with MVC and CQRS. I am also following Chain of Responsibility in CQRS.

At present I am not sure about the part where I should keep business logic.

Example. I have Command of Debit Account from bank account. I have created command as DebitAccount and handler as IDebitAccountHandler. IDebitAccountHandler will be implemented in Infrastructure layer with required dependencies as DebitAccountHandler.

Here I have core logic of checking balance before debiting account. I would want to implement this in Core as it does not change with Infrastructure.

Now where should I implement this logic and also load required dependencies. My commands are interfaces without any method body, also they contain only on method of Handle/Execute.

I feel this is newbie question and arising due to my limited understanding of patterns.

4

1 回答 1

2

每个命令代表一个用例。命令处理程序不包含任何逻辑;它负责基础设施问题,并委托给该领域。

您希望所有逻辑都在您的域模型中:聚合、实体、值对象、服务......在您的示例中,逻辑将被Account聚合封装。

public class Account
{
    private Balance _balance;

    public void Debit(Amount amount) 
    {
        if (_balance.IsSufficient())
                // debit..
    }
}
于 2013-10-09T12:51:52.523 回答