Where to put global rules validation in DDD

后端 未结 9 2072
一整个雨季
一整个雨季 2020-12-07 07:10

I\'m new to DDD, and I\'m trying to apply it in real life. There is no questions about such validation logic, as null check, empty strings check, etc - that goes directly to

9条回答
  •  隐瞒了意图╮
    2020-12-07 07:57

    Create a method, for example, called IsUserNameValid() and make that accessible from everywhere. I would put it in the user service myself. Doing this will not limit you when future changes arise. It keeps the validation code in one place (implementation), and other code that depends on it will not have to change if the validation changes You may find that you need to call this from multiple places later on, such as the ui for visual indication without having to resort to exception handling. The service layer for correct operations, and the repository (cache, db, etc.) layer to ensure that stored items are valid.

提交回复
热议问题