一个域对象被“填充”;由多个存储库

发布于 2024-10-05 03:55:44 字数 254 浏览 2 评论 0原文

我是 DDD 新手,需要澄清一些概念,以便我可以将其应用到我的项目中。

基本上,我有一个域对象“客户”。 CustomerRepository 将通过引用 DAL 返回此域对象。

问题是 DAL 无法提供“填充”客户域对象所需的所有信息。有关客户的一些信息将由其他外部资源获取,可能是其他存储库或外部 Web 服务。

也许我应该划分我的“客户”域对象。但如果我的业务逻辑不允许我这样做怎么办?

另外,返回域对象只是存储库的责任吗?

I am new to DDD and need to clear some concept so that i can apply it on my project.

Basically, i have a domain object "Customer". CustomerRepository would return this domain object by referring the DAL.

The problem is that the DAL cannot provide all the information needed to 'fill' Customer domain object. Some information regarding the Customer will be acquired by some other external resource, maybe some other repository or a external web service.

Maybe i should divide my "Customer" domain object. But what if my business logic doesn't allow me to do so?

Also, is it only repository responsibility to return domain object?

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

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

发布评论

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

评论(1

戈亓 2024-10-12 03:55:44

是的,这应该是存储库的责任。

现在的存储很便宜。也许将数据加倍可以解决您的问题?例如,如果 customer.firstname 来自数据源 #1,但 customer.lastname 来自数据源 #2,您只需确保在客户注册时 customer.lastname 存储在数据源 #1 中(+ 将更新已注册的过程)顾客)?

另一件事 - 你的领域模型不应该知道这个问题。您应该尽量让它不知道技术问题。否则 - 您最终将失去隔离并最终得到人工域对象,这些对象在那里编码只是为了使其运行。

Yes, it should be responsibility of repository.

Storage is cheap nowadays. Maybe doubling that data would solve Your problems? E.g., if customer.firstname comes from data source #1 but customer.lastname comes from data source #2, You could just make sure that on customer registration customer.lastname is stored in data source #1 (+ procedure that would update already registered customers)?

Another thing - Your domain model shouldn't know about this problem. You should try to keep it unaware of technical problems. Otherwise - You will eventually lose isolation and end up with artificial domain objects that are coded there just to make it run.

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