流程创建新订单输入 DDD 方式

发布于 2024-10-11 16:53:20 字数 390 浏览 7 评论 0原文

我是第一次探索领域驱动设计,并牢记一些我想讨论的问题。其中之一是...

我正在设计一个用于订单维护的 Web 应用程序。当用户创建新订单时,系统会打开一个新订单输入屏幕。它将生成一个应用程序编号和一些与订单限制相关的预配置信息(来自数据库),用户必须针对所创建的订单进行选择。

现在我想到的问题......

1. 如何生成这个新的订单输入屏幕,其中包含已生成的申请号以及从 DDD 角度从数据库中提取的一些信息?

2. 我是否必须使用 OrderFactory 创建新订单(填充了 App# 和限制),然后将其转换为 DTO 并将其发送到表示层?

3. 填写必要的详细信息后,当用户提交订单时,应遵循什么流程来保存订单?假设表示层将 OrderDTO 发送到服务层,那么服务层应该做什么?

I'm exploring Domain Driven Design for the first time and stuck with some questions in mind which I would like to discuss. One of them is...

I'm designing a web application for order maintenance. When the user creates a new Order, the system opens up a new order entry screen. It will generates an Application Number and some pre-configured information pertaining to order restrictions (from database) which the user has to select specific to this order being created.

Now the question I have in mind ....

1. How to go about generating this NEW order entry screen with Application Number generated and some information pulled in from database from DDD stand point?

2. Do I have to use an OrderFactory to create a NEW Order (with App# and restrictions populated) and then translate it to DTO and send it across to Presentation Layer?

3. After filling in the necessary details, when user submits the Order, what should be the process to follow to persist it? say presentation layer sends in a OrderDTO to service layer and then service layer should do what?

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

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

发布评论

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

评论(2

撑一把青伞 2024-10-18 16:53:21

以下是一个非常小的示例,可以让您对生命周期有一些了解。

请注意,这是一种传统的 DDD 风格,您可能希望将读取模型与写入模型 (CQRS) 分开,并基于 UI 任务。

在表示代码(控制器)中

var newOrder = _orderService.NewOrder(); // return a new DTO containing the generated id.
// Fill the updated info.
_orderService.SubmitOrder(updatedOrder);

在服务层(应用程序层)中

public OrderDTO NewOrder()
{
  var newOrder = OrderFactory.CreateNew();     // Create a new order which generate an id
  return _mapper.Convert<OrderDTO>(newOrder);  // Construct OrderDTO for the new order
}

public void SubmitOrder(OrderDTO orderDTO)
{
  var order = _mapper.Convert<Order>(orderDTO); // Construct order entity from DTO
  order.Activate() // Call some business logic in the domain 
  _orderRepository.Save(order); // Save order in repository
}

The following is a very small sample which can give you a little idea about the lifecycle.

Note that this is sort of traditional DDD style, you may want to separate the read model from the write model (CQRS) and make the UI task based.

In Presentation code (Controller)

var newOrder = _orderService.NewOrder(); // return a new DTO containing the generated id.
// Fill the updated info.
_orderService.SubmitOrder(updatedOrder);

In Service Layer (Application Layer)

public OrderDTO NewOrder()
{
  var newOrder = OrderFactory.CreateNew();     // Create a new order which generate an id
  return _mapper.Convert<OrderDTO>(newOrder);  // Construct OrderDTO for the new order
}

public void SubmitOrder(OrderDTO orderDTO)
{
  var order = _mapper.Convert<Order>(orderDTO); // Construct order entity from DTO
  order.Activate() // Call some business logic in the domain 
  _orderRepository.Save(order); // Save order in repository
}
在风中等你 2024-10-18 16:53:21

DDD 的核心是捕获用户意图。因此请提出更多问题,例如

1)用户为什么要创建订单 - 命令

2)用户创建订单后应该发生什么。这对域模型意味着什么——来自域的事件

请查看 CQRS 模式以获取更多信息

DDD is all about capturing the user intention .So put more questions like

1) Why did the user want to create order -- Command

2)what should happen after the user has created the order. what is that mean to the domain model -- Events coming out of domain

please look at CQRS pattern for more info

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