问题标签 [domain-driven-design]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
7 回答
185 浏览

database - 是否应在数据库中重复“一个父对象最多有 2 个子对象”之类的规则

可以使用触发器在数据库中强制执行诸如“一个父对象最多有 2 个子对象”之类的规则。但是,如果该规则已在域层中实施,那么复制该规则是否是一个好主意。

在哪些情况下重复此类规则是合理的?有没有其他方法可以避免这种重复?这不是数据完整性规则吗?

谢谢

0 投票
3 回答
1099 浏览

c# - How to implement an offline reader writer lock

Some context for the question

  • All objects in this question are persistent.
  • All requests will be from a Silverlight client talking to an app server via a binary protocol (Hessian) and not WCF.
  • Each user will have a session key (not an ASP.NET session) which will be a string, integer, or GUID (undecided so far).

Some objects might take a long time to edit (30 or more minutes) so we have decided to use pessimistic offline locking. Pessimistic because having to reconcile conflicts would be far too annoying for users, offline because the client is not permanently connected to the server.

Rather than storing session/object locking information in the object itself I have decided that any aggregate root that may have its instances locked should implement an interface ILockable

This LockID will be the identity of a "Lock" object which holds the information of which session is locking it.

Now, if this were simple pessimistic locking I'd be able to achieve this very simply (using an incrementing version number on Lock to identify update conflicts), but what I actually need is ReaderWriter pessimistic offline locking.

The reason is that some parts of the application will perform actions that read these complex structures. These include things like

  • Reading a single structure to clone it.
  • Reading multiple structures in order to create a binary file to "publish" the data to an external source.

Read locks will be held for a very short period of time, typically less than a second, although in some circumstances they could be held for about 5 seconds at a guess.

Write locks will mostly be held for a long time as they are mostly held by humans.

There is a high probability of two users trying to edit the same aggregate at the same time, and a high probability of many users needing to temporarily read-lock at the same time too. I'm looking for suggestions as to how I might implement this.

One additional point to make is that if I want to place a write lock and there are some read locks, I would like to "queue" the write lock so that no new read locks are placed. If the read locks are removed withing X seconds then the write lock is obtained, if not then the write lock backs off; no new read-locks would be placed while a write lock is queued.

So far I have this idea

  1. The Lock object will have a version number (int) so I can detect multi-update conflicts, reload, try again.
  2. It will have a string[] for read locks
  3. A string to hold the session ID that has a write lock
  4. A string to hold the queued write lock
  5. Possibly a recursion counter to allow the same session to lock multiple times (for both read and write locks), but not sure about this yet.

Rules:

  • Can't place a read lock if there is a write lock or queued write lock.
  • Can't place a write lock if there is a write lock or queued write lock.
  • If there are no locks at all then a write lock may be placed.
  • If there are read locks then a write lock will be queued instead of a full write lock placed. (If after X time the read locks are not gone the lock backs off, otherwise it is upgraded).
  • Can't queue a write lock for a session that has a read lock.

Can anyone see any problems? Suggest alternatives? Anything? I'd appreciate feedback before deciding on what approach to take.

0 投票
7 回答
170542 浏览

domain-driven-design - 我在哪里可以找到一些 DDD 的好例子?

我正在学习领域驱动设计,但是有一些实际问题让我感到困惑,我认为看到一些好的样本可能会清楚。

有谁知道一些可以很好地建模基本 DDD 概念的工作代码示例?

特别感兴趣

  • 说明性领域模型
  • 存储库
  • 使用域/应用程序服务
  • 值对象
  • 聚合根
0 投票
3 回答
804 浏览

nhibernate - 持久性无知可以扩展吗?

我已经简要介绍了 NHibernate 和 Linq2Sql。我也打算看看实体框架。

当我谈到这些 ORM 时,提出的问题是“它们无法扩展”,那么它们可以吗?从谷歌我得到的印象是他们能够很好地扩展,但最终我认为必须付出代价,是否值得为更丰富、更简单的业务层付出代价。

0 投票
2 回答
4380 浏览

javascript - Javascript 域模型对象的约定

如果我必须在 C# 中创建域模型对象,我可能会执行以下操作:

在 Javascript 中,定义此类对象的约定是什么?我在想这样的事情:

0 投票
4 回答
625 浏览

architecture - 如何处理需要在数据库中查找数据的值对象

我刚开始研究领域驱动设计,很可能我对实体/价值划分的理解是错误的,所以如果是这样,请告诉我。

据我了解,由于其身份完全由其属性定义,因此 Address 是典型的值对象。据我了解,这意味着不应该有单独的存储库或地址的数据访问对象。

这给我带来了两难境地,因为在我的例子中,地址包含一个国家,其中一个国家有一个名称和一个国家代码,并且应该从数据库中加载国家代码列表。

我的问题是,我该如何设计这个?我希望人们能够使用 new 运算符创建地址,但我不想为国家/地区创建数据访问对象,如果我这样做了,我当然不想在地址对象中引用它。

我有一些想法,但我想听听任何人可能有的任何建议。

0 投票
6 回答
30700 浏览

design-patterns - 领域驱动设计和工厂类的作用

我不清楚工厂类的角色和职责是什么。我知道工厂类应该负责创建域对象(聚合根)及其关联的实体和值对象。

但我不清楚工厂“层”在 DDD 架构中的位置?工厂是否应该直接调用存储库以获取其数据或服务库?

工厂在哪里适合以下框架:
UI > App > Domain > Service > Data

此外,因为工厂是唯一允许创建对象的地方,如果您想在数据和服务层中创建对象,您不会获得循环引用吗?

如果工厂类的作用是创建对象,那么服务层有什么好处呢?

我已经问了很多问题,并感谢任何回应。我缺少的是一个示例应用程序,它演示了域驱动设计项目中的所有层如何组合在一起......那里有什么吗?

0 投票
1 回答
488 浏览

c# - 使用 SQL 后端时的存储库模式和项目删除

所以假设我有一个名为 Post 的类,其中包含一个 IList

我发现当我要求我的存储库更新我的帖子时,将评论添加到列表中很容易,它可以查看哪些评论是新的,并将所需的信息发送到我的数据层,但是当评论被删除时呢? ? 你怎么处理这个?

你会拉回一个评论列表来检查哪些评论不再存在于当前更改的集合中吗?

或者连接事件来跟踪它?

还是完全不同的东西?

只是为了获取更多信息,我在 C# 中执行此操作并且不能使用 O/R 映射器。我必须使用存储过程来检索数据集并手动映射我的对象。我可能对存储库模式的理解是错误的,但我使用它来调解数据层,从请求数据、添加数据等,它将我的数据集数据映射到对象并返回对象。因此,如果您愿意,也可以随意详细说明如何使用存储库模式。

0 投票
4 回答
2779 浏览

domain-driven-design - 所有“批量”操作在 DDD 中属于哪里?

在 DDD 中,关键概念之一是存储库,它允许您检索实体(或聚合根),然后在更新后将它们保存回来。

假设我们需要对实体执行一些“批量”操作,并且实体的数量使得将它们检索到内存中是绝对不可能的。ie操作只能在数据库中进行。

这种“批量”操作的地方在哪里?它应该是存储库上的方法吗?它不会通过数据库特定操作“泄漏”存储库抽象吗?它不会将业务操作从实体转移到存储库吗?

0 投票
2 回答
2448 浏览

domain-driven-design - 我应该如何将对象添加到由聚合根维护的集合中

假设我有一个 BlogPost 聚合根。它拥有一个 List <Comment>
BlogPost AddComment 签名应该如何?是否可以使用:

或者我应该避免在它之外创建对根的孩子的引用,并做这样的事情: