简体   繁体   English

Automapper 将 Post 模型映射到域模型?

[英]Automapper map Post models to domain models?

I have the following model sets:我有以下模型集:

  • Entities实体
  • Domains
  • Views观看次数
  • Requests (Post methods)请求(Post 方法)

I have the following automapper mappings:我有以下自动映射器映射:

  • Entity -> domain实体 -> 域
  • Domain -> Entity域 -> 实体
  • Domain -> View域 -> 查看

I have hard time understanding what do to with my Post models.我很难理解如何处理我的 Post 模型。 Should they be mapped directly to domains?它们是否应该直接映射到域? Should they be mapped to RequestsDomains?它们应该映射到 RequestsDomains 吗?

What do you think?你怎么认为?

Post models are nearly always commands in the DDD sense. Post 模型几乎总是 DDD 意义上的命令。 If they are true commands, then your domain is responsible for enforcing invariants etc. Mapping could bypass all of those.如果它们是真正的命令,那么您的域负责执行不变量等。映射可以绕过所有这些。 I rarely if ever map back into a domain.我很少映射回域。 You can pass a command to a handler or the command directly to the domain for any potential state changes:您可以将命令传递给处理程序或将命令直接传递给域以进行任何潜在的状态更改:

class Invoice {
     void Handle(ApproveCommand command) {
         // Do work to approve an invoice. ApproveCommand is your Post model
     }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM