问题标签 [domain-events]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
147 浏览

domain-driven-design - 将引用的聚合根转换为另一个聚合根

我的系统有“联系人”的语言,这是一种“幽灵用户”,我们有一些信息——它的验证规则很薄,它的状态主要是联系信息。我们还有一个“用户”的概念,它是经过全面审查和注册的用户。将“用户”视为充实的“联系人”。

我们试图捕捉的生命周期是,一旦有人使用“联系人”的信息注册,“联系人”将被“用户”替换。

我们在系统中有其他聚合根,它们引用指向“Contact”的 UUID 的“ContactId”。当“联系人”注册时,我们想使用“用户”的新概念在域中表示他们,“用户”现在拥有自己的“用户 ID”UUID。

  1. 我们如何保持仍然通过 ContactID 引用“Contact”的关系,现在通过 UserID 引用“User”?
  2. 尝试将我的聚合转换为另一个聚合是否存在根本问题?
  3. 如果是这样,我应该如何为“联系人”->“注册用户”的这个特定生命周期建模?
  4. 如果答案是将这两个想法合并到一个聚合根中,我如何才能让我的域对象始终有效,尽管在此“联系人”实际注册之前“用户”无效?

附带说明一下,我们将 CQRS/ES 用于整体架构。

谢谢!

0 投票
1 回答
90 浏览

c# - 用于确认状态的领域事件

我有一个关于领域事件的问题。我正在使用 DDD 实现一个应用程序,是的,该应用程序对于 DDD 来说足够复杂。

我的场景是一个登录 Wcf 服务,除了验证用户凭据并返回一个令牌之外,该服务还需要创建一个会话并审核登录。为此,我为会话和审计创建了两个单独的域上下文,因为它们超出了登录的范围.

问题是,Wcf 实现的一部分位于 SharedKernel 中,这是所有 Wcf 服务处理令牌的令牌验证的要求,该令牌需要从客户端传递给 Wcf 服务以确保安全。令牌的验证需要检查是否存在有效的会话(例如,数据库中有一条具有相同令牌且未过期的记录),我正在努力解决如何最好地实现这一点并有一些想法

  1. 我相信,由于 Session 在它自己的有界上下文中,我应该引发一个返回结果的同步域事件,毕竟我只需要一个 true/false 来确认令牌的有效会话
  2. 或者; 我可以在共享内核中为此实现一个域上下文来处理这个问题,但这意味着在共享内核中拥有域实体和 EF 上下文,并且可能在会话的有界上下文之外。

我真的很纠结哪种方法是最好的,有没有人遇到过类似的事情,你对用最佳实践来实现这个有什么建议?领域事件是我需要实现的正确方法吗?

0 投票
1 回答
586 浏览

domain-driven-design - DDD: Domain Events implementation in monolithic application

I've made some small research about Domain Events, and have found few different solutions

  • Udi Dahan solution, which handle events immediately
  • Deferred domain events, which fire off in infrastructure mostly
  • Domain Events which return result

Questions:

  • Which one is a pure Domain Events ?
  • Is it possible to have them all in the same project ?
  • In that case how should I name and distinguish them ?
  • Where to register EventHandler ? Someone mentioned that Application Service is appropriated place, but here I've seen that it was registered right into the Domain Model, and handled there, as well, and not in separate Event handler class.

One more extra question.

For example: When order is created and paid it has to get status "OrderPaid".

Because purchasing and ordering are two different contexts, right after Order was created we need to rise a Domain Event, which should be handled by Event Handler in Purchasing bounded context, but in result of Event Handling, there should be raised one more Domain Event - OrderPaid, which might be handled by Order context again. With monolith application it seems that one solution might be: pass Order object into Event Handlers to achieve expected behavior. Is there any other ways how to solve it, in such architecture style ?

0 投票
2 回答
2583 浏览

domain-driven-design - 消息总线服务在领域驱动设计中的位置

我正在努力加深对 DDD 的理解。更具体地说,如何通过消息总线处理域事件以进行异步处理。

可以说我有一些架构->

当我的域引发一些域事件时,如何将该事件发送到 RabbitMQ 等消息传递服务?

我的第一个想法是注入一个消息总线服务 IMessageBus,它知道如何将事件发送到 RabbitMQ。域事件处理程序将使用该服务将事件分派到总线。

但后来我想,现在我的域必须知道如何处理自己的事件。

有人可以对此事有所了解吗?

0 投票
1 回答
1362 浏览

json - Domain event storage in SQL... use JSON serialization?

I'm looking at refactoring an existing code-base before we let it loose in the wild with our first customer, and I really don't like the current domain event storage structure and I was trying to come up with a good way to store the many & very different events in RDB tables.

Architecture:

  • Web app
  • Java
  • Spring 4
  • Spring JDBC
  • MSSQL

Details:

  • 40+- different events, each related to either the aggregate root or one of it's child elements.
  • Details of the event are stored, but not the object state (so no CQRS event sourcing)
  • Events are ONLY used for reports
  • Reports are fed with java objects. IE. the reports do NOT run directly off of SQL.

Currently the events are stored in a single event table per bounded context. In order to hold all the different event types & data the table schema looks like this

...repeat like 10x...

so, for example(order=aggregate root, item=child of order):

No I don't like it, and no I was not responsible for doing that.

Issues:

  • context_1_xxx fields are fragile and difficult to maintain/troubleshoot/expand
  • Everything stuffed into one table will be a performance problem(even though reporting is not performance sensitive)
  • Events are linked to the domain object; they don't store the state of the object. eg. the recorded event is useless if the item is deleted

My gut tells me creating 40 different tables with schema unique to each event is not the answer. Instead I was thinking of serializing(JSON) a snapshot of the domain object(s) to be saved along with the event data.
It seems convenient solution:

  • we already use a Spring/Jackson module to serialize objects for the browser-based clients.
  • the team is pretty comfortable with the serialize/deserialize process so there is no major learning curve.
  • the event data must go back through the application for generating reports which will be easy enough by de-serializing with Jackson

The only real downsides I can see are: - unable to use SQL based 3rd party reporting tools - unable to index the tables on the properties of the stored object(JSON)

I can somewhat mitigate issue#2 by further breaking down the event storage into a few different tables.

What else am I missing? Is there an established best-approach to accomplishing this? How do you do it?

0 投票
1 回答
490 浏览

domain-driven-design - 在哪里订阅域事件

在我的应用程序服务中,我有以下用于发布域事件的代码:

我正在尝试决定我是否喜欢在应用服务中拥有发布事件的这种知识,或者我是否应该将其外部化到根目录更高的某个地方。

想法?

0 投票
1 回答
211 浏览

domain-driven-design - DDD: Applying Event Store in a legacy system

Our current system is a legacy system which doesn't use domain events. We are going to start publishing domain events. Other bounded contexts are going to listen to these domain events, but only from the time we start publishing, losing all the past information.

Then, how to deal with this legacy system which didn't record these events, but somehow we want to have a past history before the implementation of this event store system?

Is it a good approach trying to figure out what happened and try to create the domain events (reverse engineering) according to the data we have in our DB?

0 投票
1 回答
797 浏览

php - PHP中的DDD -> DomainEventPublisher -> 在哪里使用订阅方法?

流量:

CreateNewTaskRequest -> CreateNewTaskService -> Task::writeFromNew() -> NewTaskWasCreated(domain event) -> DomainEventPublisher 调用订阅者的句柄。

按照上面的流程,我想知道您在哪里添加域事件的订阅者?

我目前正在阅读这本书DDD in PHP,但我无法掌握应该在哪里完成?

这是我的代码,但我觉得不对

任务扩展聚合根:

0 投票
1 回答
701 浏览

php - PHP中的DDD->投影仪->应该在何时何地调用投影仪的注册方法?

我目前正在阅读DDD in PHP一书中的投影,我很困惑何时何地从投影仪类调用 register 方法。

流程: CreateNewTaskRequest -> CreateNewTaskService -> Task::writeFromNew() -> PDOTaskRepository。

在 PDOTaskRepository 的 save 方法结束时,会调用投影仪的 project 方法,然后调用所有已注册的正在侦听给定域事件的投影的 project 方法。

但是,我应该在何时何地将投影注册到投影仪?

0 投票
1 回答
2121 浏览

c# - ASP.NET Web API 的域驱动设计(域事件)

为 Web API 项目实现 DDD/CQRS 的最佳方法是什么,因为我仍然不太了解从 Web API 调用其他服务时如何获得响应。我阅读了有关 Rx observable 的内容,但我想要一个更清晰的解释和简单的示例链接会很棒。我在 ASP.NET Web API 和 Autofac 中使用 Udi Dahan 样式的域事件进行注入。这是我尝试在 Controller 的 Web API 中使用域事件的方法。我所做的代码都在工作。

这引发了事件处理程序:

当然,HelloMessage 事件名称应该使用通用语言,这样会更合适。这只是一个简单的示例,这很容易。

现在,我想调用另一个,比如说第三部分 Web API 服务,它需要相当长的时间来响应。以及如何检索响应并返回到 MyApiController。根据 Udi Dahan 的说法,直接在处理程序中使用这不是一个好主意。例如:

我的问题是:

  1. 我如何以简单和更好的方式做到这一点?
  2. 如何在域被提升后从第 3 方 Web API 检索响应到 MyApiController?
  3. 为 Web API 项目实施 DDD 的最佳方法是什么?

提前致谢。