存储库可以根据它(实际上)包含的对象返回 bool 值吗?
例如:
if (userRepository.checkCredentials(username, password))
{
// ...
或者它是一种更好的方法来做详细的方式:
user = userRepository.findByUsername(username);
if (user != null && user.checkPassword(password)) {
{
// ...
最佳答案
听起来更像是规范,不是吗?
if (canAuthenticateSpec.isSatisfiedBy(username, password))
过去,我使用规范完成了这项工作,因此我可以清楚而简单地检查我的代码以供使用。
但是,最近,我使用一个可以完成工作的服务来完成此操作,并根据他们未进行身份验证的原因构建结果。所以,像这样:
AuthenticateResult result = slAuthenticator.Authenticate(username, password)
if (result.authenticated) {
user = result.user
} else {
String message = result.failureReason;
关于language-agnostic - DDD : can a repository return boolean values?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7435449/