问题描述
我有一个会议对象:
会议{id,名称,时间,CreatedBy,UpdatedBy}
和
MeetingAssignee {id,MeetingID,EmployeeId,CreatedBy,UpdatedBy)
会议作为聚合根,具有方法AssignEmployee。
Meeting, as Aggregate root, has a method AssignEmployee.
我大约像我所说的AssignEmployee一样,将当前用户传递给Meeting对象,以便它可以相应地更新其审核字段。
I was about to pass in the current user to the Meeting object as I call AssignEmployee, so that it can update its audit fields accordingly.
但这似乎不正确-是吗?显然,我可以公开审核字段,以后再更改-也许是在服务级别?
But this doesn't seem right - is it? Obviously I can keep the audit fields public and change them later - perhaps at service level?
每个人还有其他更喜欢的方法来更新这些字段吗?
What is everyone's else preferred method for updating these fields?
请注意:我们不使用Nhibernate,
Please note: We are not using Nhibernate, but a custom ORM which does not have anything automatic in place.
谢谢。
推荐答案
审计和日志记录很有趣,因为它们通常在应用程序中的每个地方都需要,并且它们都是必需的(日志记录是来自OP运营商的要求)。
Auditing and logging are fun as they are usually needed everywhere in the application and they are both requirements (logging is a requirement from the OPs guys).
在不了解您的大部分模型的情况下,并且由于必须进行审核,因此我会将当前用户传递给 AssignEmployee
,而不是在那行表示 AuditBlahBlahBlah
,我将添加一个事件(也许MeetingUpdated或AssigneeAdded ...您会发现一个好名字),并且该事件被分派给进行审核的类。这样一来,Meeting类就不了解审计,而是为审计目的调度业务事件(在我看来,这是非常DDDish)。
Without knowing much of your model, and since auditing must be a requirement, I would pass the current user to AssignEmployee
and instead of having a line there that says AuditBlahBlahBlah
, I would add an event (maybe MeetingUpdated or AssigneeAdded... you'll find a good name) and that event gets dispatched to the class that does the auditing. In this way the Meeting class has no clue about auditing and dispatches business events for auditing purposes (which, in my view, is very DDDish).
我想知道还有哪些其他人可能会说(希望我能学到新东西!)
I wonder what other people might say (hopefully, I can learn something new!)
这篇关于何时更新审核字段? DDD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!