![]() |
VOOZH | about |
dotnet add package ModelingEvolution.Observable --version 0.0.10
NuGet\Install-Package ModelingEvolution.Observable -Version 0.0.10
<PackageReference Include="ModelingEvolution.Observable" Version="0.0.10" />
<PackageVersion Include="ModelingEvolution.Observable" Version="0.0.10" />Directory.Packages.props
<PackageReference Include="ModelingEvolution.Observable" />Project file
paket add ModelingEvolution.Observable --version 0.0.10
#r "nuget: ModelingEvolution.Observable, 0.0.10"
#:package ModelingEvolution.Observable@0.0.10
#addin nuget:?package=ModelingEvolution.Observable&version=0.0.10Install as a Cake Addin
#tool nuget:?package=ModelingEvolution.Observable&version=0.0.10Install as a Cake Tool
Minimal MVVM primitives for .NET.
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:
SubscribersAvailable(true) — someone started watchingSubscribersAvailable(false) — nobody is watching anymoreRead 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 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>
Use ModelingEvolution.Observable.ObservableCollection<T> instead of the system
ObservableCollection<T> when:
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>.
}
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)
Filtered view over an IList<T> that implements INotifyCollectionChanged.
Supports dynamic Filter predicate with automatic Merge() on filter change.
Transforming + filtering view. Maps TSrc to TDst (via IViewFor<TSrc>)
with optional filtering. Propagates collection change notifications.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 3 NuGet packages that depend on ModelingEvolution.Observable:
| Package | Downloads |
|---|---|
|
ModelingEvolution.Ide
Package Description |
|
|
ModelingEvolution.Observable.Blazor
Minimal classes for Observable |
|
|
ModelingEvolution.VideoStreaming.Ui
Package Description |
This package is not used by any popular GitHub repositories.