Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/matt-goldman/Maui.Plugins.PageResolver

A simple and lightweight page resolver for use in .NET MAUI projects
https://github.com/matt-goldman/Maui.Plugins.PageResolver

dependency-injection dotnet dotnetmaui source-generator

Last synced: 30 days ago
JSON representation

A simple and lightweight page resolver for use in .NET MAUI projects

Awesome Lists containing this project

README

        

[![NuGet Status](https://img.shields.io/nuget/v/Goldie.MauiPlugins.PageResolver.svg?style=flat)](https://www.nuget.org/packages/Goldie.MauiPlugins.PageResolver/) [![Nuget](https://img.shields.io/nuget/dt/Goldie.MauiPlugins.PageResolver)](https://www.nuget.org/packages/Goldie.MauiPlugins.PageResolver)

## Watch the video:


Watch the video

# MAUI PageResolver
A simple and lightweight page resolver for use in .NET MAUI projects.

If you want a simple page resolver with DI without using a full MVVM framework (or if you want to use MVU), this package will let you navigate to fully resolved pages, with view models and dependencies, by calling:

```cs
await Navigation.PushAsync();
```

# Advanced features

Additional features supported by PageReolver:
* Paramaterised navigation - pass page parameters

```csharp
await Navigation.PushAsync(myPageParam1, "bob", 4);
```

* Paramaterised navigation - pass ViewModel parameters (.NET 8 version only)

```csharp
await Navigation.PushAsync(myViewModelParam1, "bob", 4);
```

* Source generator - automatically register dependencies in `IServiceCollection` with generated code (.NET 8 version only)

```csharp
using Maui.Plugins.PageResolver;
using DemoProject;
using DemoProject.Pages;
using DemoProject.ViewModels;
using DemoProject.Services;
// ---------------
//
// Generated by the MauiPageResolver Auto-registration module.
// https://github.com/matt-goldman/Maui.Plugins.PageResolver
//
// ---------------

namespace DemoProject;

public static class PageResolverExtensions
{

public static MauiAppBuilder UseAutodependencies(this MauiAppBuilder builder)
{
var ViewModelMappings = new Dictionary();

// pages
builder.Services.AddTransient();

// ViewModels
builder.Services.AddTransient();

// Services
builder.Services.AddSingleton();
builder.Services.AddTransient();

// ViewModel to Page mappings
ViewModelMappings.Add(typeof(MainPage), typeof(MainViewModel));

// Initialisation
builder.Services.UsePageResolver(ViewModelMappings);
return builder;
}
}
```

* Lifetime attributes - override convention-based service lifetimes (singleton for services, transient for pages and ViewModels) in the source generator (.NET 8 version only)

```csharp
[Transient]
public class CustomScopedService : ICustomScopedService
{
[...]
```

# Getting Started

Check out the full instructions in the wiki on [using PageResolver](https://github.com/matt-goldman/Maui.Plugins.PageResolver/wiki/1-Using-the-PageResolver)