Skip to main content
Post Closed as "Duplicate" by Doc Brown c#
added 174 characters in body
Source Link

Recently I asked the following question regarding Clean Architecture with some things that were unclear to me: Clean Architecture using interfaces or Mediator approach?

I think I have a better understanding now. I'm using ASP.NET Core for development and I have an API layer with endpoints calling logic in the Application layer using injected interfaces.

I wish to use FluentValidation for writing my validation logic and I'm wondering what is the place for doing validation on data.

  1. One approach would be to have validation written on the Presentation layer, and have the validation done in the called endpoint. If all is valid, call the Application layer with the received data.
  2. Another approach would be to have the validation in the called method in the Application layer - the thought is that the API is the interaction with the user and the Application is in-charge of validating the data it had received is valid. Also If for some reason there would be any additional front-facing layers (parallel to the API layer) there wouldn't need to be validators introduced to it since the Application code is the one doing the validation, while the presentation is just accepting the data and passing it forward to the application. But this approach also add a bit of complexity since the response from the Application should return exactly what is invalid in the data to the presentation layer so that the presentation layer could notify the caller.
  3. A final approach is to have it in both places - which seems a bit redundant to me.

I've seen a lot of developers that put it as part of a pipeline - when using Mediator approach - which is not my case - maybe a con in favor of Mediator approach?

What is the "correct" place to place the validation?

EDIT

Please also consider the following scenario as being a validation: when a user registers, he cannot register if the email address he entered is already registered.

Recently I asked the following question regarding Clean Architecture with some things that were unclear to me: Clean Architecture using interfaces or Mediator approach?

I think I have a better understanding now. I'm using ASP.NET Core for development and I have an API layer with endpoints calling logic in the Application layer using injected interfaces.

I wish to use FluentValidation for writing my validation logic and I'm wondering what is the place for doing validation on data.

  1. One approach would be to have validation written on the Presentation layer, and have the validation done in the called endpoint. If all is valid, call the Application layer with the received data.
  2. Another approach would be to have the validation in the called method in the Application layer - the thought is that the API is the interaction with the user and the Application is in-charge of validating the data it had received is valid. Also If for some reason there would be any additional front-facing layers (parallel to the API layer) there wouldn't need to be validators introduced to it since the Application code is the one doing the validation, while the presentation is just accepting the data and passing it forward to the application. But this approach also add a bit of complexity since the response from the Application should return exactly what is invalid in the data to the presentation layer so that the presentation layer could notify the caller.
  3. A final approach is to have it in both places - which seems a bit redundant to me.

I've seen a lot of developers that put it as part of a pipeline - when using Mediator approach - which is not my case - maybe a con in favor of Mediator approach?

What is the "correct" place to place the validation?

Recently I asked the following question regarding Clean Architecture with some things that were unclear to me: Clean Architecture using interfaces or Mediator approach?

I think I have a better understanding now. I'm using ASP.NET Core for development and I have an API layer with endpoints calling logic in the Application layer using injected interfaces.

I wish to use FluentValidation for writing my validation logic and I'm wondering what is the place for doing validation on data.

  1. One approach would be to have validation written on the Presentation layer, and have the validation done in the called endpoint. If all is valid, call the Application layer with the received data.
  2. Another approach would be to have the validation in the called method in the Application layer - the thought is that the API is the interaction with the user and the Application is in-charge of validating the data it had received is valid. Also If for some reason there would be any additional front-facing layers (parallel to the API layer) there wouldn't need to be validators introduced to it since the Application code is the one doing the validation, while the presentation is just accepting the data and passing it forward to the application. But this approach also add a bit of complexity since the response from the Application should return exactly what is invalid in the data to the presentation layer so that the presentation layer could notify the caller.
  3. A final approach is to have it in both places - which seems a bit redundant to me.

I've seen a lot of developers that put it as part of a pipeline - when using Mediator approach - which is not my case - maybe a con in favor of Mediator approach?

What is the "correct" place to place the validation?

EDIT

Please also consider the following scenario as being a validation: when a user registers, he cannot register if the email address he entered is already registered.

Source Link

Where should validation be placed?

Recently I asked the following question regarding Clean Architecture with some things that were unclear to me: Clean Architecture using interfaces or Mediator approach?

I think I have a better understanding now. I'm using ASP.NET Core for development and I have an API layer with endpoints calling logic in the Application layer using injected interfaces.

I wish to use FluentValidation for writing my validation logic and I'm wondering what is the place for doing validation on data.

  1. One approach would be to have validation written on the Presentation layer, and have the validation done in the called endpoint. If all is valid, call the Application layer with the received data.
  2. Another approach would be to have the validation in the called method in the Application layer - the thought is that the API is the interaction with the user and the Application is in-charge of validating the data it had received is valid. Also If for some reason there would be any additional front-facing layers (parallel to the API layer) there wouldn't need to be validators introduced to it since the Application code is the one doing the validation, while the presentation is just accepting the data and passing it forward to the application. But this approach also add a bit of complexity since the response from the Application should return exactly what is invalid in the data to the presentation layer so that the presentation layer could notify the caller.
  3. A final approach is to have it in both places - which seems a bit redundant to me.

I've seen a lot of developers that put it as part of a pipeline - when using Mediator approach - which is not my case - maybe a con in favor of Mediator approach?

What is the "correct" place to place the validation?