Assimalign.Extensions.Validation.Configurable 1.0.0-pre.1.0.4

Prefix Reserved
This is a prerelease version of Assimalign.Extensions.Validation.Configurable.
dotnet add package Assimalign.Extensions.Validation.Configurable --version 1.0.0-pre.1.0.4                
NuGet\Install-Package Assimalign.Extensions.Validation.Configurable -Version 1.0.0-pre.1.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Assimalign.Extensions.Validation.Configurable" Version="1.0.0-pre.1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Assimalign.Extensions.Validation.Configurable --version 1.0.0-pre.1.0.4                
#r "nuget: Assimalign.Extensions.Validation.Configurable, 1.0.0-pre.1.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Assimalign.Extensions.Validation.Configurable as a Cake Addin
#addin nuget:?package=Assimalign.Extensions.Validation.Configurable&version=1.0.0-pre.1.0.4&prerelease

// Install Assimalign.Extensions.Validation.Configurable as a Cake Tool
#tool nuget:?package=Assimalign.Extensions.Validation.Configurable&version=1.0.0-pre.1.0.4&prerelease                

Assimalign Extensions Validation configurable

This library offers an abstraction for implementing a custom configurable validator. With the available Assimalign Extensions library there is already a based implementation for implementing an XML and JSON configurable binary. However, there are some limitations to the available rules that can be implemented on a type.

Getting Started

Below is a quick start guide for implementing a custom Validation Configuration Provider. The provider

1. Build a Custom Validation Profile

First add a custom validation profile that can be configured when the IValidationConfigurableSource builds the provider.

public class ValidationConfigurableJsonProfile<T> : IValidationProfile
{
    public Type ValidationType { get; }

    public ValidationMode ValidationMode { get; }

    public IValidationItemStack ValidationItems { get; }

    public void Configure(IValidationRuleDescriptor descriptor) 
    {
        // Some logic for configuring the JSON Validation Profile
    }
}

2. Create a Configurable Validation Source for the custom Profile

public sealed class ValidationConfigurableJsonSource<T> : IValidationConfigurableSource
    where T : class
{
    private readonly Func<ValidationConfigurableJsonProfile<T>> configure;

    public ValidationConfigurableJsonSource(Func<ValidationConfigurableJsonProfile<T>> configure)
    {
        this.configure = configure;
    }

    public IValidationConfigurableProvider Build() =>
        new ValidationConfigurableJsonProvider<T>(configure.Invoke());
}

3. Create a Configurable Validation Provider to injest the source

Let's note that a IValidationConfigurableSource can have multiple providers. Depending on the scenerio there may be times when the source of the validation rules changes locations such as local development vs a API request to retrieve the validaiton rules.

public sealed class ValidationConfigurableJsonProvider<T> : IValidationConfigurableProvider
    where T : class
{
    private readonly ValidationConfigurableJsonProfile<T> profile;

    private ValidationConfigurableJsonProvider() { }

    internal ValidationConfigurableJsonProvider(ValidationConfigurableJsonProfile<T> profile)
    {
        this.profile = profile;
    }


    public IValidationProfile GetProfile() => this.profile;


    public bool TryGetProfile(Type type, out IValidationProfile profile)
    {
        if (type == typeof(T))
        {
            profile = this.profile;
            return true;
        }
        else
        {
            profile = null;
            return false;
        }
    }
}

4. Use the Configurable Validation Source to inject the provider

Now we should be able to build a configurable validator with our custom provider.

 var validator = ValidationConfigurableBuilder.Create()
        .Add(new ValidationConfigurableJsonSource<T>(() =>
        {
            return JsonSerializer.Deserialize<{Some Serialialzable Validation Profile}>(json);
        }))
        .ToValidator();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Assimalign.Extensions.Validation.Configurable:

Package Downloads
Assimalign.Extensions.Validation.Configurable.Json

This library implements a default

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-pre.1.0.4 133 6/16/2022
1.0.0-pre.1.0.3 118 5/23/2022
1.0.0-pre.1.0 116 5/23/2022