在领域驱动设计中使用数据库作业

发布于 2024-10-30 01:46:02 字数 153 浏览 9 评论 0原文

我正在使用域驱动设计方法创建 .net 应用程序。该应用程序包括向客户收取服务费用。该规则规定,每天在给定时间应生成发票并更新用户的余额。正如我所看到的,这里最好的选择是计划执行上述任务的数据库作业。但是,这与DDD兼容吗?在这种情况下,逻辑被分割在数据库和域名层之间,这似乎不是一个好主意。

I am creating a .net application using Domain Driven Design approach. The application includes billing clients for services. The rule says that daily, at a given time an invoice should be generated and user's balance should be updated. As I see, the best option here would be a database job which being scheduled does the above task. However, is this compatible with DDD? The logic is split among database and domail layer in this case, which seems not to be a good ideea.

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

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

发布评论

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

评论(2

猫烠⑼条掵仅有一顆心 2024-11-06 01:46:02

DDD 的一部分是设法尽可能地将领域模型与技术问题脱钩。

将业务知识放入数据库作业中意味着:

  • 您将有 2 个地方来查找业务逻辑(失去模型隔离)
  • 您的业务逻辑将用 2 种语言描述(例如 c#;t-sql)
  • 管理业务逻辑可能并不容易w/ 程序化 sql 脚本
  • 与用 .Net 编写的部分同步可能并不容易,

我个人不会走那条路。我会写后台服务。

Part of DDD is managing to decouple domain model from technical concerns as much as possible.

Putting business knowledge in database jobs means:

  • You would have 2 places to look for business logic (loss of model isolation)
  • Your business logic would be described in 2 languages (e.g. c#; t-sql)
  • It might not be easy to manage business logic w/ procedural sql scripts
  • It might not be easy to sync w/ part which is written in .Net

I personally wouldn't go that road. I would write background service.

穿越时光隧道 2024-11-06 01:46:02

如果这很重要的话,实现数据库作业将更难以调试和单元测试。

我会推荐一项执行计划任务的服务。

Implementing a database job will be more difficult to debug and unit test if that matters.

I would recommend a service that does scheduled tasks.

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