Stronk.Validation.FluentValidation 1.0.0

FluentValidation extensions for Stronk.

Install-Package Stronk.Validation.FluentValidation -Version 1.0.0
dotnet add package Stronk.Validation.FluentValidation --version 1.0.0
<PackageReference Include="Stronk.Validation.FluentValidation" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Stronk.Validation.FluentValidation --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Use FluentValidation validators with Stronk.

public class Program
{
    public static void Main(string[] args)
    {
        var config = new StronkConfig()
            .Validate.With<ConfigurationValidator>()
            .Build<Configuration>();
    }
}

public class Configuration
{
    public TimeSpan Timeout { get; set; }
    public Uri Callback { get; set; }
}

public class ConfigurationValidator : AbstractValidator<Configuration>
{
    private const string[] Hosts = { "localhost", "internal" };

    public ConfigurationValidator()
    {
        var validHosts = new HashSet<string>(Hosts, StringComparer.OrdinalIgnoreCase);

        RuleFor(x => x.Timeout)
            .GreaterThan(TimeSpan.Zero)
            .LessThan(TimeSpan.FromMinutes(2));

        RuleFor(x => x.Callback)
            .Must(url => url.Scheme == Uri.UriSchemeHttps)
            .Must(url => validHosts.Contains(url.Host));
    }
}

A complete example can be seen in the Samples project.

Use FluentValidation validators with Stronk.

public class Program
{
    public static void Main(string[] args)
    {
        var config = new StronkConfig()
            .Validate.With<ConfigurationValidator>()
            .Build<Configuration>();
    }
}

public class Configuration
{
    public TimeSpan Timeout { get; set; }
    public Uri Callback { get; set; }
}

public class ConfigurationValidator : AbstractValidator<Configuration>
{
    private const string[] Hosts = { "localhost", "internal" };

    public ConfigurationValidator()
    {
        var validHosts = new HashSet<string>(Hosts, StringComparer.OrdinalIgnoreCase);

        RuleFor(x => x.Timeout)
            .GreaterThan(TimeSpan.Zero)
            .LessThan(TimeSpan.FromMinutes(2));

        RuleFor(x => x.Callback)
            .Must(url => url.Scheme == Uri.UriSchemeHttps)
            .Must(url => validHosts.Contains(url.Host));
    }
}

A complete example can be seen in the Samples project.

Version History

Version Downloads Last updated
1.0.0 121 9/7/2018