-1

Let's say I have a task management application that uses the CQRS paradigm. How would I apply it to the following:

Scenario: As a user I want to create a task.

Java Pseudo Code:

interface Command {}
class CreateTaskCommand implements Command {
    public String taskId;
    public String description;
    public boolean complete;
}

interface CommandHandler<Command> {
    public void execute(Command command);
}
class CreateTaskHandler implements CommandHandler<CreateTaskCommand> {
    public void execute(CreateTaskCommand cmd) {
        validateTask(cmd);
        repository.storeTask(new Task(cmd.taskId, cmd.description, cmd.complete));
    }
}

Given the above code, where does the Event, EventHandler and Aggregate Root come into play (how would I proceed for the given story)?

Thanks for your help.

4

1 回答 1

2

命令处理程序通常将行为委托给它与存储库一起加载的聚合根。反过来,聚合根会引发事件以响应调用的操作,例如TaskCreatedEvent. 有各种风格的事件处理程序。您可以拥有一个事件处理程序,其唯一工作是将已发布的事件分派到外部系统。外部系统将使用事件处理程序订阅已发布的事件,该事件处理程序通常会调用命令以响应事件。事件处理程序还可用于调用附加域逻辑以响应本地上下文中的事件。

于 2013-07-04T20:47:02.977 回答