NuExt.Minimal.Mvvm.Sources 0.7.0

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

NuExt.Minimal.Mvvm

NuExt.Minimal.Mvvm is a high-performance, dependency-free MVVM framework for .NET focused on robust async flows, deterministic command execution, and a clear, minimal API.

Features

  • Core:

    • Minimal.Mvvm.BindableBase — lightweight INotifyPropertyChanged base.
    • Minimal.Mvvm.ViewModelBase — lean ViewModel foundation with simple service access.
  • Command Model (self-validating): All commands (RelayCommand, RelayCommand<T>, AsyncCommand, AsyncCommand<T>, CompositeCommand) validate their state internally: if CanExecute(parameter) is false, Execute(parameter) performs no action. This guarantees consistent behavior for both UI-bound and programmatic calls.

  • Command Implementations:

    • Minimal.Mvvm.RelayCommand / RelayCommand<T> - classic, synchronous delegate-based commands with optional concurrency control.
    • Minimal.Mvvm.AsyncCommand / AsyncCommand<T> - full-featured asynchronous commands with cancellation support, reentrancy control, and predictable error propagation.
    • Minimal.Mvvm.CompositeCommand - aggregates multiple commands and executes them sequentially; awaits ExecuteAsync(...) and calls Execute(...) for non-async commands.
  • Async & Concurrency:

    • Explicit separation: ICommand.Execute (fire-and-forget) vs IAsyncCommand.ExecuteAsync (awaitable with CancellationToken).
    • Built-in reentrancy control via AllowConcurrentExecution.
    • Comprehensive Exception Handling: Local (UnhandledException) and global (AsyncCommand.GlobalUnhandledException) events with Handled propagation control.
  • Service Provider Integration:

    • Minimal.Mvvm.ServiceProvider: Lightweight service provider for registration and resolution of services, facilitating dependency injection within your application.

For an enhanced development experience, we highly recommend using the NuExt.Minimal.Mvvm.SourceGenerator package alongside this framework. It provides compile-time boilerplate generation for ViewModels.

Installation

Via NuGet:

dotnet add package NuExt.Minimal.Mvvm

Or via Visual Studio:

  1. Go to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution....
  2. Search for NuExt.Minimal.Mvvm.
  3. Click "Install".

Source Code Package

In addition to the standard package, there is also a source code package available: NuExt.Minimal.Mvvm.Sources. This package allows you to embed the entire framework directly into your application, enabling easier source code exploring and debugging.

To install the source code package, use the following command:

dotnet add package NuExt.Minimal.Mvvm.Sources

Or via Visual Studio:

  1. Go to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution....
  2. Search for NuExt.Minimal.Mvvm.Sources.
  3. Click "Install".

Usage

Example: Advanced AsyncCommand with Concurrency and Cancellation
public class SearchViewModel : ViewModelBase
{
    public IAsyncCommand<string> SearchCommand { get; }
    public ICommand CancelCommand { get; }

    public SearchViewModel()
    {
        SearchCommand = new AsyncCommand<string>(SearchAsync, CanSearch)
        {
            AllowConcurrentExecution = true
        };

        AsyncCommand.GlobalUnhandledException += (sender, e) =>
        {
            Logger.LogError(e.Exception, "Global command error");
            e.Handled = true;
        };

        CancelCommand = new RelayCommand(() => SearchCommand.Cancel());
    }

    private async Task SearchAsync(string query, CancellationToken cancellationToken)
    {
        await Task.Delay(1000, cancellationToken);
        Results = $"Results for: {query}";
    }

    private bool CanSearch(string query) => !string.IsNullOrWhiteSpace(query);

    private string _results;
    public string Results
    {
        get => _results;
        private set => SetProperty(ref _results, value);
    }
}
Example: Two-Tier Exception Handling
public class DataViewModel : ViewModelBase
{
    public IAsyncCommand LoadDataCommand { get; }

    public DataViewModel()
    {
        LoadDataCommand = new AsyncCommand(LoadDataAsync);

        LoadDataCommand.UnhandledException += (sender, e) =>
        {
            if (e.Exception is HttpRequestException httpEx)
            {
                ShowError($"Network error: {httpEx.Message}");
                e.Handled = true;
            }
        };
    }

    private async Task LoadDataAsync(CancellationToken cancellationToken)
    {
        throw new HttpRequestException("Connection failed");
    }
}
Example Using Source Generator

To further simplify your ViewModel development, consider using the source generator provided by the NuExt.Minimal.Mvvm.SourceGenerator package. Here's an example:

using Minimal.Mvvm;

public partial class ProductViewModel : ViewModelBase
{
    [Notify]
    private string _name = string.Empty;
    
    [Notify(Setter = AccessModifier.Private)]
    private decimal _price;
    
    public ProductViewModel()
    {
        SaveCommand = new AsyncCommand(SaveAsync);
    }
    
    [Notify]
    private async Task SaveAsync(CancellationToken token)
    {
        await Task.Delay(500, token);
        Price = 99.99m;
    }
}

This automation helps to maintain clean and efficient code, improving overall productivity. For details on installing and using the source generator, refer to the NuExt.Minimal.Mvvm.SourceGenerator documentation.

Example Using ServiceProvider
public class MyService
{
    public string GetData() => "Hello from MyService!";
}

public class MyViewModel : ViewModelBase
{
    public IRelayCommand MyCommand { get; }

    public MyViewModel()
    {
        // Register services
        ServiceProvider.Default.RegisterService<MyService>();
        
        MyCommand = new RelayCommand(() =>
        {
            // Resolve and use services
            var myService = ServiceProvider.Default.GetService<MyService>();

            var data = myService.GetData();
            // Use the data
        });
    }
}

Contributing

Issues and PRs are welcome. Keep changes minimal and performance-conscious.

License

MIT. See LICENSE.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETFramework 4.6.2

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • 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
0.7.3 87 3/16/2026
0.7.2 100 2/26/2026
0.7.1 103 2/23/2026
0.7.0 114 2/12/2026
0.6.0 154 1/11/2026
0.5.2 358 12/15/2025
0.5.1 304 12/14/2025
0.4.1 533 12/10/2025
0.4.0 260 12/5/2025
0.3.4 381 2/21/2025
0.3.3 351 1/26/2025
0.3.2 367 1/22/2025
0.3.1 343 1/19/2025
0.3.0 375 1/13/2025
0.2.0 697 11/14/2024
Loading failed