{"id":13431208,"url":"https://github.com/valit-stack/Valit","last_synced_at":"2025-03-16T11:31:18.079Z","repository":{"id":65414197,"uuid":"103189874","full_name":"valit-stack/Valit","owner":"valit-stack","description":"Valit is dead simple validation for .NET Core. No more if-statements all around your code. Write nice and clean fluent validators instead!","archived":false,"fork":false,"pushed_at":"2019-12-24T22:34:26.000Z","size":13003,"stargazers_count":322,"open_issues_count":11,"forks_count":26,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-10T08:04:11.768Z","etag":null,"topics":["core","dotnet","fluent-api","validation"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/valit-stack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-11T21:27:23.000Z","updated_at":"2024-11-02T13:40:49.000Z","dependencies_parsed_at":"2023-01-23T10:55:09.615Z","dependency_job_id":null,"html_url":"https://github.com/valit-stack/Valit","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valit-stack%2FValit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valit-stack%2FValit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valit-stack%2FValit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valit-stack%2FValit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/valit-stack","download_url":"https://codeload.github.com/valit-stack/Valit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243862783,"owners_count":20360210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["core","dotnet","fluent-api","validation"],"created_at":"2024-07-31T02:01:01.352Z","updated_at":"2025-03-16T11:31:17.407Z","avatar_url":"https://github.com/valit-stack.png","language":"C#","readme":"![Valit](https://avatars1.githubusercontent.com/u/32653478?s=200\u0026v=4)\n\nValit is **dead simple** validation for .NET Core. No more if-statements all around your code. Write nice and clean **fluent validators** instead! \n\n|   | master  | develop  |\n|---|--------|----------|\n|AppVeyor|[![Build status](https://ci.appveyor.com/api/projects/status/github/valit-stack/Valit?branch=master\u0026svg=true\u0026passingText=master%20passing\u0026failingText=master%20failing\u0026pendingText=master%20pending)](https://ci.appveyor.com/project/GooRiOn/valit/branch/master)|[![Build status](https://ci.appveyor.com/api/projects/status/github/valit-stack/Valit?branch=develop\u0026svg=true\u0026passingText=develop%20passing\u0026failingText=develop%20failing\u0026pendingText=develop%20pending)](https://ci.appveyor.com/project/GooRiOn/valit/branch/develop)|\n|Codecov|[![codecov](https://codecov.io/gh/valit-stack/valit/branch/master/graph/badge.svg)](https://codecov.io/gh/valit-stack/valit/branch/master)|[![codecov](https://codecov.io/gh/valit-stack/valit/branch/develop/graph/badge.svg)](https://codecov.io/gh/valit-stack/valit/branch/develop)|\n\n![NuGet](https://img.shields.io/nuget/v/Valit.svg)\n\n\n# Installation\nValit is available on [NuGet](https://www.nuget.org/packages/Valit/).\n\n### Package manager\n```bash\nInstall-Package Valit -Version 2.0.0\n```\n\n### .NET CLI\n```bash\ndotnet add package Valit --version 2.0.0\n```\n\n# Getting started\nIn 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: \n\n- creating new instance of validator using ``Create()`` static method.\n- choosing [validation strategy](http://valitdocs.readthedocs.io/en/latest/strategies/index.html) using ``WithStrategy()`` method **(not required)**.\n- selecting property using ``Ensure()`` method and defining rules for it. \n- Extending rules with [custom errors](http://valitdocs.readthedocs.io/en/latest/validation-errors/index.html) (such as messages or error codes), [tags and conditions](http://valitdocs.readthedocs.io/en/latest/validation-rules/index.html). **(not required)**.\n- applying created rules to an object using ``For()`` method.\n\nHaving the validator created, simply invoke ``Validate()`` method which will produce the result with all the data.\n\nLet'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:\n\n```cs\n\n    public class RegisterModel\n    {\n        public string Email { get; set; }        \n        public string Password { get; set; }\n        public ushort Age { get; set ;}\n    }\n```\n\nThese are the validation criteria:\n\n- ``Email`` is required and needs to be a proper email address\n- ``Password`` is required and needs to be at least 10 characters long\n- ``Age`` must be greater than 16\n\n\nThis is how you can handle such scenario using Valit:\n  \n```cs\n\n        void ValidateModel(RegisterModel model)\n        {\n            var result = ValitRules\u003cRegisterModel\u003e\n                .Create()\n                .Ensure(m =\u003e m.Email, _=\u003e_\n                    .Required()\n                    .Email())\n                .Ensure(m =\u003e m.Password, _=\u003e_ \n                    .Required()\n                    .MinLength(10))\n                .Ensure(m =\u003e m.Age, _=\u003e_\n                    .IsGreaterThan(16))\n                .For(model)\n                .Validate();\n\n            if(result.Succeeded)\n            {\n                // do something on success\n            }\n            else \n            {\n                // do something on failure\n            }\n        }\n```\n\nPretty 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 ;)\n\n# Documentation\nIf you're looking for documentation, you can find it [here](http://valitdocs.readthedocs.io/en/latest/index.html).\n\n# Contributing\nWant to help us develop Valit? Awesome! Here you can find [contributor guide](https://github.com/valit-stack/Valit/blob/develop/CONTRIBUTING.md) ;)\n","funding_links":[],"categories":["Frameworks, Libraries and Tools","框架, 库和工具","Misc","杂项"],"sub_categories":["Misc","大杂烩"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalit-stack%2FValit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalit-stack%2FValit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalit-stack%2FValit/lists"}