Skip to content

Commit

Permalink
.NET 8 update (#22)
Browse files Browse the repository at this point in the history
* Updated all projects to .NET 8

* Added ViewModel paramater resolution, bump remaining projects to .NET 8

* Started updating demo for new functionality

* Started adding parameterised viewmodel navigation

* Added a page to viewmodel mapping source generator

* Progress on source generator

* Working except with page params + vm

* Working with page params + viewmodel

* Working with page params + viewmodel

* Refactored auto-dependencies

* Added scope check to demo

* Updated source generator extension method

* Started adding source generator for Page->VM lookup

* Added view model mappings to source generator

* Preparing nuget package, moved mappings into static method in source generator

* Completed the source generator

* Completed first version of v2
Removed legacy autoreg

* Updated workflow

* Updated readme
  • Loading branch information
matt-goldman authored Oct 13, 2023
1 parent 88cb563 commit 9bff31e
Show file tree
Hide file tree
Showing 32 changed files with 998 additions and 382 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
name: CI

on:
create:
branches:
- release/**
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
Expand Down Expand Up @@ -40,7 +34,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.x.x
dotnet-version: 8.x.x
include-prerelease: false

- name: Install workloads
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,4 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
.meteor/
80 changes: 71 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,77 @@ If you want a simple page resolver with DI without using a full MVVM framework (
await Navigation.PushAsync<MyPage>();
```

# Getting Started
# Advanced features

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

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

* Paramaterised navigation - pass ViewModel parameters

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

* Source generator - automatically register dependencies in `IServiceCollection` with generated code

```csharp
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>();

Check out the for full instructions in the wiki on [using PageResolver](https://github.com/matt-goldman/Maui.Plugins.PageResolver/wiki/1-Using-the-PageResolver) and [using auto-dependency registration](https://github.com/matt-goldman/Maui.Plugins.PageResolver/wiki/2-Using-Auto-registration-(experimental)).

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


// Services
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

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

# Getting Started

# TODO
- [x] Use reflection / code generation to automatically register pages and view models
- [x] (Pending C# 10) Add a global using for this package
- [x] Added to readme
- [x] Set up GitHub Action to publish package
- [x] Enable page parameters to be passed
- [ ] (Possibly) change namespace
Check out the full instructions in the wiki on [using PageResolver](https://github.com/matt-goldman/Maui.Plugins.PageResolver/wiki/1-Using-the-PageResolver)
27 changes: 20 additions & 7 deletions src/DemoProject/DemoProject.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>DemoProject</RootNamespace>
<UseMaui>true</UseMaui>
Expand Down Expand Up @@ -49,17 +49,30 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<!--<PackageReference Include="Goldie.MauiPlugins.PageResolver" Version="2.0.0" />-->
<PackageReference Include="Goldie.MauiPlugins.PageResolver" Version="2.0.0-preview1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0-rc.1.23419.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Maui.Plugins.PageResolver.Autoreg\Maui.Plugins.PageResolver.Autoreg.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<!-- <ItemGroup>
<ProjectReference Include="..\Maui.Plugins.PageResolver.Attributes\Maui.Plugins.PageResolver.Attributes.csproj" />
<ProjectReference Include="..\Maui.Plugins.PageResolver.SourceGenerators\Maui.Plugins.PageResolver.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\Maui.Plugins.PageResolver\Maui.Plugins.PageResolver.csproj" />
</ItemGroup>
</ItemGroup> -->

<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

<ItemGroup>
<MauiXaml Update="Pages\MarkupPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\ScopeCheckPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\VmParamPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions src/DemoProject/DemoProject.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DemoProject", "DemoProject.csproj", "{2F0A035E-54E3-44D4-9673-2A587817E709}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2F0A035E-54E3-44D4-9673-2A587817E709}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F0A035E-54E3-44D4-9673-2A587817E709}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F0A035E-54E3-44D4-9673-2A587817E709}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F0A035E-54E3-44D4-9673-2A587817E709}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F10F3864-BA48-4B13-980D-F13F75A78214}
EndGlobalSection
EndGlobal
20 changes: 18 additions & 2 deletions src/DemoProject/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@
HorizontalOptions="Center" />

<Button
Text="Click to go to name page"
Text="Click to go to page param page"
FontAttributes="Bold"
Grid.Row="3"
SemanticProperties.Hint="Counts the number of times you click"
Command="{Binding GoToNameCommand}"
Command="{Binding GoToPageParamCommand}"
HorizontalOptions="Center" />

<Button
Text="Click to go to VM param page"
FontAttributes="Bold"
Grid.Row="3"
SemanticProperties.Hint="Counts the number of times you click"
Command="{Binding GoToVmParamCommand}"
HorizontalOptions="Center" />

<Button
Expand All @@ -48,6 +56,14 @@
Command="{Binding GoToMarkupCommand}"
HorizontalOptions="Center" />

<Button
Text="Click to go to scope check page"
FontAttributes="Bold"
Grid.Row="3"
SemanticProperties.Hint="Counts the number of times you click"
Command="{Binding GoToScopeCheckCommand}"
HorizontalOptions="Center" />

<Image Grid.Row="4"
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
Expand Down
11 changes: 5 additions & 6 deletions src/DemoProject/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace DemoProject
{
public static partial class MauiProgram
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
Expand All @@ -13,16 +13,15 @@ public static MauiApp CreateMauiApp()
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
})
.UseAutodependencies();


#if DEBUG
builder.Logging.AddDebug();
builder.Logging.AddDebug();
#endif
UseAutoreg(builder.Services);

return builder.Build();
}

static partial void UseAutoreg(IServiceCollection services);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DemoProject.ParamPage"
Title="ParamPage"
x:Class="DemoProject.PageParamPage"
Title="PageParamPage"
BackgroundColor="White">
<StackLayout>
<VerticalStackLayout>
<Label Text="Welcome to .NET MAUI!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
Expand All @@ -14,5 +14,5 @@
<Label Text="{Binding NameParam}"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</VerticalStackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace DemoProject;

public partial class ParamPage : ContentPage
public partial class PageParamPage : ContentPage
{
public ParamPage(ParamViewModel viewModel, string name)
public PageParamPage(PageParamViewModel viewModel, string name)
{
InitializeComponent();
viewModel.NameParam = name;
Expand Down
52 changes: 52 additions & 0 deletions src/DemoProject/Pages/ScopeCheckPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DemoProject.Pages.ScopeCheckPage"
Title="ScopeCheckPage">
<VerticalStackLayout>
<Label
Text="Value from default service"
FontSize="Large"
VerticalOptions="Center"
HorizontalTextAlignment="Center"
HorizontalOptions="Center" />
<Label
Text="(should retain value between page visits)"
FontSize="Large"
VerticalOptions="Center"
HorizontalTextAlignment="Center"
HorizontalOptions="Center" />

<Label
Text="{Binding DefaultCount}"
FontSize="Large"
VerticalOptions="Center"
HorizontalTextAlignment="Center"
HorizontalOptions="Center"
Margin="0,0,0,30"/>

<Label
Text="Value from default service"
FontSize="Large"
VerticalOptions="Center"
HorizontalTextAlignment="Center"
HorizontalOptions="Center" />
<Label
Text="(should reset each page visit)"
FontSize="Large"
VerticalOptions="Center"
HorizontalTextAlignment="Center"
HorizontalOptions="Center" />

<Label
Text="{Binding CustomCount}"
FontSize="Large"
VerticalOptions="Center"
HorizontalTextAlignment="Center"
HorizontalOptions="Center"
Margin="0,0,0,30"/>

<Button Text="Increase count"
Command="{Binding IncreaseCountCommand}"/>
</VerticalStackLayout>
</ContentPage>
10 changes: 10 additions & 0 deletions src/DemoProject/Pages/ScopeCheckPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace DemoProject.Pages;

public partial class ScopeCheckPage : ContentPage
{
public ScopeCheckPage(ScopeCheckViewModel viewModel)
{
InitializeComponent();
BindingContext = viewModel;
}
}
17 changes: 17 additions & 0 deletions src/DemoProject/Pages/VmParamPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DemoProject.Pages.VmParamPage"
Title="VmParamPage">
<VerticalStackLayout>
<Label Text="Welcome to .NET MAUI!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
<Label Text="Your name is:"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
<Label Text="{Binding NameParam}"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</VerticalStackLayout>
</ContentPage>
10 changes: 10 additions & 0 deletions src/DemoProject/Pages/VmParamPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace DemoProject.Pages;

public partial class VmParamPage : ContentPage
{
public VmParamPage(VmParamViewModel viewModel)
{
InitializeComponent();
BindingContext = viewModel;
}
}
Loading

0 comments on commit 9bff31e

Please sign in to comment.