开发者

Process Flow Create a New Order Entry DDD Way

开发者 https://www.devze.com 2023-02-04 05:52 出处:网络
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 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?


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
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号