返回域对象最佳实践列表

发布于 2025-01-01 05:39:46 字数 492 浏览 1 评论 0原文

我使用 DDD 原则为新项目创建了基础架构。我有为域中的工厂/水化器提供原料的存储库。应用程序层充当外观,根据请求将域模型扁平化为各种视图/编辑模型。

编辑模型被映射并合并回域模型,并由使用流畅验证的服务进行验证。任何错误都会被记录并通过错误服务报告给用户。

这一切都很完美。我现在关心的是如何最好地生成这些域对象的列表。

我想到了几个选项:

1)水合全域模型,然后将它们展平为一个列表。域模型可以缓存为 IEnumerable 列表。然后,该集合被展平并推送到请求视图。

2)创建一个“投影”对象,它是领域模型的轻量级表示。这几乎不需要水合,并且可以通过域级别拉动并映射到视图模型并显示。

3)“绕过”域并从应用层调用一个服务来生成 IEnumerable。这将使域保持干净。

我担心解决方案 1 会因为显示域项目列表而变得繁重。虽然它们将被缓存,但由于域的可搜索性质,无法保证缓存会发挥很大作用。

任何有关最佳选择的建议将不胜感激。

I've created the infrastructure for a new project using DDD principles. I have repositories which feed factories/hydrators in the domain. An application layer acts as a facade, flaterning domain models to various view/edit Models when requested.

Edit models are mapped and merged back into the domain model, being validated by a serice using fluent validation. Any errors are logged and reported back to the user through an error service.

This all works perfectly. My concern now is how best to produce lists of these domain objects.

A few options come to mind:

1) Hydrate full domain models and then flatten these to a list. The domain models could be cached as an IEnumerable list. This collection is then flattened and pushed out to the requesting view.

2) Create a "projection" object which is lightweight representation of the domain model. This would require little to no hydrating, and could be pulled through the domain level and mapped to a viewModel and displayed.

3) "bypass" the domain and have a service called from the application layer which generates the IEnumerable. This would leave the domain clean.

I worry that solution 1 would be heavy for the sake of displaying a list of domain items. Whilst they will be cahched, due to the searchable nature of the domain, there is no guarentee the cache will do much good.

Any advice on what would be the best option would be appreciated.

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

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

发布评论

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

评论(1

萌面超妹 2025-01-08 05:39:46

我更喜欢解决方案 2。保持领域模型干净是必要的。

通过CQS(命令查询分离),我们可以实现有效且轻量级的查询架构。

I prefer the solution 2. Keeping the domain model clean is neccessary.

By CQS (Command Query Separated), we can implemente an effective and lightweight query architecuture.

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