VRT.Mvvm.Navigation.Generators
1.0.1
dotnet add package VRT.Mvvm.Navigation.Generators --version 1.0.1
NuGet\Install-Package VRT.Mvvm.Navigation.Generators -Version 1.0.1
<PackageReference Include="VRT.Mvvm.Navigation.Generators" Version="1.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="VRT.Mvvm.Navigation.Generators" Version="1.0.1" />
<PackageReference Include="VRT.Mvvm.Navigation.Generators"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add VRT.Mvvm.Navigation.Generators --version 1.0.1
#r "nuget: VRT.Mvvm.Navigation.Generators, 1.0.1"
#:package VRT.Mvvm.Navigation.Generators@1.0.1
#addin nuget:?package=VRT.Mvvm.Navigation.Generators&version=1.0.1
#tool nuget:?package=VRT.Mvvm.Navigation.Generators&version=1.0.1
VRT.Mvvm
Shared, toolkit-agnostic MVVM navigation core for .NET applications (WinForms, WPF, MAUI, and similar hosts).
Packages
| Package | Contents | When to reference |
|---|---|---|
VRT.Mvvm.Navigation |
Runtime + embedded source generators | Default — apps and libraries that define Views |
VRT.Mvvm.Navigation.Generators |
Generators only (DevelopmentDependency) |
Optional — multi-project layouts or explicit analyzer reference |
<PackageReference Include="VRT.Mvvm.Navigation" Version="*" />
Features
- Navigate by ViewModel type via a single
INavigationServiceentrypoint - Session View+ViewModel cache with suspend/dispose (
INavigationWorkspace) - Explicit View ↔ ViewModel registration (
IComponentLocator/ DI helpers) - Hosts display views via toolkit-specific
IRoutingHandler.ShowView(object view) - Lightweight
NavigationResult/NavigationResult<T>with internalBind/Tap/Map - Roslyn generators:
AddMvvmComponentsand partialViewModelproperties forIViewFor<T>
Requirements
- .NET 10 (library targets
net10.0) Microsoft.Extensions.DependencyInjection.Abstractions(transitive)- Host app typically uses
Microsoft.Extensions.DependencyInjection
Quick start
using Microsoft.Extensions.DependencyInjection;
using VRT.Mvvm.Navigation;
using VRT.Mvvm.Navigation.Abstractions;
var services = new ServiceCollection();
services.AddNavigation();
// Manual mappings, or generated for all IViewFor<> in this assembly:
// services.AddNavigationComponent<HomeView, HomeViewModel>();
services.AddMvvmComponents(); // from source generator (ships with the NuGet package)
await using var provider = services.BuildServiceProvider();
var navigation = provider.GetRequiredService<INavigationService>();
// Host implements IRoutingHandler and registers itself:
// navigation.RegisterRoutingHandler(this);
await navigation.NavigateToAsync<HomeViewModel>(
configure: vm => { /* optional setup */ },
cacheView: true);
Terminology
| Name | Meaning |
|---|---|
| ViewModel type | What you navigate to (NavigateToAsync<TViewModel>) |
| View | UI instance delivered to the host (ShowView(view)) |
MvvmComponent (internal) |
Type declaration: View type ↔ ViewModel type (locator) |
MvvmComponentInstance (internal) |
Live View + ViewModel instances (session cache) |
Host responsibilities
- Implement
IRoutingHandler.ShowView(object view)to place the view in the UI (content control, panel, frame, …). - Call
INavigationService.RegisterRoutingHandler(this)on startup (do not register the host in DI if that creates a cycle withINavigationService). - Register navigable pairs via
AddMvvmComponents()(generated) and/orAddNavigationComponent<TView, TViewModel>().
Views and ViewModels
Views should be partial and implement IViewFor<TViewModel>:
- One
IViewFor<T>→ generator emitspublic TViewModel? ViewModel { get; set; } - Several
IViewFor<>on the same view → generator emits explicitTViewModel? IViewFor<TViewModel>.ViewModelproperties (avoids name/type clash) - Hand-written
ViewModelmembers are left as-is
Optional ISuspendable pauses inactive screens; IDisposable is honored when the workspace discards or evicts a pair.
Navigation injects the active ViewModel via public DataContext / ViewModel when assignable, and via matching IViewFor<T> (including explicit implementations).
Cache behavior
Session cache is keyed by ViewModel type (one View class may back multiple ViewModels).
cacheView |
Behavior |
|---|---|
true (default) |
Reuse the same View+ViewModel pair for that ViewModel type; previous cached pairs are suspended, not disposed |
false |
Create a fresh pair; when leaving, dispose the previous transient pair if it was not cached |
Call INavigationWorkspace.Clear() on logout (or similar) to dispose all cached screens.
Multi-project with Views
Each project that defines IViewFor<> views and should get generated AddMvvmComponents / ViewModel properties must compile with the generator (via VRT.Mvvm.Navigation or VRT.Mvvm.Navigation.Generators). Call AddMvvmComponents() per assembly that contains views.
Design notes
- Core has no WPF / WinForms / MAUI types.
- No MediatR / CSharpFunctionalExtensions dependency.
- Source generators ship with the main package; optional standalone Generators package for advanced layouts.
License
MIT — see LICENSE.txt.
Learn more about Target Frameworks and .NET Standard.
This package has 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 |
|---|---|---|
| 1.0.1 | 152 | 8/9/2026 |