Comments (5)
also the same validation rules are repeated twice in the application layer command handlers, once for create and once for update, so you would end up with repeating the same rules 4 times throughout the solution
from northwindtraders.
I found this article which gave me some ideas on handling this situation.
https://hackernoon.com/mediatr-behaviors-to-validate-api-resource-existence-f81182e8a36c
from northwindtraders.
I actually ended up using the override Validate found here.
https://stackoverflow.com/questions/13198471/fluentvalidation-multiple-validators
from northwindtraders.
Just seen the
Clean Architecture with ASP.NET Core 2.1
talk and it was great, thanks for all of this hard work!
Hello and thank you. :)
What if i want to render a widget in the UI and want to set it's max length too? It's a really common scenario.
This is why I've always had validations in a layer up both persistance and validation. I see how data annotations in the domain entities would fix this but since it's discouraged by the talk. What would be the best approach to tackle this? Maybe define fluent validation rules at the application layer and somehow retrieve those rules both in presentation and persistance?
In this design, data annotations at the domain layer will not support validation at the application layer. Recall that we are validating the queries and commands, and not the entities. In fact, the entities will not be exposed to the client through the Web API or any other mechanism. They will remain internal to the solution.
I use Fluent Validation, because it supports both simple and complex validation scenarios. This integrates well with ModalState and supports unobtrusive validation.
One thing that I need to investigate is how well Fluent Validation works with Open API. I've heard that data annotations provide a good experience with Open API, such as supporting max lengths and so on.
Remember that you can always push your validation down to the domain layer, and this will avoid duplication such as in the create / update customer scenario.
Thanks @paulgbrown for your suggestions. The articles seem useful.
This area is certainly something that warrants further exploration.
Again, great talk! ^_^
Thanks again and happy coding!
from northwindtraders.
Just a heads up, I've added this to the road map - https://github.com/JasonGT/NorthwindTraders/projects/1#card-17415138
from northwindtraders.
Related Issues (20)
- Consistent naming for behaviors HOT 1
- Why is CQRS put in Application and not in WebUI? HOT 2
- Do non-entities core models belong to the domain? HOT 2
- Use ProblemDetails/ValidationProblemDetails etc for exception middleware
- Use ProblemDetails/ValidationProblemDetails etc for exception middleware? HOT 1
- How can we write unit test cases for controllers extending base controller as we are not using constructor injection. any leads will be appreciated. HOT 1
- What's the point of having the IDateTime interface? HOT 2
- FromSqlRaw won't work in Application HOT 2
- ValueObject.Equals bug when objects have a different number of values HOT 1
- [Question] Should JWT/RefreshToken creation be on infrastructure? HOT 1
- [Discussion] Clean Architecture - is it really? HOT 4
- Why does it not look like shown in the XAML ControlsGallery App - DataGrid HOT 4
- Dealing with duplication HOT 6
- Application layer access to DbContext? HOT 2
- A better way to do upsert HOT 1
- Suggestion: Request with record type
- something similar HOT 1
- IDbContext and repository pattern HOT 1
- How to call stored procedure for CURD operation? HOT 1
- This repo is pretty old and the projects don't event load in VS 2022 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from northwindtraders.