Dryv 1.0.0-preview.1

This is a prerelease version of Dryv.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Dryv --version 1.0.0-preview.1
NuGet\Install-Package Dryv -Version 1.0.0-preview.1
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="Dryv" Version="1.0.0-preview.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Dryv --version 1.0.0-preview.1
#r "nuget: Dryv, 1.0.0-preview.1"
#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 Dryv as a Cake Addin
#addin nuget:?package=Dryv&version=1.0.0-preview.1&prerelease

// Install Dryv as a Cake Tool
#tool nuget:?package=Dryv&version=1.0.0-preview.1&prerelease

Dryv

NuGet NuGet

Overview

According to Rick Anderson, "One of the design tenets of MVC is DRY ("Don't Repeat Yourself")" and "The validation support provided by MVC and Entity Framework Core Code First is a good example of the DRY principle in action. You can declaratively specify validation rules in one place (in the model class) and the rules are enforced everywhere in the app"
(from Microsoft Docs).

While this is the case for simple validation rules, applying complex validations rules is a different story. For instance, see the foloowing model.

public class Customer
{
	[Required]
	public string Name { get; set; }

	public string Company { get; set; }

	public string TaxId { get; set; }
}

Using the annotation attributes provides by .NET, we can state that the Name property must be specified. ASP.NET MVC will render JavaScript code for us that performs model validation in the browser, and it will peroform server-side model validation in the controller. That's cool, certainly. But consider the following case: neither the company nor the tax ID fields are required at first. But if the user enters a company name, the tax ID field becomes required. How would you implement such a validation? The recommended way is to write an own validation attribute subclassing ValidationAttribute, make it implement IClientModelValidator, implement server side validation and add client-side code to implement a jQuery validator. Real-world application can have lots and lots of different validation rules and implementing them in C# as well as JavaScript can become a cumbersome task.

That's where Dryv comes in. The name "Dryv" is derived from the term "DRY Validation".Using Dryv, you define the rules using C# expressions and some inner magic will translate them to JavaScript. Taking teh example above, using Dryv it would look like this:

public class Customer
{
    public static readonly DryvRules Rules = DryvRules
        .For<Customer>()
        .Rule(m => m.TaxId,
            m => string.IsNullOrWhiteSpace(m.Company) || !string.IsNullOrWhiteSpace(m.TaxId)
                ? DryvResult.Success
                : $"The tax ID for {m.Company} must be specified.");

    [Required]
    public string Name { get; set; }

    public string Company { get; set; }

    [DryvRules]
    public string TaxId { get; set; }
}

In the code above, a set of rules for the class Customer is defined. This set of rules contains a rule for the property TaxId. The property TaxId has an attribute DryvRulesAttributes that makes Dryv play nicely with the ASP.NET MVC validation framework. On the client, you need to load the appropriate JavaScript implementation of Dryv. Currently, an implementation exists for jQuery unobtrusive. Other implementations (e.g. for VueJS or React) can easily be added (and will be over time).

Installation

Server

On the server, install the NuGet package:

dotnet add package Dryv 

... or ...

Install-Package Dryv 

... or ...

paket add Dryv 

Client

On the client, install the NPM package:

npm install --save dryv-jquery-unobtrusive 

... or download the JS file directly into your project and reference it from your page:

<script src="js/dryv-jquery-unobtrusive.min.js"></script>
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 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 Dryv:

Package Downloads
Dryv.AspNetCore

ASP.NET Core support for Dryv. Dryv provides complex model validation for server and client made easy. Write complex model validation rules in C# once. Dryv will generate JavaScript for client-side validation.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.0 14,565 10/3/2021
6.0.0-pre.40 10,589 4/20/2021
6.0.0-pre.38 396 4/14/2021
6.0.0-pre.37 168 3/17/2021
6.0.0-pre.36 620 3/17/2021
6.0.0-pre.35 1,449 1/20/2021
6.0.0-pre.34 2,229 10/30/2020
6.0.0-pre.29 319 9/27/2020
6.0.0-pre.28 259 9/25/2020
6.0.0-pre.27 275 9/17/2020
6.0.0-pre.26 1,196 8/1/2020
6.0.0-pre.25 237 7/31/2020
6.0.0-pre.24 313 7/31/2020
6.0.0-pre.23 233 7/30/2020
6.0.0-pre.22 289 7/29/2020
6.0.0-pre.21 328 7/29/2020
6.0.0-pre.20 275 7/28/2020
6.0.0-pre.19 276 7/27/2020
6.0.0-pre.18 341 7/26/2020
6.0.0-pre.17 275 7/25/2020
6.0.0-pre.16 243 7/23/2020
6.0.0-pre.15 243 7/22/2020
6.0.0-pre.14 266 7/22/2020
6.0.0-pre.13 272 7/20/2020
6.0.0-pre.12 241 7/20/2020
6.0.0-pre.11 229 7/20/2020
6.0.0-pre.10 220 7/17/2020
6.0.0-pre.9 323 7/16/2020
6.0.0-pre.8 304 7/16/2020
6.0.0-pre.7 236 7/15/2020
6.0.0-pre.6 284 7/10/2020
6.0.0-pre.5 275 7/9/2020
6.0.0-pre.4 247 7/8/2020
6.0.0-pre.3 257 7/7/2020
6.0.0-pre.2 267 7/5/2020
6.0.0-pre.1 257 7/2/2020
5.0.0 618 6/5/2020
4.0.0 536 5/16/2020
3.1.0 502 5/9/2020
3.0.1 884 4/17/2020
3.0.0 624 4/16/2020
2.0.0 1,248 5/14/2018
1.0.0 1,058 4/15/2018
1.0.0-preview.6 600 4/9/2018
1.0.0-preview.5 612 4/8/2018
1.0.0-preview.4 598 3/29/2018
1.0.0-preview.3 646 3/20/2018
1.0.0-preview.2 646 3/19/2018
1.0.0-preview.1 553 2/28/2018