DDD: What is included in the domain and what is included in the application?

It's hard for me to decide if something should be part of a domain or application.

Reading this answer helps with concepts like authorization, but I still run into other issues.

To illustrate my confusion, consider posting comments. Here's what needs to happen before a comment can be published. I indicate in parentheses where I think this functionality should go.

  • Make sure that the role / status of the user is allowed to comment on this post (authorization, goes to the application)
  • Make sure the post we are commenting on exists and is published (Domain)
  • Make sure that the user has not posted more than 5 comments at the last minute (throttling, intuition says that it goes to the application)
  • Make sure the comment is not an empty string (Domain)
  • Make sure there are no dirty words in the comment (Domain?)
  • Make sure the comment has no duplicates from the same user in this post (Domain?)
  • Format comment (app)
  • Remove specific HTML tags from comments that are not allowed for the current user (application)
  • Check the comment box for spam (Application?)

I cannot decide if checking the comment for spam is a question or expression about the domain, the same goes for throttling. From my point of view, both of these problems are important to me and should be present. But the same goes for authorization, and we know that this should not be in Domain.

If I share these issues between the domain service and the application service, then I feel that my domain is not fully respected and is actually relying on the application for preliminary checks. In this case, whatโ€™s the point, why donโ€™t I just do all this in the application to reduce confusion?

My current setup does this:

Controller -> App.CommentingService.Comment() -> Domain.CommentingService.Comment()

It would be useful if someone could go through all the necessary steps to create a comment and assign it to the correct level, giving some arguments.

+5
source share
1 answer

Your setup looks correct. Application services often come in two flavors:

Application features: email notifications, authorization, persistence, etc. All functions besides the domain are included in your system.

Alignment of applications: to satisfy the precedent, you need the coordinates of the functions of the application and the domain. All plumbing comes here.

Keep in mind that application coordination models use cases; therefore, they do not always correspond to 1 service service = 1, since in case of use there can be more than 1 process.

  Controller App.CommentingService.Comment() //coordination of below features and domain App.AuthService().Autorize(); //feature Domain.CommentingService.Comment(); //domain App.PersistenceService().Persist(); //feature App.NotificationService().SentNotificationToUser(); //feature 

Why don't I just do all of this in an application to reduce confusion?

Segregation of applicability, loose coupling, inception of dependencies, etc .; all this is good for many reasons. I will give you a real example that I recently participated: having an assembly of free nodes (this was in the .NET framework) using only domain services, allows me to host the same domain without changes in the web application, DesktopApp and the SOAP web service simply changing application coordination services, as the requirements and use cases are different for each application.

About what is in the domain and what is not. It is very difficult to give you a direct answer, because it depends on what your domain is or not.

i.e.

Make sure the user has not posted more than 5 comments at the last minute

You must ask, why are you throttling? To prevent a messy interface? Why? Prevent Denial of Service Threat? Or breaks the rule in your "game" because your "game" just gives the user limited attempts during spam? This is what indicates that something is a domain or application.

+3
source

Source: https://habr.com/ru/post/1240987/


All Articles