Greg Young的CQRS实施中的服务目的

发布于 2024-12-05 06:57:28 字数 466 浏览 1 评论 0原文

我决定通过 Greg Young 的实现

我不明白这里的服务是什么意思,因为它似乎与我们过去常见的三层模式完全不同。

客户端更改接收到的 DTO,并创建一个由其处理程序处理的命令,该处理程序调用域对象的方法。

然后创建事件并将其存储在事件存储中并发布以同步去规范化部分。

我在该链中找不到该服务。

我的同事告诉我,例如,如果我们在存储报告时不想将大数据存储为域的一部分,但当我们在域中需要它时,我们会发布一个从服务返回某些内容的事件。

但我无法在脑海中清晰地形成画面。

谁能解释一下这里应该做什么服务?

I decided to get acquainted with a concrete CQRS implementation on the example of Greg Young's implementation

What I do not understand is what is the meaning of services here because it seems to be completely other than we used to in common three-tier pattern.

The client changes the received DTO and it creates a command which is handled by its handler which calls a method of a domain object.

Then the event is created and stored in the event store and published to syncronise the denormolized part.

I cannot find the service in this chain.

My co-worker told me that for example that if we do not want to store large data as part of a domain when we store in reports but when we need it in our domain we publish an event which returns something from the service.

But I cannot clearly form the picture in my mind.

Can anyone explain what services are supposed to do here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

许一世地老天荒 2024-12-12 06:57:28

在CQR中,基本上,命令处理程序是您在非CQRS方案中称为应用程序服务的内容。

In CQRS, basically the command handlers are what you'd call application services in non-CQRS scenarios.

故事还在继续 2024-12-12 06:57:28

根据您所讨论的上下文,“服务”可以代表不同的事物。阅读这篇文章,我相信他在 域服务,其中 构成 DDD 的构建块

但是,在 CQRS 中,您通常拥有命令服务查询服务,它们在 DDD 上下文中代表应用服务层。但正如我在阅读这篇文章时所说的那样,我认为他使用“服务”一词是指领域服务。

'Services' can represent different things depending on the context you are talking about. Reading the article I believe he is using the term 'service' in the context of Domain Services which form the building blocks of DDD.

However, in CQRS you typically have a command service and query service, which in DDD context represent the Application Service Layer. But as I say, reading the article, I think his use of the word 'service' is meant for domain services.

仙女 2024-12-12 06:57:28

当您遇到诸如设置一致性验证之类的问题时。例如:设置验证帖子您可以需要一个服务来确保拒绝传入的重复命令,该命令的值只应保留一次。
在这种情况下,服务基本上是在具有主键约束的 Sql 表中进行插入。它只会发生一次,否则会抛出错误,整个过程失败,不会生成任何事件,查询端不会报告。
只是一个案例。

When you have problems like Set Consistency Validation. For example: Set Validation Post in SO you may need a Service that ensures that incoming duplicate commands of a value that should only be persisted once are rejected.
In this case, a service basically does an insert in a Sql table with a primary key constraint. It only happens once, otherwise, throws an error and the whole process fails and no events are generated, no reporting in the query side.
Just a case.

心房的律动 2024-12-12 06:57:28

您的意思是服务是一个远程外观(Web 服务),它将调用应用程序层,因为域服务是不同的东西。

如果您正在设计n层应用程序以向其他层公开应用程序服务,则远程外观层(Web服务)将通过调用应用程序层来公开您的业务和命令,应用程序层如David所提到的:

对于阅读部分,在您的应用程序中您需要使用 FindOrders(x, y, z)、GetMostOrderedItems() 等方法设计一个查询服务,...

对于 Write 部分,您可以设计指挥服务之一类似的方式:

  • 接受 DTO 并基于它执行域逻辑的服务 [Least CQRS]:
public void ActivateOrder(int orderID)
{
    var order = _orderRepository.FindOrder(orderID);
    order.Activate();
}

public void UpdateClientAddress(ClientAddressDTO address)
{
    var client = _clientRepository.FindClient(address.ClientID);
    client.Address = // .. map ClientAddressDTO to Address
}
  • 接受 DTO 并将其转换为要在域模型上执行的命令的服务:
public void ActivateOrder(int orderID)
{
    var orderActivationCommand = new OrderActivationCommand(orderID);
    _commandExecuter.Execute(orderActivationCommand);
}

public void UpdateClientAddress(ClientAddressDTO address)
{
    var clientMovingCommand = new clientMovingCommand(address.ClientID, address.PostalCode, ...);
    _commandExecuter.Execute(clientMovingCommand);
}
  • 接受 Command 对象(而不是 DTO)并执行的通用服务它:
// ... in remote facade or client code ...

var orderActivationCommand = new OrderActivationCommand(orderID);
_commandService.ExecuteCommand(orderActivationCommand);

// ... in application layer (service) ...

public void ExecuteCommand(Command command)
{
    _commandExeuter.Execute(command);
}

You mean about service a remote facade (Web service) which will call application layer, because domain service is a different thing.

The remote facade layer (web service) if you are designing n-tier application to expose application services to other tiers will expose your business and commands by calling the application layer, the application layer as mentioned by David:

For Read Part, in your application layer you need to design a Query Service with methods like FindOrders(x, y, z), GetMostOrderedItems(), ...

For the Write part, you can design the command service in one of many ways like:

  • Service which takes DTOs and execute domain logic based on it [Least CQRS]:
public void ActivateOrder(int orderID)
{
    var order = _orderRepository.FindOrder(orderID);
    order.Activate();
}

public void UpdateClientAddress(ClientAddressDTO address)
{
    var client = _clientRepository.FindClient(address.ClientID);
    client.Address = // .. map ClientAddressDTO to Address
}
  • Service which takes DTOs and convert it to a Command to be executed on domain model:
public void ActivateOrder(int orderID)
{
    var orderActivationCommand = new OrderActivationCommand(orderID);
    _commandExecuter.Execute(orderActivationCommand);
}

public void UpdateClientAddress(ClientAddressDTO address)
{
    var clientMovingCommand = new clientMovingCommand(address.ClientID, address.PostalCode, ...);
    _commandExecuter.Execute(clientMovingCommand);
}
  • Generic Service which takes a Command object (instead of DTO) and execute it:
// ... in remote facade or client code ...

var orderActivationCommand = new OrderActivationCommand(orderID);
_commandService.ExecuteCommand(orderActivationCommand);

// ... in application layer (service) ...

public void ExecuteCommand(Command command)
{
    _commandExeuter.Execute(command);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文