Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/havendv/mvvm.navigation
Provides platform independent navigation at the MVVM level and a Source Generator that automatically binds view and view models and registers this in your DI container
https://github.com/havendv/mvvm.navigation
binding csharp dependency-injection di dotnet generator mvvm net6 net7 source source-generator view viewmodel
Last synced: 6 days ago
JSON representation
Provides platform independent navigation at the MVVM level and a Source Generator that automatically binds view and view models and registers this in your DI container
- Host: GitHub
- URL: https://github.com/havendv/mvvm.navigation
- Owner: HavenDV
- License: mit
- Created: 2023-08-14T10:32:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-28T06:42:33.000Z (18 days ago)
- Last Synced: 2024-11-01T13:42:02.044Z (13 days ago)
- Topics: binding, csharp, dependency-injection, di, dotnet, generator, mvvm, net6, net7, source, source-generator, view, viewmodel
- Language: C#
- Homepage:
- Size: 1.04 MB
- Stars: 18
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [Mvvm.Navigation](https://github.com/HavenDV/Mvvm.Navigation/)
[![CI/CD](https://github.com/HavenDV/Mvvm.Navigation/actions/workflows/dotnet.yml/badge.svg?branch=main)](https://github.com/HavenDV/Mvvm.Navigation/actions/workflows/dotnet.yml)
[![License: MIT](https://img.shields.io/github/license/HavenDV/Mvvm.Navigation)](https://github.com/HavenDV/Mvvm.Navigation/blob/main/LICENSE.txt)
[![Discord](https://img.shields.io/discord/988253265550532680?label=Discord&logo=discord&logoColor=white&color=d82679)](https://discord.gg/g8u2t9dKgE)
[![NuGet](https://img.shields.io/nuget/dt/Mvvm.Navigation.Core.svg?style=flat-square&label=Mvvm.Navigation.Core)](https://www.nuget.org/packages/Mvvm.Navigation.Core/)
[![NuGet](https://img.shields.io/nuget/dt/Mvvm.Navigation.Wpf.svg?style=flat-square&label=Mvvm.Navigation.Wpf)](https://www.nuget.org/packages/Mvvm.Navigation.Wpf/)
[![NuGet](https://img.shields.io/nuget/dt/Mvvm.Navigation.Uno.svg?style=flat-square&label=Mvvm.Navigation.Uno)](https://www.nuget.org/packages/Mvvm.Navigation.Uno/)
[![NuGet](https://img.shields.io/nuget/dt/Mvvm.Navigation.Uno.WinUI.svg?style=flat-square&label=Mvvm.Navigation.Uno.WinUI)](https://www.nuget.org/packages/Mvvm.Navigation.Uno/)
[![NuGet](https://img.shields.io/nuget/dt/Mvvm.Navigation.Uwp.svg?style=flat-square&label=Mvvm.Navigation.Uwp)](https://www.nuget.org/packages/Mvvm.Navigation.Uwp/)
[![NuGet](https://img.shields.io/nuget/dt/Mvvm.Navigation.WinUI.svg?style=flat-square&label=Mvvm.Navigation.WinUI)](https://www.nuget.org/packages/Mvvm.Navigation.WinUI/)
[![NuGet](https://img.shields.io/nuget/dt/Mvvm.Navigation.Avalonia.svg?style=flat-square&label=Mvvm.Navigation.Avalonia)](https://www.nuget.org/packages/Mvvm.Navigation.Avalonia/)
[![NuGet](https://img.shields.io/nuget/dt/Mvvm.Navigation.Maui.svg?style=flat-square&label=Mvvm.Navigation.Maui)](https://www.nuget.org/packages/Mvvm.Navigation.Maui/)Provides platform independent navigation at the MVVM level and
a Source Generator that automatically binds view and view models and
registers this in your DI container.
## π₯Featuresπ₯
- Uses DI to resolve your view from view model.
- Generates constructors for your views(optional).
- Generates an extension method for you with all your Views and ViewModels to register them in DI.
- Does not contain custom controls, everything happens based on the attached dependency property and does not limit the user.
- Allows forward/backward navigation like in Chrome.
- Allows you to receive activation/deactivation events - just implement IActivatableViewModel for your ViewModel.
- Allows you to generate a typed ViewModel property via an attribute, bound to your BindingContext and initialized from DI.
- Supports automatic mapping between View and ViewModel based on a global attribute.
- Allows case-by-case, attribute-based control for Views.## Usage
1. Add `.AddMvvmNavigation()` call to your Host builder or `IServiceCollection`:
```csharp
public sealed partial class App
{
public App()
{
AppHost = Host
.CreateDefaultBuilder()
.AddMvvmNavigation()
.Build();
}
}
```
2. Add ViewFor attribute to your views:
```csharp
using Mvvm.Navigation;[ViewFor]
public partial class MainPage : UserControl;
```
or assembly level attribute(nameof behavior is ignored and the full namespace is taken):
```csharp
[assembly:MapViews(
viewsNamespace: nameof(MyNamespace.Views),
viewModelsNamespace: nameof(MyNamespace.ViewModels))]
```
or in .csproj:
```xml
<_Parameter1>nameof(MyNamespace.Views)
<_Parameter1_IsLiteral>true
<_Parameter2>nameof(MyNamespace.ViewModels)
<_Parameter2_IsLiteral>true
Mvvm.Navigation.ServiceLifetime.Transient
true
Mvvm.Navigation.ServiceLifetime.Scoped
true
```
Default lifetime is `ServiceLifetime.Transient` for View and `ServiceLifetime.Scoped` for ViewModel.
3. Add Navigator to your ViewModel:
```csharp
public Navigator Navigator { get; }
```
4. Add commands to your views(or just use Navigator from ViewModel):
```xml
```
Tip: you can use `CommandParameter="{mvvm:Type Type=viewModels:BlueViewModel}"` for WinUI/UWP/Uno platforms.## Base
The library was written as a replacement for ReactiveUI in a real project,
and inherits some concepts from it, excluding reactivity.
If you have the same task, then the changes are as follows:
- Replace RoutingState with Navigator
- Replace IScreen with INavigable
- Replace ReactiveUserControl with UserControl
- Replace ReactiveWindow with Window
- Replace RoutedViewHost and ViewModelViewHost with ContentControl
- Use `mvvm:Navigation.ViewModel` and `mvvm:Navigation.Navigator`(includes ServiceProvider) attached dependency properties.
- Or just bind like this ``## Support
Priority place for bugs: https://github.com/HavenDV/Mvvm.Navigation/issues
Priority place for ideas and general questions: https://github.com/HavenDV/Mvvm.Navigation/discussions
I also have a Discord support channel:
https://discord.gg/g8u2t9dKgE