We Are Getting New Validation Types in .NET 8!

Поділитися
Вставка
  • Опубліковано 26 лис 2024

КОМЕНТАРІ • 66

  • @paleocomburo
    @paleocomburo Рік тому +7

    I only use these annotations to generate the Swagger file. I turn off actual validation, because I want to customize the error response. And its pretty hard to do that with the built-in validation. Additionally, not all validations we need to do can be done via these annotations. So you always end-up with additional validation logic anyways.

  • @VanDameDev
    @VanDameDev Рік тому +15

    FluentValidations all the way. It reads nice, is functional, and you can embed logic much more easily than DataAnnotations.

    • @sulmarpl
      @sulmarpl Рік тому +3

      Yes, into Validator we can also inject dependency. To attribute no.

  • @warrenbuckley3267
    @warrenbuckley3267 Рік тому +9

    The updated Required attribute is by far the most useful. I've always hated having to mark my value types as nullable in order to mark them as required... (assuming that I'm not using FluentValidation)

  • @badwolf01
    @badwolf01 Рік тому +31

    MinimumIsExclusive and MaximumIsExclusive is great for decimal ranges that are exclusive (e.g. trying to constrain to 0.001 to 0.999). When you use an integer value, yeah, definitely not valuable.

  • @konstantinospascal1892
    @konstantinospascal1892 Рік тому +1

    it was awesome seeing you today at NDC, you had my favorite presentation of the day 😀

  • @yatsuk
    @yatsuk Рік тому +1

    I use both. Annotations are useful for generating swagger files with Swashbuckle.

  • @haxi52
    @haxi52 Рік тому +1

    The required attribute is nice. For base64, just make the property type `byte[]` The model binder should do "the right thing" and base64 encode it.

  • @vaibhavrana4953
    @vaibhavrana4953 28 днів тому

    I was looking how to validate string. Found it here. Thanks

  • @Pezsmapatkany
    @Pezsmapatkany Рік тому +4

    Why not use the `required` keyword on the property instead of `DisallowAllDefaultValues`? It works for when you want to allow the default value too (like `0` for an int). I know that that will be like using of the `JsonRequiredAttribute` and the JSON serialization will fail, but it's still better IMHO.

  • @stephajn
    @stephajn 10 місяців тому +1

    I noticed that the RequiredAttribute in .NET 8 doesn't seem to ahve that DisallowAlldefaultValues property. Did they pull it out? Or is there some kind of NuGet package I'm missing?

  • @NoName-1337
    @NoName-1337 Рік тому

    Great stuff. Need to read the whole doc of this.

  •  Рік тому +4

    I would have at expected a base64 validation to at least also check the length and if it's padded correctly.

  • @GustavoRossiMuller
    @GustavoRossiMuller Рік тому

    I needed to implement the DisallowAllDefaultValues behavior last week. in .Net 6
    Glad I'll have it available when I upgrade to .Net 8😃

  • @DmitryV_HF
    @DmitryV_HF Рік тому

    2015 year, Microsoft Enterprise Library: - I'll be back
    2023: i'm here! It's me - Microsoft Enterprise Library!
    Great news. I use alot this attributes with custom realization, except base64. Now i'll can migrate this to sdk implementation.
    Required attribute - this best update. Much problems with this attribute has before.

  • @niezebenmansour3736
    @niezebenmansour3736 Рік тому

    In complex project, i prefer using fluent validation on commands with CQRS and the contracts (DTOs) stays neutral without validation

  • @vedantkoditkar5968
    @vedantkoditkar5968 Рік тому +6

    Mostly I would just use fluent validations.

  • @dovh49
    @dovh49 Рік тому

    I like data annotations better than fluent validation but sometimes, when you need have multiple validations on the same model, fluent validations can be nice.

  • @PeteeK
    @PeteeK Рік тому +4

    Blaze it. That's a missed opportunity, Nick.

  • @sadralatif
    @sadralatif Рік тому +2

    Why would I have to use Base64String if I'm going to later check if it can be decoded or not myself? In this way it seems useless. If they're gonna stick to their idea, at least they could add a property to let us choose full check in Base64String.

  • @abdifatahAnnaati
    @abdifatahAnnaati Рік тому

    I have being thinking about fluent Validation for months and I don't why but I haven'tt made any move yet🙂. I'm just stuck with Data anatations while throwing in some custom/Regex ones when needed😊

  • @iSoldat
    @iSoldat Рік тому +1

    Now, which method of validation is more efficient, overall, data annotations or any of the fluent validation patterns? Personally, for MVC, I like data annotations, but web API, I prefer fluent validations.

    • @nickchapsas
      @nickchapsas  Рік тому +4

      I personally prefer FluentValidation for everything.

    • @danielschmid9024
      @danielschmid9024 Рік тому

      Du you also prefer fluent model configuration over attributes? Attributes like the RequiredAttribute serve two purposes model configuration and validation. the validation part can be replaced by FluentValidation. How much sense does it make to leverage the fluent api to define the model instead of attributes?

  • @vamvdotnet
    @vamvdotnet Рік тому +1

    New video suggestion: the new TimeProvider type

  • @mortezabasij4524
    @mortezabasij4524 Рік тому

    I prefer to write complex error handling with annotations but they have limitations. Then i force to use fluentvalidation

  • @vredurs
    @vredurs Рік тому

    Are these annotations something that you see in for example a swagger documentation?

  • @EdKolis
    @EdKolis Рік тому

    Could disallowing zeroed out guids cause problems if one of them is actually generated? Or is all zeroes not possible to generate?

  • @PatrickMageez
    @PatrickMageez Рік тому

    I personally feel like FluentValidation is better, because it allows a better approach to change and configure rules, instead of hard coding via Attributes and needing to recompile.

  • @nurettinselcuk5149
    @nurettinselcuk5149 Рік тому

    FluentValidation is just too strong, no chance.
    I remember when i first used MustAsync in fluent validation, i was mind blown lol

  • @_nikeee
    @_nikeee Рік тому

    Does this apply to use cases not being ASP or why is it a ".NET 8" feature, according to the title?

  • @owninggreendragsdude
    @owninggreendragsdude 11 місяців тому +1

    DisallowAllDefaultValues does NOT exist!

  • @talp0sh
    @talp0sh Рік тому

    Is it possible to have FluentValidation rules to be displayed in Swagger in the same way as data annotations?

  •  Рік тому +2

    What is the behavior if I use the disallow default value in a boolean property?

    • @zabustifu
      @zabustifu Рік тому +1

      Same thing as with the Guid. If it can't deserialize it (ie: for bool, that's only either True or False), then it'll return a bad request.

    • @kein3001
      @kein3001 Рік тому

      ​@@zabustifu is that the same for the enums case?

    • @zabustifu
      @zabustifu Рік тому +1

      @@kein3001 I haven't tried it, but that's what I'd expect (ie: if the enum is not nullable, only actual enum values are accepted). To be confirmed.

  • @TheBuzzSaw
    @TheBuzzSaw Рік тому +4

    What if the GUID is required but the default value is allowed? I need a way to express that the value must be present in the JSON.

  • @EdKolis
    @EdKolis Рік тому

    Disallow all default values? I didn't know there were any types that had more than one default value!

  • @palpie
    @palpie Рік тому

    Maps good with formats in OpenAPI.

  • @saviouromeni9000
    @saviouromeni9000 Рік тому

    i use majorly fluent validation

  • @10Totti
    @10Totti Рік тому

    Good!

  • @yoanashih761
    @yoanashih761 Рік тому

    Are you trade forex or crypto? (just curious)

  • @leokarabeg
    @leokarabeg Рік тому +3

    The DisallowAllDefaultValues kind of helps in the case of guids, but it doesn't really work for ints, where 0 would often be a valid value. Then we still have to make it nullable.

    • @kislovs
      @kislovs Рік тому +1

      You can use BindRequired or JsonRequired (if that's inside JSON body)

  • @StefanoTempesta
    @StefanoTempesta Рік тому

    Still no DateTime validation...

  • @zzzanon
    @zzzanon Рік тому

    Thank you SeaSharp-Man. I am now smarter. 5 stars.

  • @raztubes
    @raztubes Рік тому +1

    The error message exposing the underlying attribute name is just awful. Who wrote that, the coop student?

  • @paulsanchez5030
    @paulsanchez5030 Рік тому

    Comon devs. lets stop being lazy and just create our own validation attribute classes and middlewares... there are AsyncFilter actions too.... xD Great vid

  • @amrosamy8232
    @amrosamy8232 Рік тому

    I always replace them with fluent validation

  • @ddruganov
    @ddruganov Рік тому +1

    bruh i thought that the base64 string @7:01 would be the video id for a rickroll :(

    • @lalibi
      @lalibi Рік тому

      What was it? I'm too lazy to check it myself.

    • @ovidiufelixb
      @ovidiufelixb Рік тому +2

      @@lalibi Blaze it

    • @ddruganov
      @ddruganov Рік тому +1

      @@lalibi unfortunately, nothing, youtube just 404s at that url

  • @dantecavallin8229
    @dantecavallin8229 Рік тому

    Is the thumbnail a pun on frozen sets?

  • @Kingside88
    @Kingside88 Рік тому

    I really hate DataAnnotations. Using FluentValidation is much more readable, flexible and restrict.
    Thanks for the video but I will never use them for sure
    In FluentValidation I can register them in DI and inject IStringLocalizer for different messages.
    The Messages here are prewritten

  • @directionsys
    @directionsys Рік тому

    For me is useless because the messages are in english only. I prefer to user FluentValidation package

  • @michalg4824
    @michalg4824 Рік тому +1

    Such features should be from. Net 1.1, not 8 😀

  • @erikporter
    @erikporter Рік тому

    BTC is the ONLY acceptable currency. 😉

  • @blazejszajrych1472
    @blazejszajrych1472 Рік тому +1

    One should not deny BTC and ETH 😆

  • @vivekkaushik9508
    @vivekkaushik9508 Рік тому

    So basically some syntactical sugar.