Skip to content

Latest commit

 

History

History
85 lines (64 loc) · 2.19 KB

README.md

File metadata and controls

85 lines (64 loc) · 2.19 KB

Obaki.DataChecker

NuGet NuGet Downloads

Obaki.DataChecker is a library that provides flexible validation of JSON and XML inputs through customizable rules, while allowing for custom validations using FluentValidation.

Installing

To install the package add the following line inside your csproj file with the latest version.

<PackageReference Include="Obaki.DataChecker" Version="x.x.x" />

An alternative is to install via the .NET CLI with the following command:

dotnet add package Obaki.DataChecker

For more information you can check the nuget package.

Setup

Register the needed services in your Program.cs file as Scoped

public void ConfigureServices(IServiceCollection services)
{
    services.AddDataCheckerAsScoped();
}

Or as Singleton

public void ConfigureServices(IServiceCollection services)
{
    services.AddDataCheckerAsSingleton();
}

Usage

Asynchronous(Non-Blocking)

using FluentValidation.Results;
using FluentValidation;
using Obaki.DataChecker;


public class TestAsync {
    private readonly IXmlDataChecker<TestObject> _xmlDataChecker;

    public TestAsync(IXmlDataChecker<TestObject> xmlDataChecker) 
    {
          _xmlDataChecker = xmlDataChecker;
    }

   public async Task<ValidationResult> ValidateTestObject(string xmlInput)
   {

          return await _xmlDataChecker.ValidateXmlDataFromStringAsync(xmlInput);
   }
}

Synchronous(Blocking)

using FluentValidation.Results;
using FluentValidation;
using Obaki.DataChecker;


public class TestSync {
   private readonly IXmlDataChecker<TestObject> _xmlDataChecker;

    public TestAsync(IXmlDataChecker<TestObject> xmlDataChecker) 
    {
          _xmlDataChecker = xmlDataChecker;
    }

   public ValidationResult ValidateTestObject(string xmlInput)
   {

          return  _xmlDataChecker.ValidateXmlDataFromString(xmlInput);
   }
}