ModelingEvolution.Observable 0.0.8.2

dotnet add package ModelingEvolution.Observable --version 0.0.8.2
                    
NuGet\Install-Package ModelingEvolution.Observable -Version 0.0.8.2
                    
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="ModelingEvolution.Observable" Version="0.0.8.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ModelingEvolution.Observable" Version="0.0.8.2" />
                    
Directory.Packages.props
<PackageReference Include="ModelingEvolution.Observable" />
                    
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 ModelingEvolution.Observable --version 0.0.8.2
                    
#r "nuget: ModelingEvolution.Observable, 0.0.8.2"
                    
#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 ModelingEvolution.Observable@0.0.8.2
                    
#: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=ModelingEvolution.Observable&version=0.0.8.2
                    
Install as a Cake Addin
#tool nuget:?package=ModelingEvolution.Observable&version=0.0.8.2
                    
Install as a Cake Tool

ModelingEvolution.Observable

Minimal MVVM primitives for .NET.

ObservableCollection<T> with Subscriber Tracking

ModelingEvolution.Observable.ObservableCollection<T> is a drop-in replacement for System.Collections.ObjectModel.ObservableCollection<T> that tracks how many handlers are attached to CollectionChanged and raises a SubscribersAvailable event on transitions:

  • 0 to 1 subscriber: SubscribersAvailable(true) — someone started watching
  • 1 to 0 subscribers: SubscribersAvailable(false) — nobody is watching anymore

The Problem

Read models in event-sourced systems often back expensive background services: ping monitors, streaming status trackers, polling loops. These services should only run while a UI is actually displaying the data. Without subscriber tracking, every page must manually call Subscribe() / Unsubscribe() in its lifecycle methods, coupling the view to service management:

// Every page that shows devices must do this:
protected override void OnInitialized()
{
    _pingMonitor.Subscribe();
    _cameraStatus.Subscribe();
}

public void Dispose()
{
    _pingMonitor.Unsubscribe();
    _cameraStatus.Unsubscribe();
}

This is error-prone (forget to unsubscribe = resource leak) and forces the view to know about services it shouldn't care about.

The Solution

The read model uses ModelingEvolution.Observable.ObservableCollection<T> for its Items collection and wires SubscribersAvailable in the constructor:

public class DevicesReadModel
{
    private readonly PingMonitor _pingMonitor;

    public ObservableCollection<DeviceItem> Items { get; }

    public DevicesReadModel(PingMonitor pingMonitor)
    {
        _pingMonitor = pingMonitor;
        Items = new ObservableCollection<DeviceItem>();
        Items.SubscribersAvailable += OnSubscribersAvailable;
    }

    private void OnSubscribersAvailable(bool available)
    {
        if (available)
            _pingMonitor.Subscribe();
        else
            _pingMonitor.Unsubscribe();
    }
}

The Blazor view simply binds to the collection. When <ObservableForEach> (or <Observable>) subscribes to Items.CollectionChanged, the read model detects it and starts its services. When the component disposes, it unsubscribes, and the read model stops its services. The view has zero knowledge of the background services:

@* No OnInitialized, no Dispose, no IDisposable. *@
@* ObservableForEach subscribes to CollectionChanged => services start automatically. *@

<ObservableForEach ItemSource="@ReadModel.Items"
                   IsNotifyPropertyChangedEnabled="true"
                   Context="device">
    <tr>
        <td>@device.Name</td>
        <td>@device.PingMs ms</td>
    </tr>
</ObservableForEach>

When to Use

Use ModelingEvolution.Observable.ObservableCollection<T> instead of the system ObservableCollection<T> when:

  • A collection backs expensive background work (polling, pinging, event hooks) that should only run while the data is being displayed
  • You want the read model to own its service lifecycle instead of leaking it to every consuming view
  • Multiple views may observe the same collection and the services should ref-count correctly (start on first viewer, stop when last viewer leaves)

API

namespace ModelingEvolution.Observable;

public class ObservableCollection<T> : Collection<T>, INotifyCollectionChanged, INotifyPropertyChanged
{
    // Raised on 0->1 (true) and 1->0 (false) CollectionChanged subscriber transitions.
    public event Action<bool>? SubscribersAvailable;

    // Everything else is identical to System.Collections.ObjectModel.ObservableCollection<T>.
}

Sorted Insertion

ObservableCollection<T> supports maintaining sorted order via binary search:

// Insert maintaining sorted order — uses IComparable<T> by default.
var items = new ObservableCollection<DeviceTypeInfo>();
items.InsertSorted(newItem);

// Or provide a custom comparer.
items.InsertSorted(newItem, Comparer<DeviceTypeInfo>.Create((a, b) => a.Name.CompareTo(b.Name)));

BinarySearch follows the same convention as List<T>.BinarySearch: it returns the zero-based index of the item if found, or the bitwise complement (~index) of the insertion point if not found.

int index = items.BinarySearch(target);
if (index < 0)
{
    int insertionPoint = ~index;
    // target not found — insertionPoint is where it would go
}
// Full signatures
public int BinarySearch(T item, IComparer<T>? comparer = null)
public void InsertSorted(T item, IComparer<T>? comparer = null)

ObservableCollectionView<T>

Filtered view over an IList<T> that implements INotifyCollectionChanged. Supports dynamic Filter predicate with automatic Merge() on filter change.

ObservableCollectionView<TDst, TSrc>

Transforming + filtering view. Maps TSrc to TDst (via IViewFor<TSrc>) with optional filtering. Propagates collection change notifications.

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ModelingEvolution.Observable:

Package Downloads
ModelingEvolution.Observable.Blazor

Minimal classes for Observable

ModelingEvolution.VideoStreaming.Ui

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.8.2 0 2/18/2026
0.0.8.1 0 2/18/2026
0.0.8 0 2/18/2026
0.0.7 106 2/8/2026
0.0.6.6 87 2/7/2026
0.0.6.5 92 2/7/2026
0.0.6.4 350 1/14/2026
0.0.5.4 1,481 4/30/2024
0.0.3.4 193 4/30/2024