The rule itself would stay in class Usuario
. But you wouldn’t need to validate the password Usuario
twice in the domain class, for when you say:
Now, a rule that would be: for the user to register the password, he must
enter twice to confirm the entered password
This is more of a front-end validation, no need to also do it in the back-end (in the class Usuario
).
Continuing the answer, in your case, you first need to check where to place your class Usuario
within the system.
In the context of the DDD, it could be in a project of Domain (domain classes), in the context of the User (Usuarioctx) and within a User aggregation (Usuarioagg):
Projeto.Domain/UsuarioCtx/UsuarioAgg/Usuario.cs
The rule could be in a method within this class. But, however, until you get to your domain class, you’re expected to pass some Controller class. But, you also need to properly separate your project to house this controller class. One possibility is that it is in another Interface. If you are using REST, a suggestion would be:
Projeto.Interface/Services/Rest/UsuarioCtx/UsuarioController.cs
There, finally, you could have a service to register the password. As I said before, you can call this service after you validate, on the front end, if the user entered 2 identical passwords. Validated this, call a correct REST service (a PUT
, as it is an update), as a cadastrarNovaSenha
(method name in class, not service name! ) in your UsuarioController
.
In the UsuarioController
, make other relevant validations that, preferably, may be in the User domain class (example: check if the password is equal registered is equal to the new password, comparing the hash). Always taking care, of course, not to pass classes of Repository into your domain class to perform searches...
If you really want to validate the same form passwords back-end, you can use a simple method like this on Usuario.cs
, being called the UsuarioController.cs
:
public bool VerifySenhasIguais(String senhaNova)
{
//TODO comparação com a senha atual
}
Once the necessary validations have been made, update the user with the new password and save again. This stage has more details, but I think your question does not cover this.
Remembering that I’m not getting into the merit of the discussion that you need all this to get what you want, but I’m giving you an example of what it could be.
I understood what you meant perfectly, it’s exactly how I thought you thought, although the way you answered it is different from the point of view of the question, I could understand what you meant by the separation of services implementations, interfaces, and also the care with the repositories, because the domain layer only has interfaces of repositories and not the concrete classes themselves....
– Elkin