Nullean.Entities.ComponentModel 0.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Nullean.Entities.ComponentModel --version 0.4.0
                    
NuGet\Install-Package Nullean.Entities.ComponentModel -Version 0.4.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.ComponentModel" Version="0.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nullean.Entities.ComponentModel" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="Nullean.Entities.ComponentModel" />
                    
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.ComponentModel --version 0.4.0
                    
#r "nuget: Nullean.Entities.ComponentModel, 0.4.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.ComponentModel@0.4.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.ComponentModel&version=0.4.0
                    
Install as a Cake Addin
#tool nuget:?package=Nullean.Entities.ComponentModel&version=0.4.0
                    
Install as a Cake Tool

Nullean.Entities.ComponentModel

Nullean.Entities

NuGet

The rules your domain already has show up next to the field in your MVVM form, through INotifyDataErrorInfo.

Without this package, a desktop or mobile form repeats its validation in the view model, or in attributes, and drifts from the rules the domain enforces. This package runs your Nullean.Entities constraint set from the view model and reports each violation under the property it is about, through System.ComponentModel.INotifyDataErrorInfo: the interface Avalonia's and WPF's bindings read to draw an error next to a field.

It builds on Nullean.Entities and the BCL only: no UI-framework dependency, no reflection, trim and NativeAOT clean. It is optional and does not need the other integration packages.

Install

Targets net10.0 and net11.0.

dotnet add package Nullean.Entities
dotnet add package Nullean.Entities.ComponentModel

Get going

The domain value is immutable and declares its rules:

using Nullean.Entities;

public sealed partial record Signup(string Name, string Email, int Age)
{
	[Constraint]
	public static readonly Constraint<Signup> EmailHasAt = Constraints<Signup>.Check(
		s => s.Email.Contains('@') ? [] : [Violation.Error(nameof(Email), "Email needs an @")]
	);
}

The view model is mutable. ConstraintViewModel<T> builds the domain value from it (ToValue) and revalidates after every change:

using Nullean.Entities.ComponentModel;

public sealed class SignupViewModel() : ConstraintViewModel<Signup>(Signup.Constraints)
{
	private string _name = "";
	private string _email = "";
	private int _age;

	public string Name { get => _name; set => SetProperty(ref _name, value); }
	public string Email { get => _email; set => SetProperty(ref _email, value); }
	public int Age { get => _age; set => SetProperty(ref _age, value); }

	protected override Signup ToValue() => new(Name, Email, Age);
}

Bind as usual; nothing else to configure:

<TextBox Text="{Binding Email}" />

Type not-an-email and Avalonia 12 shows "Email needs an @" under the box (its INotifyDataErrorInfo plugin is on by default). Fix it and the error goes. WPF does the same through Validation.Errors.

Already on CommunityToolkit.Mvvm's ObservableObject, or a base of your own? Own a ConstraintErrors<T> and delegate INotifyDataErrorInfo to it; the docs page has the complete view model.

What you get

  • ConstraintErrors<T>(ConstraintSet<T> constraints, Func<T> current, object? sender = null, ConstraintErrorsOptions? options = null): an INotifyDataErrorInfo to own and delegate to. Validate() runs the set over current(); Validate(T previous) also runs the rules about a change (ConstraintSet<T>.Check), for an edit of an existing entity; Clear() forgets everything. ErrorsChanged is raised only for the properties whose messages changed, with sender as its sender.
  • GetErrors(property) returns the messages as strings; GetErrors(null) or GetErrors("") the entity-level ones (violations with no Member). GetViolations(property) and Violations return the Violations themselves.
  • ConstraintErrorsOptions: MinimumSeverity (errors only by default; Warning adds warnings), Members (domain member name to view-model property name, when they differ), Time (the TimeProvider for time-aware rules).
  • ConstraintViewModel<T>: an optional base with INotifyPropertyChanged, SetProperty, Validate(), and RunConstraints() to override (call Errors.Validate(original) when editing). HasErrors raises PropertyChanged when it flips.

Pitfalls and limits

  • Nothing is reported until the first change or Validate(), so an empty form is not red on open. After that every property is revalidated on every change: no "touched" tracking.
  • Validation is synchronous, on the UI thread, on every change. Keep the projection and the rules cheap; checks that need a database do not belong in constraints.
  • The projection must not throw: a half-typed form must still build a value.
  • A violation on a nested member (Address.City) is reported under that name; map it to the bound property name with Members.
  • INotifyDataErrorInfo has no severity: a warning you opt into shows like an error.
  • Tested against Avalonia 12.1.5 (headless, a real TextBox binding) and CommunityToolkit.Mvvm 8.4.2. WPF is not tested here. WinUI 3 and MAUI's stock controls do not draw INotifyDataErrorInfo errors themselves; call GetErrors from your own view.

Next

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 89 11/12/2026
0.4.0 91 11/11/2026
0.3.0 100 11/4/2026