Goldie.MauiPlugins.PageResolver
1.0.1
See the version list below for details.
dotnet add package Goldie.MauiPlugins.PageResolver --version 1.0.1
NuGet\Install-Package Goldie.MauiPlugins.PageResolver -Version 1.0.1
<PackageReference Include="Goldie.MauiPlugins.PageResolver" Version="1.0.1" />
paket add Goldie.MauiPlugins.PageResolver --version 1.0.1
#r "nuget: Goldie.MauiPlugins.PageResolver, 1.0.1"
// Install Goldie.MauiPlugins.PageResolver as a Cake Addin
#addin nuget:?package=Goldie.MauiPlugins.PageResolver&version=1.0.1
// Install Goldie.MauiPlugins.PageResolver as a Cake Tool
#tool nuget:?package=Goldie.MauiPlugins.PageResolver&version=1.0.1
MAUI PageResolver
A simple and lightweight page resolver for use in .NET MAUI projects.
While we're waiting for the full MVVM frameworks we know and love to be updated for MAUI, or if you just 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>();
Getting Started
Step 1: Install Nuget package
Install the Nuget package
dotnet add package Goldie.MauiPlugins.PageResolver
Step 2: Register dependencies
Your services, view models, and pages all need to be registered in the service collection. Update the Configure method in your Startup.cs as follows
using Microsoft.Maui;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Controls.Compatibility;
// Add reference to PageResolver
using Maui.Plugins.PageResolver;
// Add any required references to your services, view models, etc.
using MyApp.Services;
using MyApp.ViewModels;
using MyApp.Views;
namespace MyApp
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
// register your services
builder.Services.AddSingleton<IMyService, MyService>();
// register your view models
builder.Services.AddTransient<MyViewModel>();
// register your views
builder.Services.AddTransient<MyPage>();
// register the page resolver
builder.Services.UsePageResolver();
return builder.Build();
}
}
}
Step 3: Inject your dependencies
Use constructor injection to add your dependencies to your pages and view models. E.g.:
public class MyPage
{
public MyViewModel ViewModel { get; set; }
public MyPage(MyViewModel viewModel)
{
ViewModel = viewModel;
BindingContext = ViewModel;
}
}
And in your view models:
public class MyViewModel
{
public IMyService Service { get; set; }
public MyViewModel(IMyService myService)
{
Service = myService;
}
}
Step 4: Use in your code
In your code, navigate to your page by calling:
await Navigation.PushAsync<MyPage>();
This will return a fully resolved instance of MyPage
including all dependencies.
Modal pages are also supported:
await Navigation.PushModalAsync<MyPage>();
Notes
This is just something I put together for myself (with some input from William Liebenberg), but thought it might be useful to others. If you use it and it's helpful, great. If not, please remember it's an early attempt at doing something useful for a preview version of MAUI. If you have comments or suggestions, feedback is welcome.
TODO
- Use reflection / code generation to automatically register pages and view models
- (Pending C# 10) Add a global using for this package
- Set up GitHub Action to publish package
- (Possibly) change namespace
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- Microsoft.Maui.Controls.Build.Tasks (>= 6.0.101-preview.9.1843)
- Microsoft.Maui.Dependencies (>= 6.0.101-preview.9.1843)
- Microsoft.Maui.Extensions (>= 6.0.101-preview.9.1843)
- Microsoft.Maui.Resizetizer.Sdk (>= 6.0.101-preview.9.1843)
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 |
---|---|---|
2.0.1 | 1,796 | 11/18/2023 |
2.0.0 | 141 | 11/13/2023 |
2.0.0-preview1 | 72 | 10/13/2023 |
1.1.1 | 3,416 | 1/14/2023 |
1.1.0 | 254 | 1/14/2023 |
1.0.7 | 940 | 8/13/2022 |
1.0.6 | 448 | 6/26/2022 |
1.0.5 | 338 | 3/8/2022 |
1.0.5-preview1 | 109 | 3/5/2022 |
1.0.4 | 132 | 2/26/2022 |
1.0.3 | 112 | 2/26/2022 |
1.0.2 | 138 | 2/14/2022 |
1.0.1 | 234 | 10/23/2021 |
1.0.0 | 225 | 6/17/2021 |
1.0.0-build | 125 | 8/13/2022 |