@Service 注入聚合?

@Service injection into aggregates?

我有一个 Order 集合,其中包含以下命令:

PlaceOrderCommand是指将Order放置到外部执行场所。我已经捕获了在单独的(非 CQRS)@Service 中向外部执行场所下订单的行为。然而,我正在努力(由于缺乏使用 Axon 的经验)如何最好地将我的 @Service 与聚合连接起来。

我的正常思维方式应该是:

我的问题是:

我可能考虑的另一件事是:

能否就此场景建模的最佳实践提出建议?

The PlaceOrderCommand refers to placing the Order onto an external execution venue.

我假设将订单下达到外部执行场所意味着与外部系统进行交互。如果是,那么它不应该是您域的一部分。在这种情况下,您需要提出 Integration Event.

如您所述,您可以从您的域中提出 Command 之类的 ProcessOrder。在那个 Command 中,您可以更新 Domain(例如,将 OrderStatus 设置为 Processing)并引发一个集成事件,例如 OrderArrived,然后由一个单独的过程。

来自 Microsoft Docs:

The purpose of integration events is to propagate committed transactions and updates to additional subsystems, whether they are other microservices, Bounded Contexts or even external applications.

Integration events must be based on asynchronous communication between multiple microservices (other Bounded Contexts) or even external systems/applications.

您可以将集成事件作为 Domain 之外的单独进程(或工作程序)来处理。这是你的@Service 将被注入的地方。成功处理订单后,您可以广播名为 OrderPlaced.

的集成事件

现在,任何与下订单有关的订阅者都将订阅该事件。在您的情况下,您的 Domain 有兴趣在下订单后更新状态。因此,您会在 DomainSubscribeOrderPlaced 事件来更新 Order.

的状态

希望对您有所帮助。