Nullean.Entities.Blazor 0.5.0

dotnet add package Nullean.Entities.Blazor --version 0.5.0
                    
NuGet\Install-Package Nullean.Entities.Blazor -Version 0.5.0
                    
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="Nullean.Entities.Blazor" Version="0.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nullean.Entities.Blazor" Version="0.5.0" />
                    
Directory.Packages.props
<PackageReference Include="Nullean.Entities.Blazor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nullean.Entities.Blazor --version 0.5.0
                    
#r "nuget: Nullean.Entities.Blazor, 0.5.0"
                    
#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.
#:package Nullean.Entities.Blazor@0.5.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nullean.Entities.Blazor&version=0.5.0
                    
Install as a Cake Addin
#tool nuget:?package=Nullean.Entities.Blazor&version=0.5.0
                    
Install as a Cake Tool

Nullean.Entities.Blazor

Nullean.Entities

A Blazor form shows your domain rules under the right field, as the user types, with one line in the EditForm.

NuGet

Without this package, a Blazor form either repeats the domain's rules as DataAnnotations attributes or checks the model by hand in the submit handler and has no way to put the message under a field. This package adds <ConstraintValidator>, which checks an EditForm's model against a Nullean.Entities constraint set and writes the violations into the form's validation state, so <ValidationMessage For="..."> and <ValidationSummary> show them and OnValidSubmit waits until there are none.

It builds on Nullean.Entities and Microsoft.AspNetCore.Components.Forms; it does not need the other integration packages. It is optional, works in every render mode including WebAssembly, uses no reflection, and builds with the trim and AOT analyzers on.

Install

Targets net10.0 and net11.0.

dotnet add package Nullean.Entities
dotnet add package Nullean.Entities.Blazor

Quick start

A form model with its rules on it:

using Nullean.Entities;

public sealed partial class SignUp
{
	public string Email { get; set; } = "";
	public string Password { get; set; } = "";
	public string Confirm { get; set; } = "";

	[Constraint]
	public static readonly Constraint<SignUp> EmailLooksValid = Constraints<SignUp>.Check(
		s => s.Email.Contains('@') ? [] : [Violation.Error(nameof(Email), "Enter an email address")]
	);

	[Constraint]
	public static readonly Constraint<SignUp> ConfirmMatches = Constraints<SignUp>.Check(
		s => s.Confirm == s.Password ? [] : [Violation.Error(nameof(Confirm), "Must match the password")]
	);
}

And the form (add @using Nullean.Entities.Blazor here or in _Imports.razor):

<EditForm Model="Model" OnValidSubmit="Save">
	<ConstraintValidator Constraints="SignUp.Constraints" />

	<InputText @bind-Value="Model.Email" />
	<ValidationMessage For="() => Model.Email" />

	<InputText type="password" @bind-Value="Model.Password" />
	<InputText type="password" @bind-Value="Model.Confirm" />
	<ValidationMessage For="() => Model.Confirm" />

	<ValidationSummary />
	<button type="submit">Sign up</button>
</EditForm>

Type not-an-email and leave the field: "Enter an email address" appears under it, and nothing appears under the fields not reached yet. Submit with a mismatched confirmation: "Must match the password" appears under Confirm. Change Password to match, and that message goes away. Save runs once the model breaks no rule.

The value: the rule is written once, on the type, and the same set guards your API, your service layer and your generated tests. Change ConfirmMatches and the form follows.

What you get

  • ConstraintValidator<TModel>, used as <ConstraintValidator Constraints="..." /> (Razor infers TModel from the set):
    • Constraints (required): T.Constraints for a type that declares its own rules, or a companion's set such as ContactRules.All.
    • MinimumSeverity: Severity.Error (default) shows errors only; Severity.Warning adds warnings; Severity.Hint shows everything.
    • Time: a TimeProvider for rules that read the clock.
  • On submit, the whole model is checked. When a field changes, the set runs again, that field gets its current messages, and messages on other fields that no longer hold are removed.
  • A violation is shown on the field named by Violation.Member. One without a member is a model-level message, shown by <ValidationSummary>.

Pitfalls and limits

  • Give each violation a member (Violation.Error(nameof(Email), "...")), or it only shows in the summary.
  • Members match the form model's own properties. A dotted member (Address.City) shows in the summary, not in <ValidationMessage For="() => Model.Address.City">.
  • Blazor counts every shown message as invalid: a warning you choose to show also blocks OnValidSubmit.
  • Only point-in-time rules run. Rules over a change (Transitions, Monotonic) need a previous value; call Apply in the submit handler for those.
  • Constraints are synchronous and pure. Checks that need a server belong in the submit handler.
  • If the model already implements IValidatableObject over its constraints, Blazor's own <DataAnnotationsValidator /> reports them too; do not use both for the same rules, or each message shows twice.

Learn more

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0 69 11/12/2026
0.4.0 77 11/11/2026
0.3.0 98 11/4/2026