知识卡片
嵌套更新混合命令
Client SDK 的 MergePatchPersonDto 可在一次聚合更新中组合不同层级的命令。书中示例更新 Person 的生日,对 2020 年计划设置 IsPropertyDescriptionRemoved=true 并改为 active;其月度计划数组同时含 MergePatchMonthPlanDto 与 CreateMonthPlanDto。根命令携带 Version、CommandId 和 RequesterId,序列化后作为 PATCH /People/Yang,Jiefeng,1 的请求体。各层 commandType 决定创建或更新语义;示例新建月计划只填了描述,序列化结果的 month 为 0,不能照抄为“二月计划”而忽略缺失的月份赋值。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《深入实践DDD:以DSL驱动复杂软件开发》第165章《13.5.2 更新聚合实例》(源文件:_epub-src/OEBPS/Text/chapter167.xhtml)
- 结论依据:原文 C# 示例和 JSON 输出展示嵌套 MergePatch/Create 命令、删除标记及根命令元数据;新建月计划未赋 `Month`,输出 JSON 为 0,与文字所说的“2020/02”不符,不能视作正确的二月创建请求。
- 原始内容:updateYearPlan2020.IsPropertyDescriptionRemoved = true; updateYearPlan2020.Active = true; updatePerson.YearPlans = new CreateOrMergePatchOrRemoveYearPlanDto[] { updateYearPlan2020 };
- 补充原文:CreateMonthPlanDto monthPlan202002 = new CreateMonthPlanDto(); monthPlan202002.Description = "My 2020/02 month plan."; updateYearPlan2020.MonthPlans = new CreateOrMergePatchOrRemoveMonthPlanDto[] { updateMonthPlan202001, monthPlan202002 };
- 补充原文:{ "commandType": "Create", "requesterId": 0, "month": 0, "description": "My 2020/02 month plan.", "dayPlans": [] }