Assimalign.Extensions.Validation.Configurable
1.0.0-pre.1.0.4
Prefix Reserved
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
<PackageReference Include="Assimalign.Extensions.Validation.Configurable" Version="1.0.0-pre.1.0.4" />
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"
// 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 | Versions 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. |
-
net6.0
- Assimalign.Extensions.Validation (>= 1.0.0-pre.1.0.4)
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 | 144 | 6/16/2022 |
1.0.0-pre.1.0.3 | 127 | 5/23/2022 |
1.0.0-pre.1.0 | 132 | 5/23/2022 |