{"id":14084,"date":"2023-10-18T06:06:40","date_gmt":"2023-10-18T06:06:40","guid":{"rendered":"https:\/\/positiwise.com\/blog\/?p=14084"},"modified":"2023-10-19T05:30:22","modified_gmt":"2023-10-19T05:30:22","slug":"fluentvalidation-in-net-core","status":"publish","type":"post","link":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core","title":{"rendered":"FluentValidation in .NET Core: A Complete Guide"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong class=\"pw-highlight-text-color\"><em>Quick Overview:<\/em><\/strong><br>The blog provides a detailed procedure to learn the use of FluentValidation in ASP.NET Core applications\/API. By following the process, you will create a demo project and verify the functioning of rules defined using FluentValidation. In addition, you will get exposure to the xUnit project. As a result, you will understand how FluentValidation works, its implementation, and testing in ASP.NET Core.<\/p><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#A_Run-Through_NET_Core_vs_Nodejs\" >A Run-Through: .NET Core vs Node.js<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#NET_Core\" >.NET Core<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Pros_of_using_NET_Core\" >Pros of using .NET Core<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Nodejs\" >Node.js<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#A_Deep_Dive_into_NET_Core_vs_Nodejs\" >A Deep Dive into .NET Core vs. Node.js<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Processing_Approach_and_Performance\" >Processing Approach and Performance<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Security\" >Security<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Scalability\" >Scalability<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Platform_Adaptability\" >Platform Adaptability<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Support_from_Community\" >Support from Community<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Comparison_Table_between_NET_Core_and_Nodejs\" >Comparison Table between .NET Core and Node.js<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Wrapping_Up_on_NET_Core_vs_Nodejs\" >Wrapping Up on .NET Core vs Node.js<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\">Implementing Validation in .NET Core with Use FluentValidation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Validation rules are considered one of the most reliable ways of controlling input. It helps the organizations to receive correct data from the users. Mostly, such validations are configured at forms for verifying input. Its primary aim is to ensure that company standards are met and that all records are in the same format.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ASP.NET Core applications are highly used for providing such functionalities, so it&#8217;s essential to configure best-in-class validation. By implementing FluentValidation in ASP.NET Core apps and APIs, you can effortlessly validate data to store only sensible information.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Read through this blog to understand What fluent validation is in .NET Core and how you can use it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is FluentValidation .NET Core?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">FluentValidation is one of the <a href=\"https:\/\/positiwise.com\/blog\/essential-net-core-libraries-that-every-programmer-should-know\">most popular .NET libraries<\/a> used to define validation rules in the .NET applications. Primarily, it\u2019s compatible and used with .NET Core 3.1, .NET 5, .NET 6, .NET Standard 2.0, and ASP.NET.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition, installing FluentValidation in your .NET project is quite an easy task. It can be installed using the NuGet package manager and command line interface. However, it&#8217;s preferred that you should use the latest Visual Studio version for using FluentValidation in ASP.NET Core applications.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Further, the FluentValidation library offers the following benefits:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It makes unit testing easy for developers.<\/li>\n\n\n\n<li>It helps to define centralized rules for validators.<\/li>\n\n\n\n<li>It provides errors rather than throwing exceptions.<\/li>\n\n\n\n<li>It follows the fail-fast principle.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">The Ways To Implement FluentValidation in ASP.NET Core<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In ASP.NET Core web applications and <a href=\"https:\/\/positiwise.com\/hire\/net-web-api-development\">ASP.NET Web API<\/a>, FluentValidation can be used by the following three approaches:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Manual Validation<\/li>\n\n\n\n<li>Automatic Validation<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Further, automatic validation is divided into two categories, as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Automatic Validation for applications with ASP.NET validation pipeline.<\/li>\n\n\n\n<li>Automatic Validation for applications using the filter.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In the manual validation method, the validator is inside the controller or at the API endpoint. It first invokes the validator and then processes the result. However, the functioning gets reversed in automatic validation, as models get validated before a controller invokes an action. Therefore, you should always analyze your requirements before selecting any of the validation approaches.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code Example To Configure FluentValidation in ASP Dot NET Core API<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s have a look at a practical example to learn about the working of FluentValidation in <a href=\"https:\/\/positiwise.com\/blog\/a-guide-to-building-web-apis-with-entity-framework-core-in-net-7\">ASP.NET Core Web API<\/a>. You can effortlessly follow this tutorial on your system by downloading the latest version of Visual Studio IDE.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After installing the IDE, open it and create a new project. You have to select the ASP.NET Core API template and fill out the required details to use it. In addition, you can also follow the below path for project creation:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>File &gt;&gt; New &gt;&gt; ASP.NET Core 3.1 API<\/em><\/strong>. (You should use the latest version of ASP.NET Core available on Visual Studio). Once the project gets created, its structure will display in Solutions Explorer, looking similar to the following snippet.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"274\" height=\"202\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/webapplication1-project.jpg\" alt=\"WebApplication1 Project\" class=\"wp-image-14116\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Further, to view what code this API template holds hit the combination of <strong><em>Ctrl+F5<\/em><\/strong>. It will run the API, and you will understand the working. Mainly, the API provides details about the weather forecast of upcoming days.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;\n  {\n    \"date\": \"2020-07-01T14:34:13.7180989+10:00\",\n    \"temperatureC\": 42,\n    \"temperatureF\": 107,\n    \"summary\": \"Bracing\"\n  },\n  {\n    \"date\": \"2020-07-02T14:34:13.7181617+10:00\",\n    \"temperatureC\": 31,\n    \"temperatureF\": 87,\n    \"summary\": \"Freezing\"\n  },\n  {\n    \"date\": \"2020-07-03T14:34:13.7181627+10:00\",\n    \"temperatureC\": 24,\n    \"temperatureF\": 75,\n    \"summary\": \"Scorching\"\n  },\n  {\n    \"date\": \"2020-07-04T14:34:13.7181632+10:00\",\n    \"temperatureC\": -17,\n    \"temperatureF\": 2,\n    \"summary\": \"Hot\"\n  },\n  {\n    \"date\": \"2020-07-05T14:34:13.7181636+10:00\",\n    \"temperatureC\": 52,\n    \"temperatureF\": 125,\n    \"summary\": \"Bracing\"\n  }\n]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To learn about FluentValidation, we will be adding a new API method, enabling the addition of a new forecast. For streamlining the procedure, we have divided it into easy-to-execute steps as below.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Open the WeatherForecastController.cs File<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Open the <strong><em>WeatherForecastController.cs file<\/em><\/strong>. Inside it, you will see a Get() method, which provides the weather forecast details to the user.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;HttpGet]\npublic IEnumerable&lt;WeatherForecast&gt; Get()\n{\n    var rng = new Random();\n    return Enumerable.Range(1, 5).Select(index =&gt; new WeatherForecast\n    {\n        Date = DateTime.Now.AddDays(index),\n        TemperatureC = rng.Next(-20, 55),\n        Summary = Summaries&#91;rng.Next(Summaries.Length)]\n    }).ToArray();\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Add a New Method<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add a new method in the file, similar to the following code block. The new method will return a &#8220;<strong><em>Success<\/em><\/strong>&#8221; string after accepting the WeatherForecast parameter.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;HttpPost]\npublic ActionResult Post(&#91;FromBody] WeatherForecast forecast)\n{\n    return Ok(\"Success!\");\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Test the New Method<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After adding a method, always test it before moving further. It ensures that the logic has been implemented correctly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To test the API, we will use the POSTMAN tool. After opening it, click on \u201cNew\u201d and define the below rules.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"308\" height=\"37\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/new-option.png\" alt=\"New Option\" class=\"wp-image-14115\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/new-option.png 308w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/new-option-300x36.png 300w\" sizes=\"auto, (max-width: 308px) 100vw, 308px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>HTTP verb should be <strong><em>POST<\/em><\/strong><\/li>\n\n\n\n<li>The URL should be <strong><em>http:\/\/localhost:61997\/weatherforecast<\/em><\/strong><\/li>\n\n\n\n<li>Content-Type header should have &#8220;<strong><em>application\/json<\/em><\/strong>&#8221; as the value<\/li>\n\n\n\n<li>The body type must be &#8220;<strong><em>JSON.<\/em><\/strong>&#8220;<\/li>\n\n\n\n<li>Configure the \u201c<strong><em>TemperatureC<\/em><\/strong>\u201d with a value of <strong><em>6000<\/em><\/strong> on the WeatherForecast model.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"645\" height=\"397\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/success-message.png\" alt=\"Success Message\" class=\"wp-image-14118\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/success-message.png 645w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/success-message-300x185.png 300w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Run the test case and ensure that it returns Success. As a result, now you have the leverage to add a new weather forecast to the output. However, we have used the temperature value 6000, which is exponentially high for any living organism.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, to pass only the appropriate temperature value, we will configure our API with FluentValidation. It will validate the temperature to a defined value, which is going to be 100 in our case. If the value is equal to or below 100, the Success string will be displayed as output. Otherwise, the user will see an error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s continue the procedure.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Configure FluentValidation Mechanism<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To configure the FluentValidation mechanism, we need its package. To download the package into your project, open the package manager console or NuGet package manager.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you use the package manager console, run the below command. Otherwise, you can search for \u201c<strong><em>FluentValidation.AspNetCore<\/em><\/strong>\u201d on the NuGet package manager and install it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PM&gt;&gt; install-package FluentValidation.AspNetCore<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After the installation, your ASP.NET Core API project will contain the necessary FluentValidation file and associated additional mechanisms.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Add a Validation Logic<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Under the WeatherForecast class, add a validation logic like the following code block.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class WeatherForecastValidator : AbstractValidator&lt;WeatherForecast&gt;\n{\n    public WeatherForecastValidator()\n    {\n        RuleFor(model =&gt; model.TemperatureC).LessThanOrEqualTo(100);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this code, the WeatherForecastValidator class is inherited from the <strong><em>AbstractValidator&lt;T&gt;<\/em><\/strong> class. It supports the FluentValidation mechanism to learn that the WeatherForecast class requires validation. Further, under the constructor, rules are specified to check TemperatureC to be equal to less than to value 100.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition, you can define as many rules as you want. But, to understand fundamentals, you should start from this only.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Test the FluentValidation Rule<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">As mentioned above, always test when you define something new in the code. In accordance with that, we will now test the FluentValidation rule that we defined in Step 5.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To test the validation, add a new .NET Core project called the xUnit Test Project.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"491\" height=\"94\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/xunit-test-project-net-core.jpg\" alt=\"xunit test project net core\" class=\"wp-image-14120\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/xunit-test-project-net-core.jpg 491w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/xunit-test-project-net-core-300x57.jpg 300w\" sizes=\"auto, (max-width: 491px) 100vw, 491px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">After the project creation, rename its \u201c<strong><em>UnitTest.cs<\/em><\/strong>\u201d file to \u201c<strong><em>WeatherForecastValidatorTests.cs.<\/em><\/strong>\u201d It\u2019s not necessary to rename the file, but it\u2019s always a best practice to do for better identification. Whenever some businesses <a href=\"https:\/\/positiwise.com\/hire-asp-net-developers\">hire dedicated .NET developers<\/a>, they also follow this practice to streamline testing and maintenance procedures.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 7: Add the Reference<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add the reference to the project through the Reference Manager. Firstly, provide a reference to the project named <strong><em>WebApplication1<\/em><\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"781\" height=\"179\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/reference-manager-xunittestproject1.jpg\" alt=\"reference manager xunittestproject1\" class=\"wp-image-14119\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/reference-manager-xunittestproject1.jpg 781w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/reference-manager-xunittestproject1-300x69.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/reference-manager-xunittestproject1-768x176.jpg 768w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step 8: Install .NET Packages<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Again, open the package manager and run the below-provided commands for installing required .NET packages. Primarily, we will be installing two packages, one for the FluentValidation library and the other for the xUnit Visual Studio test runner.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The command for FluentValidation installation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PM&gt;&gt; install-package FluentValidation\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The command for xUnit VS Test Runner:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PM&gt;&gt; install-package xunit.runner.visualstudio<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 9: Access the WeatherForecastValidatorTests.cs File<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After installation of both packages, access the <strong><em>WeatherForecastValidatorTests.cs<\/em><\/strong> file. Here, we\u2019ll be adding the test methods.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add the two statements below to the file. The first statement enables the use of test helpers, and the second defines a reference to the application, having the validator.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using FluentValidation.TestHelper;\nusing WebApplication1;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Further, under the <strong><em>WeatherForecastValidatorTests<\/em><\/strong> class, add the following code. Using it will create an instance for the validator, which will be used during testing.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>private readonly WeatherForecastValidator _validator = new WeatherForecastValidator();<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 10: Add the Logic to Test the Failing Validation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add the logic for testing the failing validation, extending from <strong><em>FluentValidation.TestHelper<\/em><\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Fact]\npublic void GivenAnInvalidTemperatureCValue_ShouldHaveValidationError()\n    =&gt; _validator.ShouldHaveValidationErrorFor(model =&gt; model.TemperatureC, 101);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The code contains three primary things. First is the property value, i.e., 101, in this tutorial. Second is the validator invoking, and third is causing the pass\/fail per the result.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 11: Add a Successful Validation Testing Method<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Include a method for successful validation testing by adding the below code. It enables the utilization of the xUnit theories, leading numerous values to pass the test.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Theory]\n&#91;InlineData(99)]\n&#91;InlineData(100)]\npublic void GivenAValidTemperatureCValue_ShouldNotHaveValidationError(int temperatureC)\n    =&gt; _validator.ShouldNotHaveValidationErrorFor(model =&gt; model.TemperatureC, temperatureC);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 12: Check the Functionality using Test Explorer<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to the <strong><em>Test Explorer<\/em><\/strong> to check the functionality of the validator. Run the tests to see the output as below. If your output is different and any test fails, check the configuration and again test.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"604\" height=\"215\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/run-all-tests.jpg\" alt=\"run all tests\" class=\"wp-image-14122\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/run-all-tests.jpg 604w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/run-all-tests-300x107.jpg 300w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As a result, we are able to test every individual property with the help of the FluentValidation mechanism. Till this step, we have created the logic and defined the rule for validation, which is working fine. And now, we will be adding it to our ASP.NET Core API.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 13: Configure Methods for .NET Versions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">At this step, the configuration differs for the .NET 5 or lower version and the .NET 6 and above version.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you are using .NET 5 or lower, open the <strong><em>Startup.cs file<\/em><\/strong>, and under the ConfigureServices method, add the below code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public void ConfigureServices(IServiceCollection services)\n{\n    services.AddControllers()\n            .AddFluentValidation(fv =&gt; fv.RegisterValidatorsFromAssemblyContaining&lt;WeatherForecastValidator&gt;());\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Further, if you are using the .NET 6 or above version, open the <strong><em>Program.cs<\/em><\/strong> file and modify it per the below snippet.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>builder.Services.AddControllers()\n    .AddFluentValidation(fv =&gt; fv.RegisterValidatorsFromAssemblyContaining&lt;WeatherForecastValidator&gt;());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">By doing this, the FluentValidation middleware gets activated in the ASP.NET Core application and API. It tells the mechanism to discover validators in the API.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 14: Test FluentValidation Configurations using the POSTMAN Tool<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Lastly, test all the <strong><em>FluentValidation<\/em><\/strong> configurations and their working in our API using the <strong><em>POSTMAN<\/em><\/strong> tool. Use the same rules defined in Step 3 and hit the send button.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"553\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/check-everything-works-fine.jpg\" alt=\"check everything works fine\" class=\"wp-image-14121\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/check-everything-works-fine.jpg 624w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/check-everything-works-fine-300x266.jpg 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This time, you will see an error for the TemperatureC value as 6000. It means that the FluentValidation is working correctly. However, don\u2019t end your testing here. Pass more values and verify the validation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the help of this approach or, more specifically, due to FluentValidation, the task of checking <strong><em>ModelState<\/em><\/strong> gets eliminated. All the validation work is completed automatically, providing the correct response to the user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Best ASP.NET Development Services For FluentValidation Implementation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Implementing validation in an ASP.NET Core app requires years of experience in the development domain. Only experts should be preferred for configuring FluentValidation and similar mechanisms in the software. The experts with 10+ years of experience understand how the validation should work and how to define a reliable logic. Moreover, they know the most appropriate way and test cases to verify the functioning. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to leverage all such benefits and expertise, outsource the ASP.NET masters from a globally trusted firm like Positiwise Software Pvt Ltd. It will help you affordably avail of <a href=\"https:\/\/positiwise.com\/technologies\/dot-net-development\">ASP.NET development services<\/a> and build a business application from scratch or modify the current software with relevant validation. In addition, always review the portfolio of the company and compare prices, customer reviews, and feedback before onboarding.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Concluding Up<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Concludingly, FluentValidation is a top-notch mechanism for ASP dot NET core API and applications. Its packages get installed within seconds, and it provides a streamlined way of defining rules. In addition, this validation method removes the additional task of model state viewing. All the validation finding and execution is completed automatically.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By following the above-defined procedure, you can efficiently learn the concept of FluentValidation in ASP.NET Core API. Also, you can use the same method and logic for your business applications. As a result of using FluentValidation, you will analyze lightweight controllers, easy-to-test and read validation rules, and improve model validation.<\/p>\n  <div class=\"related-post slider\">\r\n        <div class=\"headline\">Related Posts<\/div>\r\n    <div class=\"post-list owl-carousel\">\r\n\r\n            <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-java-technology\">\r\n\r\n      <img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"800\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1.jpg 1200w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-300x200.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-1024x683.jpg 1024w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-768x512.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-java-technology\">\r\n        .Net Core vs. Java \u2013 Which One You Should Use for Your Projects?  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Precise Road Map for ASP.NET Developers\" href=\"https:\/\/positiwise.com\/blog\/roadmap-for-asp-dot-net-developers\">\r\n\r\n      <img loading=\"lazy\" decoding=\"async\" width=\"1021\" height=\"621\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\"Hire ASP.NET Developers - A Precise Road Map to Employ ASP.NET Developers\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1.jpg 1021w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1-300x182.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1-768x467.jpg 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Precise Road Map for ASP.NET Developers\" href=\"https:\/\/positiwise.com\/blog\/roadmap-for-asp-dot-net-developers\">\r\n        Precise Road Map for ASP.NET Developers  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\".NET Core vs Node.js: The Difference Explained by Web Expert\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\">\r\n\r\n      <img loading=\"lazy\" decoding=\"async\" width=\"1021\" height=\"621\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/NET-Core-VS-Node-js-jpg.webp\" class=\"attachment-full size-full wp-post-image\" alt=\"NET-Core-VS-Node-js\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/NET-Core-VS-Node-js-jpg.webp 1021w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/NET-Core-VS-Node-js-300x182.webp 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/NET-Core-VS-Node-js-768x467.webp 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\".NET Core vs Node.js: The Difference Explained by Web Expert\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\">\r\n        .NET Core vs Node.js: The Difference Explained by Web Expert  <\/a>\r\n\r\n        <\/div>\r\n      \r\n  <\/div>\r\n\r\n  <script>\r\n      <\/script>\r\n  <style>\r\n    .related-post {}\r\n\r\n    .related-post .post-list {\r\n      text-align: left;\r\n          }\r\n\r\n    .related-post .post-list .item {\r\n      margin: 5px;\r\n      padding: 0px;\r\n          }\r\n\r\n    .related-post .headline {\r\n      font-size: 2rem !important;\r\n      color: #212529 !important;\r\n          }\r\n\r\n    .related-post .headline {\r\nmargin-top: 0;\r\npadding-left: 1%;\r\n}.related-post .post-list .item .post_thumb {\r\n      max-height: 220px;\r\n      margin: 0px 0px 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n          }\r\n\r\n    .related-post .post-list .item .post_title {\r\n      font-size: 1rem;\r\n      color: #212529;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .post-list .item .post_excerpt {\r\n      font-size: 13px;\r\n      color: #3f3f3f;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .owl-dots .owl-dot {\r\n          }\r\n\r\n      <\/style>\r\n      <script>\r\n      jQuery(document).ready(function($) {\r\n        $(\".related-post .post-list\").owlCarousel({\r\n          items: 3,\r\n          responsiveClass: true,\r\n          responsive: {\r\n            0: {\r\n              items: 1,\r\n            },\r\n            768: {\r\n              items: 2,\r\n            },\r\n            1200: {\r\n              items: 3,\r\n            }\r\n          },\r\n                      rewind: true,\r\n                                loop: true,\r\n                                center: true,\r\n                                autoplay: true,\r\n            autoplayHoverPause: true,\r\n                                nav: true,\r\n            navSpeed: 1000,\r\n            navText: ['<i class=\"fas fa-chevron-left\"><\/i>', '<i class=\"fas fa-chevron-right\"><\/i>'],\r\n                                dots: true,\r\n            dotsSpeed: 1200,\r\n                                                    rtl: false,\r\n          \r\n        });\r\n      });\r\n    <\/script>\r\n  <\/div>\r\n","protected":false},"excerpt":{"rendered":"<p>Quick Overview:The blog provides a detailed procedure to learn the use of FluentValidation in ASP.NET Core applications\/API. By [&hellip;]<\/p>\n  <div class=\"related-post slider\">\r\n        <div class=\"headline\">Related Posts<\/div>\r\n    <div class=\"post-list owl-carousel\">\r\n\r\n            <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-java-technology\">\r\n\r\n      <img width=\"1200\" height=\"800\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1.jpg 1200w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-300x200.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-1024x683.jpg 1024w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-768x512.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-java-technology\">\r\n        .Net Core vs. Java \u2013 Which One You Should Use for Your Projects?  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Precise Road Map for ASP.NET Developers\" href=\"https:\/\/positiwise.com\/blog\/roadmap-for-asp-dot-net-developers\">\r\n\r\n      <img width=\"1021\" height=\"621\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\"Hire ASP.NET Developers - A Precise Road Map to Employ ASP.NET Developers\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1.jpg 1021w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1-300x182.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1-768x467.jpg 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Precise Road Map for ASP.NET Developers\" href=\"https:\/\/positiwise.com\/blog\/roadmap-for-asp-dot-net-developers\">\r\n        Precise Road Map for ASP.NET Developers  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"A Descriptive Guide to .NET Framework\" href=\"https:\/\/positiwise.com\/blog\/a-descriptive-guide-to-dot-net-framework\">\r\n\r\n      <img width=\"1021\" height=\"621\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/a-descriptive-guide-to-dot-net-framework.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\"A Descriptive Guide to .NET Framework\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/a-descriptive-guide-to-dot-net-framework.jpg 1021w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/a-descriptive-guide-to-dot-net-framework-300x182.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/a-descriptive-guide-to-dot-net-framework-768x467.jpg 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"A Descriptive Guide to .NET Framework\" href=\"https:\/\/positiwise.com\/blog\/a-descriptive-guide-to-dot-net-framework\">\r\n        A Descriptive Guide to .NET Framework  <\/a>\r\n\r\n        <\/div>\r\n      \r\n  <\/div>\r\n\r\n  <script>\r\n      <\/script>\r\n  <style>\r\n    .related-post {}\r\n\r\n    .related-post .post-list {\r\n      text-align: left;\r\n          }\r\n\r\n    .related-post .post-list .item {\r\n      margin: 5px;\r\n      padding: 0px;\r\n          }\r\n\r\n    .related-post .headline {\r\n      font-size: 2rem !important;\r\n      color: #212529 !important;\r\n          }\r\n\r\n    .related-post .headline {\r\nmargin-top: 0;\r\npadding-left: 1%;\r\n}.related-post .post-list .item .post_thumb {\r\n      max-height: 220px;\r\n      margin: 0px 0px 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n          }\r\n\r\n    .related-post .post-list .item .post_title {\r\n      font-size: 1rem;\r\n      color: #212529;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .post-list .item .post_excerpt {\r\n      font-size: 13px;\r\n      color: #3f3f3f;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .owl-dots .owl-dot {\r\n          }\r\n\r\n      <\/style>\r\n      <script>\r\n      jQuery(document).ready(function($) {\r\n        $(\".related-post .post-list\").owlCarousel({\r\n          items: 3,\r\n          responsiveClass: true,\r\n          responsive: {\r\n            0: {\r\n              items: 1,\r\n            },\r\n            768: {\r\n              items: 2,\r\n            },\r\n            1200: {\r\n              items: 3,\r\n            }\r\n          },\r\n                      rewind: true,\r\n                                loop: true,\r\n                                center: true,\r\n                                autoplay: true,\r\n            autoplayHoverPause: true,\r\n                                nav: true,\r\n            navSpeed: 1000,\r\n            navText: ['<i class=\"fas fa-chevron-left\"><\/i>', '<i class=\"fas fa-chevron-right\"><\/i>'],\r\n                                dots: true,\r\n            dotsSpeed: 1200,\r\n                                                    rtl: false,\r\n          \r\n        });\r\n      });\r\n    <\/script>\r\n  <\/div>\r\n","protected":false},"author":3,"featured_media":14112,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-14084","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dot-net-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>FluentValidation in .NET Core: A Complete Guide<\/title>\n<meta name=\"description\" content=\"A complete guide to FluentValidation in .NET Core - validate models and input fluently with custom validation rules and error messages.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"FluentValidation in .NET Core: A Complete Guide\" \/>\n<meta property=\"og:description\" content=\"A complete guide to FluentValidation in .NET Core - validate models and input fluently with custom validation rules and error messages.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core\" \/>\n<meta property=\"og:site_name\" content=\"Positiwise\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/positiwise\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-18T06:06:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-19T05:30:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/fluentvalidation-in-net-core.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1021\" \/>\n\t<meta property=\"og:image:height\" content=\"621\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Parag Mehta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@positiwise\" \/>\n<meta name=\"twitter:site\" content=\"@positiwise\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Parag Mehta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/fluentvalidation-in-net-core#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/fluentvalidation-in-net-core\"},\"author\":{\"name\":\"Parag Mehta\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#\\\/schema\\\/person\\\/b4b3d9970ea94f5914a615f70345353a\"},\"headline\":\"FluentValidation in .NET Core: A Complete Guide\",\"datePublished\":\"2023-10-18T06:06:40+00:00\",\"dateModified\":\"2023-10-19T05:30:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/fluentvalidation-in-net-core\"},\"wordCount\":1910,\"publisher\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/fluentvalidation-in-net-core#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/fluentvalidation-in-net-core.jpg\",\"articleSection\":[\".NET Development\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2022\",\"copyrightHolder\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/fluentvalidation-in-net-core\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/fluentvalidation-in-net-core\",\"name\":\"FluentValidation in .NET Core: A Complete Guide\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/fluentvalidation-in-net-core#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/fluentvalidation-in-net-core#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/fluentvalidation-in-net-core.jpg\",\"datePublished\":\"2023-10-18T06:06:40+00:00\",\"dateModified\":\"2023-10-19T05:30:22+00:00\",\"description\":\"A complete guide to FluentValidation in .NET Core - validate models and input fluently with custom validation rules and error messages.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/fluentvalidation-in-net-core#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/positiwise.com\\\/blog\\\/fluentvalidation-in-net-core\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/fluentvalidation-in-net-core#primaryimage\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/fluentvalidation-in-net-core.jpg\",\"contentUrl\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/fluentvalidation-in-net-core.jpg\",\"width\":1021,\"height\":621,\"caption\":\"FluentValidation in .NET Core\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/fluentvalidation-in-net-core#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/positiwise.com\\\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"FluentValidation in .NET Core: A Complete Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/\",\"name\":\"Positiwise\",\"description\":\"Providing Full-cycle Software Development Services\",\"publisher\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#organization\"},\"alternateName\":\"Positiwise Software Pvt Ltd\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#organization\",\"name\":\"Positiwise\",\"alternateName\":\"Positiwise Software Pvt Ltd\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo.png\",\"contentUrl\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo.png\",\"width\":202,\"height\":29,\"caption\":\"Positiwise\"},\"image\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/positiwise\\\/\",\"https:\\\/\\\/x.com\\\/positiwise\",\"https:\\\/\\\/github.com\\\/positiwise\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/positiwise\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#\\\/schema\\\/person\\\/b4b3d9970ea94f5914a615f70345353a\",\"name\":\"Parag Mehta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g\",\"caption\":\"Parag Mehta\"},\"description\":\"Parag Mehta, the CEO and Founder of Positiwise Software Pvt Ltd has extensive knowledge of the development niche. He is implementing custom strategies to craft highly-appealing and robust applications for its clients and supporting employees to grow and ace the tasks. He is a consistent learner and always provides the best-in-quality solutions, accelerating productivity.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/paragcmehta\"],\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/author\\\/parag-mehta\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"FluentValidation in .NET Core: A Complete Guide","description":"A complete guide to FluentValidation in .NET Core - validate models and input fluently with custom validation rules and error messages.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core","og_locale":"en_US","og_type":"article","og_title":"FluentValidation in .NET Core: A Complete Guide","og_description":"A complete guide to FluentValidation in .NET Core - validate models and input fluently with custom validation rules and error messages.","og_url":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core","og_site_name":"Positiwise","article_publisher":"https:\/\/www.facebook.com\/positiwise\/","article_published_time":"2023-10-18T06:06:40+00:00","article_modified_time":"2023-10-19T05:30:22+00:00","og_image":[{"width":1021,"height":621,"url":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/fluentvalidation-in-net-core.jpg","type":"image\/jpeg"}],"author":"Parag Mehta","twitter_card":"summary_large_image","twitter_creator":"@positiwise","twitter_site":"@positiwise","twitter_misc":{"Written by":"Parag Mehta","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core#article","isPartOf":{"@id":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core"},"author":{"name":"Parag Mehta","@id":"https:\/\/positiwise.com\/blog\/#\/schema\/person\/b4b3d9970ea94f5914a615f70345353a"},"headline":"FluentValidation in .NET Core: A Complete Guide","datePublished":"2023-10-18T06:06:40+00:00","dateModified":"2023-10-19T05:30:22+00:00","mainEntityOfPage":{"@id":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core"},"wordCount":1910,"publisher":{"@id":"https:\/\/positiwise.com\/blog\/#organization"},"image":{"@id":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core#primaryimage"},"thumbnailUrl":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/fluentvalidation-in-net-core.jpg","articleSection":[".NET Development"],"inLanguage":"en-US","copyrightYear":"2022","copyrightHolder":{"@id":"https:\/\/positiwise.com\/blog\/#organization"}},{"@type":"WebPage","@id":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core","url":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core","name":"FluentValidation in .NET Core: A Complete Guide","isPartOf":{"@id":"https:\/\/positiwise.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core#primaryimage"},"image":{"@id":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core#primaryimage"},"thumbnailUrl":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/fluentvalidation-in-net-core.jpg","datePublished":"2023-10-18T06:06:40+00:00","dateModified":"2023-10-19T05:30:22+00:00","description":"A complete guide to FluentValidation in .NET Core - validate models and input fluently with custom validation rules and error messages.","breadcrumb":{"@id":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core#primaryimage","url":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/fluentvalidation-in-net-core.jpg","contentUrl":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/10\/fluentvalidation-in-net-core.jpg","width":1021,"height":621,"caption":"FluentValidation in .NET Core"},{"@type":"BreadcrumbList","@id":"https:\/\/positiwise.com\/blog\/fluentvalidation-in-net-core#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/positiwise.com\/blog"},{"@type":"ListItem","position":2,"name":"FluentValidation in .NET Core: A Complete Guide"}]},{"@type":"WebSite","@id":"https:\/\/positiwise.com\/blog\/#website","url":"https:\/\/positiwise.com\/blog\/","name":"Positiwise","description":"Providing Full-cycle Software Development Services","publisher":{"@id":"https:\/\/positiwise.com\/blog\/#organization"},"alternateName":"Positiwise Software Pvt Ltd","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/positiwise.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/positiwise.com\/blog\/#organization","name":"Positiwise","alternateName":"Positiwise Software Pvt Ltd","url":"https:\/\/positiwise.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/positiwise.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/07\/logo.png","contentUrl":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/07\/logo.png","width":202,"height":29,"caption":"Positiwise"},"image":{"@id":"https:\/\/positiwise.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/positiwise\/","https:\/\/x.com\/positiwise","https:\/\/github.com\/positiwise","https:\/\/www.linkedin.com\/company\/positiwise"]},{"@type":"Person","@id":"https:\/\/positiwise.com\/blog\/#\/schema\/person\/b4b3d9970ea94f5914a615f70345353a","name":"Parag Mehta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g","caption":"Parag Mehta"},"description":"Parag Mehta, the CEO and Founder of Positiwise Software Pvt Ltd has extensive knowledge of the development niche. He is implementing custom strategies to craft highly-appealing and robust applications for its clients and supporting employees to grow and ace the tasks. He is a consistent learner and always provides the best-in-quality solutions, accelerating productivity.","sameAs":["https:\/\/www.linkedin.com\/in\/paragcmehta"],"url":"https:\/\/positiwise.com\/blog\/author\/parag-mehta"}]}},"_links":{"self":[{"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/posts\/14084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/comments?post=14084"}],"version-history":[{"count":10,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/posts\/14084\/revisions"}],"predecessor-version":[{"id":14129,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/posts\/14084\/revisions\/14129"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/media\/14112"}],"wp:attachment":[{"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/media?parent=14084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/categories?post=14084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/tags?post=14084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}