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.4 1,675 9/27/2024
6.0.3 1,236 8/19/2024
6.0.2 208 8/19/2024
6.0.1 171 7/25/2024
6.0.0 17,284 10/3/2021
6.0.0-pre.40 10,606 4/20/2021
6.0.0-pre.38 413 4/14/2021
6.0.0-pre.37 187 3/17/2021
6.0.0-pre.36 637 3/17/2021
6.0.0-pre.35 1,459 1/20/2021
6.0.0-pre.34 2,239 10/30/2020
6.0.0-pre.29 335 9/27/2020
6.0.0-pre.28 277 9/25/2020
6.0.0-pre.27 293 9/17/2020
6.0.0-pre.26 1,206 8/1/2020
6.0.0-pre.25 253 7/31/2020
6.0.0-pre.24 324 7/31/2020
6.0.0-pre.23 250 7/30/2020
6.0.0-pre.22 307 7/29/2020
6.0.0-pre.21 339 7/29/2020
6.0.0-pre.20 292 7/28/2020
6.0.0-pre.19 294 7/27/2020
6.0.0-pre.18 353 7/26/2020
6.0.0-pre.17 288 7/25/2020
6.0.0-pre.16 262 7/23/2020
6.0.0-pre.15 262 7/22/2020
6.0.0-pre.14 280 7/22/2020
6.0.0-pre.13 291 7/20/2020
6.0.0-pre.12 259 7/20/2020
6.0.0-pre.11 248 7/20/2020
6.0.0-pre.10 238 7/17/2020
6.0.0-pre.9 342 7/16/2020
6.0.0-pre.8 317 7/16/2020
6.0.0-pre.7 251 7/15/2020
6.0.0-pre.6 303 7/10/2020
6.0.0-pre.5 288 7/9/2020
6.0.0-pre.4 259 7/8/2020
6.0.0-pre.3 275 7/7/2020
6.0.0-pre.2 286 7/5/2020
6.0.0-pre.1 275 7/2/2020
5.0.0 650 6/5/2020
4.0.0 574 5/16/2020
3.1.0 542 5/9/2020
3.0.1 943 4/17/2020
3.0.0 665 4/16/2020
2.0.0 1,296 5/14/2018
1.0.0 1,089 4/15/2018
1.0.0-preview.6 611 4/9/2018
1.0.0-preview.5 621 4/8/2018
1.0.0-preview.4 614 3/29/2018
1.0.0-preview.3 661 3/20/2018
1.0.0-preview.2 657 3/19/2018
1.0.0-preview.1 569 2/28/2018