存储库的替代数据访问模式

发布于 2024-07-15 02:30:12 字数 386 浏览 5 评论 0原文

我的域中有某些对象不是聚合根/实体,但我仍然需要从数据库中检索它们。 我不想通过为这些东西创建存储库来混淆事情。 那么,替代数据访问模式有哪些? 您是否会简单地为它们创建一个 DAO,同时仍然分离接口?

编辑:

关于我正在做的事情的更多细节。 我需要创建一个代码。 该代码的格式有一定的规则。 其中一个规则是最终字符必须是一个唯一的数字,从最后生成的代码开始加一。 例如:

ABCD1 ABCD2 ABCD3

因此,我保留一个一行一列的表来存储相关数字。 现在,我不想将此数字视为一个实体并为其创建存储库 - 这太过分了。 我只需要一种检索数字、加 1 并保存它的方法。 我知道有很多方法可以做到这一点,但我想知道是否有一种惯用的方法。

I have certain objects in my domain which are not aggregate roots/entities, yet I still need to retrieve them from a database. I don't want to confuse things by creating repositories for these things. So, what are alternative data access patterns? Would you simply create a DAO for them, while still of course separating the interface?

Edit:

Some more detail on what I'm doing. I need to create a code. This code has certain rules as to its format. One of the rules is that the final character must be a unique number incremented by one from the last code generated. For example:

ABCD1
ABCD2
ABCD3

So, I'm keeping a table with one row, one column to store the number in question. Now, I don't want to consider this number an entity and create a repository for it - that's overkill. I just need a way of retrieving the number, adding 1 to it, and saving it. I know there are myriad ways I could do it, but I'm wondering if there's an customary way.

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

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

发布评论

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

评论(3

对风讲故事 2024-07-22 02:30:12

理论上有几种可以应用的数据访问模式。 如果您希望我们建议特定模式,您需要提供更多详细信息。

如果没有更多细节,我只能建议考虑查看Martin Fowler 的企业应用程序架构模式一书。

编辑:习惯方式? 不,不是我能想到的 - 这实际上取决于您在域中的位置和方式使用这个独特的代码。 如果我这样做,我可能会创建一个直接与数据库对话来执行此功能的小型服务 - 不像存储库那么重量级,并且非常专注于手头的问题。

There are several data access patterns that could apply, in theory. You'd need to provide more detail though if you want us to suggest a specific pattern.

Without more detail, all I can suggest is to consider looking into Martin Fowler's Patterns of Enterprise Application Architecture book.

Edit: Customary way? No, not that I can think of - it really depends on where and how you're using this unique code in your domain. If I were doing this, I'd probably create a small service that speaks directly to the database to perform this function - not as heavy-weight as a repository, and very focused on the problem at hand.

往日 2024-07-22 02:30:12

基于编辑:我会首先查看您需要创建该代码的上下文。 也许有一些相关的实体或您缺少的东西。

顺便说一句,我发现这个问题非常有趣,因为它在编码特定功能时不时出现。 我通常最终会发现我在场景中遗漏了一些东西,并且它最终非常适合正常的存储库模式。

Based on the edit: I would look first at the context in which you need to create that code. Perhaps there are some related entities or something that you are missing.

btw, I find the question really interesting as it comes up from time to time while coding specific features. I usually end up finding I was missing something on the scenario and it ends up fitting well with the normal repository pattern.

猛虎独行 2024-07-22 02:30:12

在调查了选项之后,我将采用表网关模式。

After surveying the options I'm going with the Table Gateway pattern.

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