I find it difficult to decide whether something should be part of domain or application.
Reading through this answer helps a lot with concepts like authorisation but I still find myself struggling with other things.
To illustrate my confusion please consider a case of comment posting. Here are the things that need to happen before a comment can be posted. I indicate in parenthesis where I think this functionality should go.
- Make sure user role/status is allowed to comment on this post (authorisation, goes to Application)
- Make sure post to which we are commenting exists and is published (Domain)
- Make sure user has not posted more than 5 comments in the last minute (throttling, intuition says it goes to Application)
- Make sure comment is not an empty string (Domain)
- Make sure comment does not have dirty words (Domain?)
- Make sure comment does not have duplicates from same user in this post (Domain?)
- Format the comment (Application)
- Remove certain HTML tags from comment that are not permitted for current user (Application)
- Check comment for spam (Application?)
I can't decide whether checking comment for spam is domain concern or application, same goes for throttling. From my point of view both of these concerns are important for me and must be present. But same goes for authorisation and we know that it should not be in Domain.
If I split these concerns between a domain service and application service then I feel like my domain is not completely enforced and actually relies on application to make prior checks. In that case what is the whole point, why don't I just do it all in application to reduce confusion?
My current setup does this:
Controller ->
App.CommentingService.Comment() ->
Domain.CommentingService.Comment()
It would be helpful if someone could go through all the required steps to create a comment and assign it to the right layer giving some reasoning behind.