A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/valit-stack/Valit below:

valit-stack/Valit: Valit is dead simple validation for .NET Core. No more if-statements all around your code. Write nice and clean fluent validators instead!

Valit is dead simple validation for .NET Core. No more if-statements all around your code. Write nice and clean fluent validators instead!

Valit is available on NuGet.

Install-Package Valit -Version 2.0.0
dotnet add package Valit --version 2.0.0

In order to create a validator you need to go through few steps. It's worth mentioning that not all of them are mandatory. The steps are:

Having the validator created, simply invoke Validate() method which will produce the result with all the data.

Let's try it out with very practical example. Imagine that your task is to validate model sent from registration page of your app. The example object might look as follows:

    public class RegisterModel
    {
        public string Email { get; set; }        
        public string Password { get; set; }
        public ushort Age { get; set ;}
    }

These are the validation criteria:

This is how you can handle such scenario using Valit:

        void ValidateModel(RegisterModel model)
        {
            var result = ValitRules<RegisterModel>
                .Create()
                .Ensure(m => m.Email, _=>_
                    .Required()
                    .Email())
                .Ensure(m => m.Password, _=>_ 
                    .Required()
                    .MinLength(10))
                .Ensure(m => m.Age, _=>_
                    .IsGreaterThan(16))
                .For(model)
                .Validate();

            if(result.Succeeded)
            {
                // do something on success
            }
            else 
            {
                // do something on failure
            }
        }

Pretty cool, right? Of course, the above example was fairly simple but trust us. From now on, even complicated validation criterias won't scare you anymore ;)

If you're looking for documentation, you can find it here.

Want to help us develop Valit? Awesome! Here you can find contributor guide ;)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4