Skip to main content
6 events
when toggle format what by license comment
Aug 11, 2017 at 19:31 comment added Yurii N. Route constraints are not for validation, what should we do then with valid in context of query parameters, but invalid in context of business logic?
Aug 11, 2017 at 17:57 comment added t3chb0t @YuriyN. yes, usually it's better. You can do this for example for [FromBody] or [FromQuery]. With simple parameters this is not necessary as they are part of the route and if they were invalid the action wouldn't be hit and if their values are invalid but there is no such resource then 404 would be appropriate which is already handeled by the respository. Alternatively there is a large table of Route Constraints that you can apply to the route (mind the warning there).
Aug 11, 2017 at 17:33 comment added Yurii N. Ok, seems legit, but I still can't understand how can I validate a lot of input parameters with ModelState? Do you mean that for each action we need create DTO, like GetLibraryParameters?
Aug 11, 2017 at 15:37 comment added t3chb0t @YuriyN. rarely there is anything more complex and if there is something then it probably does not belong to the action but to some other service/repository etc etc. If you have actions with so much logic then you're doing it wrong. But come back when you have something more complex to show, then we can talk. Currently your approach is not using what asp.net core offers you and you write things that are unnecessary work.
Aug 11, 2017 at 14:59 comment added Yurii N. My code could be reduced for two lines only because of its simplicity, imagine more complex code and more complex flow, how it would be then?
Aug 11, 2017 at 13:08 history answered t3chb0t CC BY-SA 3.0