Passing services into Domain layer. #136
-
How would you implement for ex. public void Edit(MemberId editorId, string editedComment, MeetingCommentingConfiguration meetingCommentingConfiguration, IExternalSystem system, ILogger logger)
{
this.CheckRule(new CommentTextMustBeProvidedRule(editedComment));
this.CheckRule(new MeetingCommentCanBeEditedOnlyByAuthorRule(this._authorId, editorId));
this.CheckRule(new CommentCanBeEditedOnlyIfCommentingForMeetingEnabledRule(meetingCommentingConfiguration));
_comment = editedComment;
_editDate = SystemClock.Now;
// Here is more logic with `_comment` and other Entities
// ...
// Loading some data from the external system
var data = system.ProcessComment(_comment);
if(data.SomeState)
{
logger.Warring("Some important information");
_comment = data.CommentPrefic + _comment + "_xx";
// Do some logic with other Entities
// ...
}
// Here is more logic with `_comment` and other Entities
// ...
this.AddDomainEvent(new MeetingCommentEditedDomainEvent(this.Id, editedComment));
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi!
So it's application layer's concern to prepare all data which is needed for business decisions in an use case and then delegate this decisions to domain model. So in the example you should get data from As for logging it's a cross-cutting concern and doesn't belong to domain logic nor application logic. It's often implemented with decorator pattern. For example you could create decorator for
|
Beta Was this translation helpful? Give feedback.
Hi!
You should keep your domain model as isolated as possible. This means it must operate only primitive types(or domain primitives) and domain objects and have no dependecies to any external logic(call database or 3rd party services). This constraint helps to express properly ubiquotous language, makes domain model easier to understand(not to add accidential complexity to essential one) and test.
Repository and Domain service are part of domain model but it's also recommended not to pass them to aggregates[1]: