Obaki.DataChecker is a library that provides flexible validation of JSON and XML inputs through customizable rules, while allowing for custom validations using FluentValidation.
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.
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();
}
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);
}
}