ZeroAlloc.Notify.Generator 1.2.12

There is a newer version of this package available.
See the version list below for details.
dotnet add package ZeroAlloc.Notify.Generator --version 1.2.12
                    
NuGet\Install-Package ZeroAlloc.Notify.Generator -Version 1.2.12
                    
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="ZeroAlloc.Notify.Generator" Version="1.2.12">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroAlloc.Notify.Generator" Version="1.2.12" />
                    
Directory.Packages.props
<PackageReference Include="ZeroAlloc.Notify.Generator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 ZeroAlloc.Notify.Generator --version 1.2.12
                    
#r "nuget: ZeroAlloc.Notify.Generator, 1.2.12"
                    
#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 ZeroAlloc.Notify.Generator@1.2.12
                    
#: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=ZeroAlloc.Notify.Generator&version=1.2.12
                    
Install as a Cake Addin
#tool nuget:?package=ZeroAlloc.Notify.Generator&version=1.2.12
                    
Install as a Cake Tool

ZeroAlloc.Notify

NuGet Build License: MIT AOT GitHub Sponsors

ZeroAlloc.Notify is a source-generated notification library for .NET 8, .NET 10 and .NET Standard 2.0. It provides async-first property and collection change notifications without reflection or dynamic dispatch. The Roslyn source generator eliminates runtime overhead by wiring all dispatch at compile time — no virtual dispatch, fully awaitable handlers.

Install

The source generator is bundled into the main package — a single PackageReference is all you need:

dotnet add package ZeroAlloc.Notify

The standalone ZeroAlloc.Notify.Generator package is still published for backwards compatibility with existing direct PackageReferences, but new consumers should reference only ZeroAlloc.Notify.

Quick Example

using ZeroAlloc.Notify;

// 2. Subscribe to async notifications
var vm = new UserViewModel();
vm.PropertyChangedAsync += async (args, ct) =>
{
    Console.WriteLine($"Property '{args.PropertyName}' changed from {args.OldValue} to {args.NewValue}");
    await Task.Delay(100, ct); // Non-blocking handler execution
};

// 3. Set properties — fully awaitable
await vm.SetNameAsync("Alice");
await vm.SetAgeAsync(30);

// 1. Define a ViewModel with observable properties
[NotifyPropertyChangedAsync]
public partial class UserViewModel
{
    [ObservableProperty]
    private string _name = "";

    [ObservableProperty]
    private int _age;
}

Performance

ZeroAlloc.Notify provides async-first, fully awaitable handler dispatch — the only framework in this comparison where await vm.SetNameAsync(...) truly awaits all handlers. Refreshed benchmarks (.NET 10.0.12, i9-12900HK, BenchmarkDotNet v0.15.8, 5 attached handlers):

Library Time Allocated Async support
Manual INotifyPropertyChanged (baseline) 35.2 ns 24 B ❌
PropertyChanged.Fody 29.0 ns 0 B ❌
CommunityToolkit.Mvvm 50.2 ns 0 B ❌
ZeroAlloc.Notify 112.8 ns 40 B ✅

Honest framing: ZA.Notify is the slowest of the four and allocates. The 40 B is the event args object handed to the handlers: a sealed class carrying the old and new value as object?, so a value-type property also boxes both values, 88 B in all for an int. A change with no subscribers allocates nothing, because the args are created only when someone listens. An allocation-free args shape is planned for the next major version, see #237. For pure-sync view models, Fody is the right choice (fastest, 0 B). ZA.Notify is the only library here that supports async handlers; the trade-off is the cost of that capability. At 112.8 ns / 40 B per setter, it still scales to ~8.8M property changes per second per thread.

See docs/performance.md for detailed benchmark results and where each allocation comes from.

Features

  • Property Notifications — Strongly-typed, fully async PropertyChangedAsync events
  • Collection Changes — CollectionChangedAsync with observable property support
  • Data Validation — INotifyDataErrorInfoAsync for async error collection
  • Sequential & Parallel — [InvokeSequentially] attribute for handler ordering
  • Compiler Diagnostics — Missing handlers and misconfigurations caught at build time
  • Async-First — Fully awaitable ValueTask handlers; no fire-and-forget, no callbacks
  • Native AOT Compatible — No reflection at runtime; all dispatch resolved at compile time
  • Source Generated — Full type safety with compile-time verification

Documentation

Topic Description
Getting Started Install and send your first notification in five minutes
Observable Properties Defining and using observable properties
Async Notifications Property and collection changed notifications with await support
Collection Changes Observable collections with async event dispatch
Validation INotifyDataErrorInfoAsync with async error handling
Performance Zero-alloc internals, detailed benchmarks, Native AOT
Diagnostics ZAN001–ZAN006 source generator warnings and errors
Advanced Patterns Cancellation, scoped bindings, parallel handlers
Testing Unit-testing observable models and notification flows

Examples

samples/ZeroAlloc.Notify.AotSmoke is a runnable console app that exercises the generated setters and async property events; CI publishes it with Native AOT and runs it. For collection changes and validation, the Collection Changes and Validation guides have complete examples.

License

MIT. See LICENSE.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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
2.0.2 54 11/23/2026
2.0.1 58 11/22/2026
2.0.0 55 11/22/2026
1.3.1 92 11/17/2026
1.3.0 88 11/11/2026
1.2.14 103 10/22/2026
1.2.13 95 10/16/2026
1.2.12 104 10/15/2026
1.2.11 99 10/12/2026
1.2.10 94 10/11/2026
1.2.9 107 9/30/2026
1.2.8 101 9/28/2026
1.2.7 104 9/20/2026
1.2.6 112 9/20/2026
1.2.5 108 9/20/2026
1.2.4 113 9/19/2026
1.2.3 132 8/7/2026
1.2.2 134 5/13/2026
1.2.1 130 5/12/2026
1.2.0 125 5/3/2026
Loading failed