ConvMVVM3.SourceGenerator
1.0.3
dotnet add package ConvMVVM3.SourceGenerator --version 1.0.3
NuGet\Install-Package ConvMVVM3.SourceGenerator -Version 1.0.3
<PackageReference Include="ConvMVVM3.SourceGenerator" Version="1.0.3" />
<PackageVersion Include="ConvMVVM3.SourceGenerator" Version="1.0.3" />
<PackageReference Include="ConvMVVM3.SourceGenerator" />
paket add ConvMVVM3.SourceGenerator --version 1.0.3
#r "nuget: ConvMVVM3.SourceGenerator, 1.0.3"
#:package ConvMVVM3.SourceGenerator@1.0.3
#addin nuget:?package=ConvMVVM3.SourceGenerator&version=1.0.3
#tool nuget:?package=ConvMVVM3.SourceGenerator&version=1.0.3
<p align="center"> <img src="https://github.com/gellston/ConvMVVM3/blob/main/logo.png?raw=true" alt="ConvMVVM3 Logo" width="400"/> </p>
ConvMVVM3 (Convergence MVVM3) is a modern, cross-platform MVVM framework that combines the best features from Prism and Community Toolkit while adding unique innovations.
π XAML Namespace Mapping
ConvMVVM3 exposes a single XAML XML namespace for a clean, consistent XAML experience:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:convMVVM3="https://github.com/gellston/ConvMVVM3"
convMVVM3:ViewModelLocator.AutoWireViewModel="True">
</Window>
xmlns:convMVVM3="https://github.com/gellston/ConvMVVM3"β ConvMVVM3 XAML features (Regions, ViewModelLocator, Behaviors/Interactivity, etc.)convMVVM3:ViewModelLocator.AutoWireViewModel="True"β ViewModel auto-wiring (Prism-like)
β¨ Key Differentiators from Prism & Community Toolkit
π UIDispatcher (UNIQUE - Cross-Platform)
Microsoft-compatible UI thread dispatcher for multiple platforms:
// Setup - Available for WPF, MAUI, Avalonia, WinUI
services.AddWPFUIDispatcher(); // WPF
// Usage - Cross-platform compatible
await dispatcher.InvokeAsync(() => Title = "Updated");
π Smart Dependency Injection (UNIQUE - Built-in)
Lightweight service container with addon system - No external DI required:
// Built-in container - Zero external dependencies
services.AddSingleton<IMyService, MyService>();
π‘ WeakReference Messenger (Memory-Safe, Cross-Platform)
Thread-safe messaging with automatic cleanup:
// Automatic weak references - Platform-agnostic
WeakReferenceMessenger.Default.Send<Message>(this, newData);
π― Region System (Prism-inspired, Cross-Platform)
Built-in region management for multiple frameworks:
<ContentControl convMVVM3:RegionPlugin.RegionName="MainContent" />
β‘ Source Generator (Community Toolkit-inspired)
Automatic property and command generation with enhanced features:
[ObservableProperty] private string title; // Generates Title property
[RelayCommand] private void Save(); // Generates SaveCommand
[AsyncRelayCommand] private async Task Load(); // Generates LoadCommand
ποΈ Architecture Overview
Core MVVM Components (Platform-Agnostic)
ConvMVVM3.Core/
βββ ObservableObject # Base class with INotifyPropertyChanged
βββ ObservableRecipient # Message recipient base class
βββ UIDispatcher # Cross-platform dispatcher interface
βββ WeakReferenceMessenger # Memory-safe messaging system
βββ Commands/
β βββ RelayCommand # Synchronous command implementation
β βββ AsyncRelayCommand # Async command with cancellation
βββ DependencyInjection/ # Built-in DI container
WPF Implementation (One of Many Platforms)
ConvMVVM3.WPF/ # WPF-specific implementation
βββ Regions/ # Region system (Prism-inspired)
βββ WPFUIDispatcher # WPF-specific dispatcher
βββ Interactivity/ # Behaviors / triggers / actions
βββ WeakEventManager # Memory-efficient event handling
Source Generation (Cross-Platform)
ConvMVVM3.SourceGenerator/
βββ ObservableProperty generation # Auto property implementation
βββ RelayCommand generation # Auto command creation
βββ Dependency tracking # Smart property notification
βββ Compile-time validation # Early error detection
π Project Structure
ConvMVVM3.Core/ # Platform-agnostic MVVM library
ConvMVVM3.SourceGenerator/ # Cross-platform source generator
ConvMVVM3.WPF/ # WPF-specific interactivity + regions
ConvMVVM3.Host/ # DI host implementation
ConvMVVM3.WPF.Tests/ # WPF unit tests
ConvMVVM3.Tests/ # Core unit tests
π οΈ Installation
dotnet add package ConvMVVM3
π Quick Start
1) Basic ViewModel with Cross-Platform Generation
// Works on ALL supported platforms
public partial class MainViewModel : ObservableObject
{
[ObservableProperty]
private string title = "Hello ConvMVVM3!";
[RelayCommand]
private void ShowMessage() => MessageBox.Show(Title);
[AsyncRelayCommand]
private async Task LoadDataAsync()
{
Title = "Loading...";
await Task.Delay(1000);
Title = "Data Loaded!";
}
}
2) ViewModelLocator (AutoWireViewModel)
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:convMVVM3="https://github.com/gellston/ConvMVVM3"
convMVVM3:ViewModelLocator.AutoWireViewModel="True">
</Window>
3) Cross-Platform UIDispatcher Integration
// Setup varies by platform
services.AddWPFUIDispatcher(); // WPF
// Usage is identical across platforms
public partial class MyViewModel : ObservableObject
{
private readonly IUIDispatcher _dispatcher;
public MyViewModel(IUIDispatcher dispatcher)
{
_dispatcher = dispatcher;
}
[AsyncRelayCommand]
private async Task UpdateFromBackgroundAsync()
{
var data = await Task.Run(() => GetHeavyData());
// Thread-safe UI update (cross-platform)
await _dispatcher.InvokeAsync(() => Title = data);
}
}
4) Cross-Platform Region Management
<Grid>
<ContentControl convMVVM3:RegionPlugin.RegionName="MainContent" />
</Grid>
// Platform-agnostic navigation
_regionManager.RequestNavigate("MainContent", typeof(HomeViewModel));
5) Memory-Safe Cross-Platform Messaging
// Sender (all platforms)
WeakReferenceMessenger.Default.Send<DataUpdatedMessage>(this, newData);
// Receiver (auto-cleanup, all platforms)
public partial class MyViewModel : ObservableObject, IRecipient<DataUpdatedMessage>
{
public void Receive(DataUpdatedMessage message)
{
Title = message.Data;
}
}
6) WPF Interactivity / Behaviors
<Button Content="Click Me">
<convMVVM3:Interaction.Triggers>
<convMVVM3:EventTrigger EventName="Click">
<convMVVM3:InvokeCommandAction Command="{Binding SaveCommand}" />
</convMVVM3:EventTrigger>
</convMVVM3:Interaction.Triggers>
</Button>
π§° Helpful Utilities
This section includes a few practical helpers used frequently in Prism-style MVVM apps:
ConvMVVM3.Core.Mvvm.ThreadingConvMVVM3.Core.Mvvm.CollectionsConvMVVM3.Host.DependencyInjection
A) BusyScope β ConvMVVM3.Core.Mvvm.Threading
Use a scope to ensure IsBusy is always restored (even if an exception occurs).
Recommended for simple βsingle operationβ flows.
using ConvMVVM3.Core.Mvvm.Threading;
// In your ViewModel
private bool _isBusy;
public bool IsBusy
{
get => _isBusy;
set { _isBusy = value; /* RaisePropertyChanged */ }
}
public async Task RefreshAsync()
{
using (BusyScope.Enter(v => IsBusy = v))
{
await LoadAsync();
}
}
B) BusyCounterScope (Recommended) β ConvMVVM3.Core.Mvvm.Threading
Recommended when operations can overlap (nested calls, multiple async commands).
using ConvMVVM3.Core.Mvvm.Threading;
private int _busyCount;
private bool _isBusy;
public bool IsBusy
{
get => _isBusy;
set { _isBusy = value; /* RaisePropertyChanged */ }
}
public async Task RefreshAsync()
{
using (BusyCounterScope.Enter(
getCount: () => _busyCount,
setCount: v => _busyCount = v,
setBusy: v => IsBusy = v))
{
await LoadAsync();
}
}
C) OperationGuard β ConvMVVM3.Core.Mvvm.Threading
Prevents re-entrancy (double-click save, multiple async executions).
Combine it with BusyScope/BusyCounterScope for a great UX.
using ConvMVVM3.Core.Mvvm.Threading;
private readonly OperationGuard _saveGuard = new OperationGuard();
private int _busyCount;
public Task SaveAsync()
{
return _saveGuard.RunAsync(async () =>
{
using (BusyCounterScope.Enter(
() => _busyCount,
v => _busyCount = v,
v => IsBusy = v))
{
await SaveAsyncCore();
}
});
}
D) ObservableRangeCollection β ConvMVVM3.Core.Mvvm.Collections
Use AddRange/ReplaceRange to avoid thousands of per-item collection change notifications.
using ConvMVVM3.Core.Mvvm.Collections;
public ObservableRangeCollection<ItemViewModel> Items { get; } = new();
public async Task LoadItemsAsync()
{
var items = await LoadFromServerAsync();
// One reset notification instead of N adds
Items.ReplaceRange(items);
}
E) ActivatorUtilities β ConvMVVM3.Host.DependencyInjection
ActivatorUtilities helps create objects by mixing:
- DI-resolved services from
IServiceResolver - runtime arguments you provide (e.g., IDs, parameters, view references)
using ConvMVVM3.Core.DependencyInjection.Abstractions;
using ConvMVVM3.Host.DependencyInjection;
// Example types
public sealed class UserDetailsViewModel
{
public UserDetailsViewModel(IUserService service, int userId)
{
// service comes from DI, userId comes from runtime args
}
}
public static class Example
{
public static void CreateWithRuntimeArgs(IServiceResolver resolver)
{
// 1) CreateInstance: DI + runtime args
var vm = (UserDetailsViewModel)ActivatorUtilities.CreateInstance(
resolver,
typeof(UserDetailsViewModel),
123);
// 2) GetServiceOrCreateInstance: prefer registered instance, otherwise create
var shell = ActivatorUtilities.GetServiceOrCreateInstance<MainShellViewModel>(resolver);
// 3) CreateFactory: preselect ctor + argument mapping for speed
var factory = ActivatorUtilities.CreateFactory(
typeof(UserDetailsViewModel),
new[] { typeof(int) });
var vmFast = (UserDetailsViewModel)factory(resolver, new object[] { 456 });
}
}
Note: The class name is ActivatorUtilities (not ActivityUtility).
π§© Bootstrapper
ConvMVVM3 supports a Prism-style Bootstrapper flow for registering modules, building the shell, and initializing regions/services.
public class AppBootStrapper : Bootstrapper
{
protected override void ConfigureRegion(IRegionManager regionManager)
{
}
protected override Window CreateShell(IServiceContainer provider)
{
return (Window)provider.GetService("MainWindowView");
}
protected override void OnInitialized(IServiceContainer provider)
{
}
protected override void RegisterModules()
{
this.RegisterModule<AModule>();
this.RegisterModule<BModule>();
this.RegisterModule<CModule>();
this.RegisterModule<MainModule>();
}
protected override void RegisterServices(IServiceRegistry container)
{
}
}
π― Platform Support Matrix
| Feature | WPF | MAUI | Avalonia | WinUI | UNO |
|---|---|---|---|---|---|
| Core MVVM | β | β | β | β | β |
| UIDispatcher | β | π | π | π | π |
| Source Generator | β | β | β | β | β |
| Region System | β | π | π | π | π |
| Built-in DI | β | β | β | β | β |
| Weak Messenger | β | β | β | β | β |
| WPF Interactivity | β | β | β | β | β |
| Platform Interactivity | β | π | π | π | π |
β Available | π Planned | β Not applicable
π License
MIT License - see LICENSE file
ConvMVVM3: Modern, cross-platform MVVM framework that bridges the gap between Prism's power and Community Toolkit's simplicity while adding unique cross-platform innovations.
Future Roadmap: MAUI, Avalonia, WinUI, and UNO Platform support coming soon!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- ConvMVVM3.Host (>= 1.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ConvMVVM3.SourceGenerator:
| Package | Downloads |
|---|---|
|
ConvMVVM3.WPF
ConvMVVM3 Core MVVM library (platform-agnostic). |
GitHub repositories
This package is not used by any popular GitHub repositories.