![]() |
VOOZH | about |
dotnet add package RxBlazorV2 --version 1.2.5
NuGet\Install-Package RxBlazorV2 -Version 1.2.5
<PackageReference Include="RxBlazorV2" Version="1.2.5" />
<PackageVersion Include="RxBlazorV2" Version="1.2.5" />Directory.Packages.props
<PackageReference Include="RxBlazorV2" />Project file
paket add RxBlazorV2 --version 1.2.5
#r "nuget: RxBlazorV2, 1.2.5"
#:package RxBlazorV2@1.2.5
#addin nuget:?package=RxBlazorV2&version=1.2.5Install as a Cake Addin
#tool nuget:?package=RxBlazorV2&version=1.2.5Install as a Cake Tool
๐ .NET
๐ NuGet
๐ Build and Test
๐ GitHub Repo stars
A reactive programming framework for Blazor applications built on top of R3 (Reactive Extensions). RxBlazorV2 uses Roslyn source generators to automatically create observable models with reactive property bindings, command patterns, and dependency injection support.
Live demos: Reactive patterns ยท MudBlazor components
Breaking changes in 1.2.x โ ComponentTriggerType has been removed. All existing [ObservableComponentTrigger] usages must be reviewed. See Breaking Changes below for the cleanup checklist.
New in 1.2.x (non-breaking) โ cancellation token on OnContextReadyAsync, plus swipe + sort list components in RxBlazorV2.MudBlazor. See What's New below.
The following are non-breaking additions โ existing code continues to compile and run unchanged.
OnContextReadyAsync(CancellationToken) overloadBoth ObservableModel and ObservableComponent<T> now expose a cancellation-aware OnContextReadyAsync(CancellationToken) virtual. The token is cancelled when the model or component is disposed, so async initialization work (e.g. await Task.Delay(...) before flipping a property) aborts cleanly instead of writing to a torn-down R3 subject after navigation.
The existing parameterless OnContextReadyAsync() keeps working โ the new virtual delegates to it by default. Opt in by switching the override signature only where you actually need cancellation:
// Existing override โ still works, no changes required
protected override Task OnContextReadyAsync()
{
PreferredFormat = Storage.PreferredFormat;
return Task.CompletedTask;
}
// New override โ cancellation token bound to disposal
protected override async Task OnContextReadyAsync(CancellationToken cancellationToken)
{
await Task.Delay(3000, cancellationToken); // OperationCanceledException on dispose
IndirectUsageReady = true; // never runs after navigation away
}
RxBlazorV2.MudBlazorTwo reactive list components for iOS-Mail-style swipe actions and drag-to-reorder:
MudSwipeoutRx<TItem> โ row with reveal-on-swipe action panels (up to 3 per side), overswipe-to-fire, swipe-to-delete. Standalone โ does not require a sortable list around it.MudSortableSwipeoutListRx<TItem> โ sortable list with three activation modes (drag-handle, tap-hold, whole-row), cross-list groups (SortableGroup with move / clone / drag-out-to-remove semantics), edge auto-scroll, real-time grow/shrink of the dropzone.Single ESM gesture engine: Pointer Events for mouse / pen, Touch Events for finger input (touchmove non-passive so preventDefault reliably wins the gesture against the browser scroll heuristic on iOS Safari and Android Chrome).
See the dedicated for full API, usage examples, the touch-action trade-off, and live screenshots in the sample app (/sortable, /contacts, /notifications).
ComponentTriggerType RemovedThe ComponentTriggerType enum (RenderAndHook, RenderOnly, HookOnly) has been removed. [ObservableComponentTrigger] and [ObservableComponentTriggerAsync] now only generate hook methods โ they never control rendering.
Why: Rendering is always handled by the reactive pipeline through properties referenced in razor. The enum was either redundant (property in razor already re-renders) or an anti-pattern (forcing re-render for properties not in razor).
Cleanup checklist:
[ObservableComponentTrigger(ComponentTriggerType.RenderOnly)] attribute entirely. These never produced a hook โ their only job was to force a re-render, which the reactive pipeline now handles automatically. The attribute is redundant.HookOnly and RenderAndHook variants, check whether the generated hook is actually used. Search the component for overrides of the generated On{Property}Changed() / On{Property}ChangedAsync() method. If no override exists or the override is empty, remove the attribute. If the hook is used, keep the attribute and drop the enum argument.Migration:
| Before | After |
|---|---|
[ObservableComponentTrigger] |
[ObservableComponentTrigger] (unchanged) |
[ObservableComponentTrigger(ComponentTriggerType.RenderOnly)] |
Remove the attribute entirely |
[ObservableComponentTrigger(ComponentTriggerType.RenderAndHook)] |
[ObservableComponentTrigger] (only if hook is used) |
[ObservableComponentTrigger(ComponentTriggerType.HookOnly)] |
[ObservableComponentTrigger] (only if hook is used) |
[ObservableComponentTrigger(ComponentTriggerType.HookOnly, hookMethodName: "X")] |
[ObservableComponentTrigger("X")] (only if hook is used) |
[ObservableComponentTriggerAsync(ComponentTriggerType.HookOnly)] |
[ObservableComponentTriggerAsync] (only if hook is used) |
ObservableCollection Code Fix Uses private initRXBG042 (non-observable collection) code fix now generates private init instead of init for collection properties. This aligns with latest Roslyn analyzer recommendations.
The generic [ObservableTrigger<T>] and [ObservableTriggerAsync<T>] attributes have been removed. Use these alternatives instead:
| Removed | Replacement |
|---|---|
[ObservableTrigger<T>(method, param)] |
[ObservableModelObserver] on service methods |
[ObservableTriggerAsync<T>(method, param)] |
[ObservableModelObserver] with async signature |
Note: The non-generic
[ObservableTrigger]and[ObservableTriggerAsync]attributes for internal method execution are still available.
For internal model observers that react to referenced model changes, use the auto-detection pattern:
[ObservableModelScope(ModelScope.Scoped)]
public partial class MyModel : ObservableModel
{
public partial MyModel(SettingsModel settings);
// Auto-detected: private void method accessing Settings properties
private void OnThemeChanged()
{
// Automatically subscribed to Settings.Theme changes
ApplyTheme(Settings.Theme);
}
// Async version with CancellationToken
private async Task OnLanguageChangedAsync(CancellationToken ct)
{
await LoadLocalizationAsync(Settings.Language, ct);
}
}
For external services, use [ObservableModelObserver]:
public class ThemeService
{
[ObservableModelObserver(nameof(SettingsModel.Theme))]
private void OnThemeChanged(SettingsModel model)
{
ApplyGlobalTheme(model.Theme);
}
}
IErrorModel[ObservableComponent]dotnet add package RxBlazorV2
The package includes the source generator and code fixes automatically.
| Package | Description |
|---|---|
| RxBlazorV2.MudBlazor | Reactive MudBlazor components: command-bound buttons / icon buttons / FABs with progress + cancellation + confirmation dialogs, status display, and swipe + sort list components (MudSwipeoutRx, MudSortableSwipeoutListRx). See its . |
[ObservableModelScope(ModelScope.Scoped)]
[ObservableComponent]
public partial class CounterModel : ObservableModel
{
public partial int Count { get; set; }
[ObservableCommand(nameof(Increment))]
public partial IObservableCommand IncrementCommand { get; }
private void Increment() => Count++;
}
@page "/counter"
@inherits CounterModelComponent
<p>Count: @Model.Count</p>
<button @onclick="() => Model.IncrementCommand.Execute()">Increment</button>
Properties marked as partial with both getter and setter are automatically enhanced with change notifications, value equality checks, and integration with the reactive observable stream.
public partial class MyModel : ObservableModel
{
public partial string Name { get; set; } = "Default";
public partial int Count { get; set; }
}
Commands link UI actions to model methods with automatic CanExecute tracking.
| Interface | Description |
|---|---|
IObservableCommand |
Sync, no parameters |
IObservableCommand<T> |
Sync with parameter |
IObservableCommandAsync |
Async, no parameters |
IObservableCommandAsync<T> |
Async with parameter and cancellation |
IObservableCommandR<T> |
Sync with return value |
IObservableCommandR<T1, T2> |
Sync with parameter and return value |
IObservableCommandRAsync<T> |
Async with return value |
IObservableCommandRAsync<T1, T2> |
Async with parameter and return value |
[ObservableCommand(nameof(Save), nameof(CanSave))]
public partial IObservableCommandAsync SaveCommand { get; }
[ObservableCommand(nameof(Calculate))]
public partial IObservableCommandR<int> CalculateCommand { get; }
private async Task Save() { /* ... */ }
private bool CanSave() => !string.IsNullOrEmpty(Name);
private int Calculate() => Count * 2;
IErrorModel)Commands automatically capture exceptions and route them to an IErrorModel implementation for centralized error handling:
// Implement IErrorModel in your error handling model
[ObservableModelScope(ModelScope.Singleton)]
public partial class ErrorModel : ObservableModel, IErrorModel
{
[ObservableComponentTrigger]
public ObservableList<string> Errors { get; } = [];
public void HandleError(Exception error)
{
Errors.Add(error.Message);
}
}
// Any model that injects IErrorModel gets automatic error capture
[ObservableModelScope(ModelScope.Scoped)]
public partial class MyModel : ObservableModel
{
public partial MyModel(IErrorModel errorModel);
[ObservableCommand(nameof(DoRiskyOperation))]
public partial IObservableCommandAsync RiskyCommand { get; }
private async Task DoRiskyOperation()
{
// If this throws, the exception is automatically
// captured and sent to ErrorModel.HandleError()
await _service.DoSomethingAsync();
}
}
Key Points:
IErrorModel via partial constructor to enable automatic error captureHandleError(Exception) methodRxBlazorV2.MudBlazor.StatusDisplay for automatic UI feedbackA third positional argument on [ObservableCommand] names a method that maps an
Exception to a user-facing string. When the command body throws, the framework
invokes the formatter, then always populates Command.Error (the raw exception)
and Command.ErrorMessage (the formatted text), and also forwards the formatted
text to a configured StatusBaseModel. Cryptic ex.Message strings never reach the
user โ your formatter rewrites them.
[ObservableCommand(nameof(LoadContactsAsync), nameof(CanLoad), nameof(FormatLoadError))]
public partial IObservableCommandAsync LoadContactsCommand { get; }
private async Task LoadContactsAsync(CancellationToken ct) { /* no try/catch */ }
// Required signature: string Method(Exception). Instance or static, any accessibility.
private string FormatLoadError(Exception ex) => ex switch
{
HttpRequestException http => $"Network error loading contacts: {http.Message}",
TimeoutException => "The data service is unreachable. Try again.",
_ => $"Failed to load contacts: {ex.Message}",
};
Key Points:
Command.ErrorMessage; render the global status
log from StatusBaseModel.Messages โ the consumer chooses which surface(s) to renderOperationCanceledException from a CancellationToken is intercepted by the
cancelable factory and never reaches the formatterstring Method(Exception))Models can reference and react to changes in other models through the partial constructor pattern:
[ObservableModelScope(ModelScope.Scoped)]
public partial class ShoppingCartModel : ObservableModel
{
// Declare dependencies via partial constructor
public partial ShoppingCartModel(ProductCatalogModel catalog, ILogger logger);
// Generator creates:
// - protected ProductCatalogModel Catalog { get; } with auto-subscription
// - private readonly ILogger _logger field
public partial decimal Total { get; set; }
private void RecalculateTotal()
{
Total = Quantity * Catalog.Price; // Access referenced model
}
}
Key Points:
protected properties with auto-subscriptionprivate readonly fields with underscore prefixUse [ObservableComponent] to generate a Blazor component base class:
[ObservableModelScope(ModelScope.Scoped)]
[ObservableComponent] // Generates MyModelComponent
public partial class MyModel : ObservableModel
{
public partial string Title { get; set; }
}
@page "/mypage"
@inherits MyModelComponent
<h1>@Model.Title</h1>
Options:
componentName: Custom component class name (default: {ModelName}Component)includeReferencedTriggers: Include triggers from referenced models (default: true)RxBlazorV2 provides multiple trigger types for different reactive scenarios:
Generate hook methods in components for property changes:
[ObservableComponent]
public partial class SettingsModel : ObservableModel
{
// Generates OnThemeChanged() hook in component
[ObservableComponentTrigger]
public partial string Theme { get; set; }
// Async hook with custom name
[ObservableComponentTriggerAsync("HandleDarkModeToggle")]
public partial bool IsDarkMode { get; set; }
// Hook for code-behind logic
[ObservableComponentTrigger]
public partial string BackgroundTask { get; set; }
}
Triggers only generate hook methods โ rendering is always handled by the reactive pipeline through properties referenced in razor.
Execute internal methods automatically when properties change:
public partial class ValidationModel : ObservableModel
{
[ObservableTrigger(nameof(ValidateEmail))]
public partial string Email { get; set; }
[ObservableTriggerAsync(nameof(SaveAsync), nameof(CanSave))]
public partial string Data { get; set; }
private void ValidateEmail() { /* validation */ }
private async Task SaveAsync() { /* save */ }
private bool CanSave() => !string.IsNullOrEmpty(Data);
}
Auto-execute commands when properties change:
public partial class SearchModel : ObservableModel
{
public partial string Query { get; set; }
[ObservableCommand(nameof(Search))]
[ObservableCommandTrigger(nameof(Query))]
public partial IObservableCommandAsync SearchCommand { get; }
private async Task Search() { /* search logic */ }
}
Define reactive contracts in abstract base classes with attribute transfer to concrete implementations:
// Abstract base class defines the contract with reactive attributes
public abstract class StatusBaseModel : ObservableModel
{
[ObservableComponentTrigger]
public abstract ObservableList<StatusMessage> Messages { get; }
[ObservableComponentTrigger]
[ObservableTrigger(nameof(CanAddMessageTrigger))]
public abstract bool CanAddMessage { get; set; }
[ObservableCommandTrigger(nameof(CanAddMessage))]
public abstract IObservableCommand AddMessageCommand { get; }
protected abstract void CanAddMessageTrigger();
}
// Concrete class - attributes are automatically transferred from base
[ObservableComponent]
[ObservableModelScope(ModelScope.Singleton)]
public partial class AppStatusModel : StatusBaseModel
{
public override ObservableList<StatusMessage> Messages { get; } = [];
public override partial bool CanAddMessage { get; set; }
[ObservableCommand(nameof(AddMessage))]
public override partial IObservableCommand AddMessageCommand { get; }
protected override void CanAddMessageTrigger() { /* ... */ }
private void AddMessage() { /* ... */ }
}
Key Points:
override partial - attributes are automatically transferred[ObservableComponentTrigger], [ObservableTrigger], [ObservableCommandTrigger] all transferoverride modifier in generated codePrivate methods that read referenced model properties are automatically detected and subscribed. No special naming convention required - the generator analyzes which properties are actually accessed:
[ObservableModelScope(ModelScope.Scoped)]
public partial class ShoppingCartModel : ObservableModel
{
public partial ShoppingCartModel(ProductCatalogModel catalog);
[ObservableTrigger(nameof(RecalculateTotal))]
public partial int Quantity { get; set; }
public partial decimal Total { get; set; }
// This method is BOTH a property trigger AND an internal observer:
// - Called when Quantity changes (via [ObservableTrigger])
// - Called when Catalog.Price changes (auto-detected read)
private void RecalculateTotal()
{
Total = Quantity * Catalog.Price;
}
}
Valid Signatures:
private void MethodName()private Task MethodName() or private Task MethodName(CancellationToken ct)Key Points:
Allow external services to observe model changes using [ObservableModelObserver]:
public class NotificationService
{
public NotificationService(UserModel userModel)
{
// Service is injected into model constructor
}
[ObservableModelObserver(nameof(UserModel.UnreadCount))]
private void OnUnreadCountChanged(UserModel model)
{
UpdateBadge(model.UnreadCount);
}
[ObservableModelObserver(nameof(UserModel.Status))]
private async Task OnStatusChangedAsync(UserModel model, CancellationToken ct)
{
await SyncStatusAsync(model.Status, ct);
}
}
Group property changes for single notifications:
public partial class FormModel : ObservableModel
{
[ObservableBatch("userInfo")]
public partial string FirstName { get; set; }
[ObservableBatch("userInfo")]
public partial string LastName { get; set; }
public void UpdateUser(string first, string last)
{
using (SuspendNotifications("userInfo"))
{
FirstName = first;
LastName = last;
} // Single notification fired here
}
}
| Attribute | Target | Description |
|---|---|---|
[ObservableModelScope] |
Class | DI lifetime (Singleton, Scoped, Transient) |
[ObservableComponent] |
Class | Generate component base class |
[ObservableCommand] |
Property | Link command to implementation method |
[ObservableComponentTrigger] |
Property | Generate component hook (sync) |
[ObservableComponentTriggerAsync] |
Property | Generate component hook (async) |
[ObservableTrigger] |
Property | Execute method on change (sync) |
[ObservableTriggerAsync] |
Property | Execute method on change (async) |
[ObservableCommandTrigger] |
Property | Auto-execute command on property change |
[ObservableModelObserver] |
Method | Subscribe service method to model property changes |
[ObservableBatch] |
Property | Group for batched notifications |
Key Design Principles:
field keyword)See the RxBlazorV2Sample project for comprehensive, interactive examples โ live at b-straub.github.io/RxBlazorV2/:
| Sample | Description |
|---|---|
| BasicCommands | Sync/async commands and observable properties |
| BasicCommandWithReturn | Commands that return values |
| ParameterizedCommands | Commands with type-safe parameters |
| CommandsWithCanExecute | Conditional command execution |
| CommandsWithCancellation | Long-running async with cancellation |
| ErrorHandling | Automatic error capture via IErrorModel |
| CommandTriggers | Auto-execute commands on property changes |
| ComponentTriggers | Component hooks for property changes |
| PropertyTriggers | Internal method execution on changes |
| ModelObservers | External and internal service subscriptions |
| ModelReferences | Cross-model reactive subscriptions |
| ModelPatterns | Partial constructor pattern examples |
| GenericModels | Generic observable models with DI |
| ObservableBatches | Batched property notifications |
| ValueEquality | Automatic value equality |
| CrossComponentCommunication | Share models across components |
| InternalModelObservers | Auto-detected private methods reacting to referenced model changes |
Run the sample application:
dotnet run --project RxBlazorV2Sample
The RxBlazorV2.MudBlazor.Sample project showcases the reactive MudBlazor components in four pages โ live at b-straub.github.io/RxBlazorV2/mudblazor/:
| Page | Demonstrates |
|---|---|
/ (Buttons) |
MudButton[Async]Rx[Of<T>], MudIconButton..., MudFab... with progress / cancellation / confirmation; StatusDisplay for snackbar + icon messages |
/sortable |
MudSortableSwipeoutListRx intra-list reorder + MudSwipeoutRx swipe-to-pin / archive / delete; runtime toggle between drag-handle / tap-hold / whole-row activation |
/contacts |
Cross-list groups: All Contacts (clone source) โ VIP Group (move target) with drag-out-to-remove |
/notifications |
Standalone MudSwipeoutRx (no sortable wrapping) โ DB-style timestamp-desc order with toggle-read / archive (toggles) / overswipe-to-delete |
Run:
dotnet run --project RxBlazorV2.MudBlazor.Sample
The ReactivePatternSample is a multi-project Blazor application demonstrating all reactive patterns in a real-world scenario:
| Project | Description |
|---|---|
| ReactivePatternSample | Main Blazor WASM host application |
| ReactivePatternSample.Auth | Authentication model with login/logout commands and triggers |
| ReactivePatternSample.Settings | User preferences with component triggers for theme/language |
| ReactivePatternSample.Status | Status bar model with internal observers and notifications |
| ReactivePatternSample.Storage | Persistence layer with external model observers |
| ReactivePatternSample.Todo | Todo list demonstrating commands, triggers, and cross-model reactivity |
| ReactivePatternSample.Share | Sharing functionality with async commands and dialogs |
Key demonstrations:
[ObservableModelObserver]Run the reactive pattern sample:
dotnet run --project ReactivePatternSample/ReactivePatternSample
The generator provides comprehensive diagnostics (RXBG001-RXBG092) with code fixes. See the folder for detailed documentation.
Key diagnostic ranges:
Contributions are welcome! Please ensure:
This project is licensed under the MIT License - see the file for details.
Built with:
| 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 1 NuGet packages that depend on RxBlazorV2:
| Package | Downloads |
|---|---|
|
RxBlazorV2.MudBlazor
Reactive MudBlazor button components for RxBlazorV2. Provides automatic progress indicators, cancellation support, and confirmation dialogs for command bindings. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.2.5 | 96 | 5/7/2026 | |
| 1.2.4 | 163 | 5/2/2026 | |
| 1.2.3 | 112 | 4/30/2026 | |
| 1.2.2 | 113 | 4/27/2026 | |
| 1.2.1 | 115 | 4/16/2026 | |
| 1.2.0 | 126 | 4/15/2026 | 1.2.0 is deprecated because it has critical bugs. |
| 1.1.5 | 150 | 4/3/2026 | |
| 1.1.4 | 120 | 4/2/2026 | |
| 1.1.3 | 135 | 4/1/2026 | |
| 1.1.2 | 176 | 12/20/2025 | |
| 1.1.1 | 213 | 12/20/2025 | 1.1.1 is deprecated because it has critical bugs. |
| 1.1.0 | 215 | 12/20/2025 | 1.1.0 is deprecated because it has critical bugs. |
| 1.0.9 | 218 | 12/20/2025 | 1.0.9 is deprecated because it has critical bugs. |
| 1.0.8 | 305 | 12/18/2025 | |
| 1.0.7 | 300 | 12/18/2025 | |
| 1.0.6 | 384 | 12/17/2025 | |
| 1.0.5 | 326 | 12/15/2025 | |
| 1.0.4 | 172 | 12/11/2025 | |
| 1.0.3 | 247 | 12/4/2025 | |
| 1.0.1 | 347 | 12/3/2025 | 1.0.1 is deprecated because it has critical bugs. |
v1.0.0 - Initial Release
- ObservableModel base class with R3 reactive state management
- Roslyn incremental source generator for partial properties and commands
- Automatic DI registration with AddObservableModels()
- Component triggers for reactive UI updates
- Property triggers for internal model methods
- Callback triggers for external service subscriptions
- Code fixes for common patterns