ServiceStack - Validation and Database Access

不羁的心 提交于 2019-12-01 09:26:04

Yes it is incorrect to perform the check for the existence of a database record in validation logic, because this is not a validation check. Which is why it is not done in the examples this way.

Checking for the existence of a record is a verification check. By way of an example to illustrate this:

If you take a Credit Card Number, you can use Luhn Algorithm to validate that the credit card number is valid. That would be done in a validator, because it is validation.

But just because you have a valid number doesn't mean it exists, you may have a valid number for a card not yet issued. It would be incorrect to use a validator to verify that it exists, because this is a verification process, and should be done in the business logic.

When you start using the database to check for existence of stuff you are out of the realm of validation, because you should only ever pass validated data to the database.

You can read more about the difference between validation and verification here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!