I am working on a school project which basically acts like a Messenger with Events etc.
Recently I came across DDD and I decided to try to implement it's concepts in my project.
I ran into a problem, where each time I want to edit an entity I need to check, if a currently logged user has rights for it.
I have CommmunicationChannel entity (AR) which has ICollection<CommunicationChannelMessage>. When I want to edit message I need to load CommunicationChannel entity, find CommunicationChannelMessage in it and then check if currently logged user is the author of the message.
I decided to create DomainService MessageManager, which has method Update(CommunicationChannel channel, string messageId, string newContent).
This method loads the message or throws NotFoundException, after that it check, if user has right to it and if not throws ForbiddenAccessException.
Basically, domain layer now has a responsibility to check if currently logged user has rights to do something. The idea behind this is that there will be no place in code, where I can forget to check permissions of the user. I can only call methods from this manager and they check permissions everytime.
So my question is following. Can a domain service have a reference to ICurrentUserService (returns entity of currently logged user). Shouldn't the check of user permission be application specific concern in Application layer instead of domain layer?
Thank you so much for your answer.