Skip to content

matt-goldman/Maui.Plugins.PageResolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NuGet Status Nuget

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:

await Navigation.PushAsync<MyPage>();

Advanced features

Additional features supported by PageReolver:

  • Paramaterised navigation - pass page parameters
await Navigation.PushAsync<MyPage>(myPageParam1, "bob", 4);
  • Paramaterised navigation - pass ViewModel parameters (.NET 8 version only)
await Navigation.PushAsync<MyPage>(myViewModelParam1, "bob", 4);
  • Source generator - automatically register dependencies in IServiceCollection with generated code (.NET 8 version only)
using Maui.Plugins.PageResolver;
using DemoProject;
using DemoProject.Pages;
using DemoProject.ViewModels;
using DemoProject.Services;
// ---------------
// <auto-generated>
//   Generated by the MauiPageResolver Auto-registration module.
//   https://github.com/matt-goldman/Maui.Plugins.PageResolver
// </auto-generated>
// ---------------

namespace DemoProject;

public static class PageResolverExtensions
{

    public static MauiAppBuilder UseAutodependencies(this MauiAppBuilder builder)
    {
         var ViewModelMappings = new Dictionary<Type, Type>();

         // pages
         builder.Services.AddTransient<MainPage>();


         // ViewModels
         builder.Services.AddTransient<MainViewModel>();


         // Services
         builder.Services.AddSingleton<IDefaultScopedService, DefaultScopedService>();
         builder.Services.AddTransient<ICustomScopedService, CustomScopedService>();


         // 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)
[Transient]
public class CustomScopedService : ICustomScopedService
{
[...]

Getting Started

Check out the full instructions in the wiki on using PageResolver

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published