├── assets
└── gfg.png
├── src
├── DemoProject
│ ├── GlobalUsings.cs
│ ├── Services
│ │ ├── INameService.cs
│ │ ├── NameService.cs
│ │ ├── IIgnoredService.cs
│ │ ├── IPopupDependencyService.cs
│ │ ├── IDefaultScopedService.cs
│ │ └── ICustomScopedService.cs
│ ├── Resources
│ │ ├── Images
│ │ │ └── dotnet_bot.png
│ │ ├── Fonts
│ │ │ ├── OpenSans-Regular.ttf
│ │ │ └── OpenSans-Semibold.ttf
│ │ ├── AppIcon
│ │ │ ├── appicon.svg
│ │ │ └── appiconfg.svg
│ │ ├── Raw
│ │ │ └── AboutAssets.txt
│ │ ├── Splash
│ │ │ └── splash.svg
│ │ └── Styles
│ │ │ ├── Colors.xaml
│ │ │ └── Styles.xaml
│ ├── ViewModels
│ │ ├── BaseViewModel.cs
│ │ ├── PageParamViewModel.cs
│ │ ├── VmParamViewModel.cs
│ │ ├── AggregateExceptionViewModel.cs
│ │ ├── MarkupViewModel.cs
│ │ ├── ScopeCheckViewModel.cs
│ │ ├── DesktopPageViewModel.cs
│ │ └── MainViewModel.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── AppShell.xaml.cs
│ ├── Pages
│ │ ├── MarkupPage.xaml.cs
│ │ ├── VmParamPage.xaml.cs
│ │ ├── ScopeCheckPage.xaml.cs
│ │ ├── DesktopRootPage.xaml.cs
│ │ ├── AggregateExceptionPage.xaml.cs
│ │ ├── PageParamPage.xaml.cs
│ │ ├── AggregateExceptionPage.xaml
│ │ ├── BrokenPage.cs
│ │ ├── PageParamPage.xaml
│ │ ├── VmParamPage.xaml
│ │ ├── MarkupPage.xaml
│ │ ├── ScopeCheckPage.xaml
│ │ └── DesktopRootPage.xaml
│ ├── Platforms
│ │ ├── Android
│ │ │ ├── Resources
│ │ │ │ └── values
│ │ │ │ │ └── colors.xml
│ │ │ ├── MainApplication.cs
│ │ │ ├── AndroidManifest.xml
│ │ │ └── MainActivity.cs
│ │ ├── iOS
│ │ │ ├── AppDelegate.cs
│ │ │ ├── Program.cs
│ │ │ ├── Info.plist
│ │ │ └── Resources
│ │ │ │ └── PrivacyInfo.xcprivacy
│ │ ├── MacCatalyst
│ │ │ ├── AppDelegate.cs
│ │ │ ├── Program.cs
│ │ │ ├── Entitlements.plist
│ │ │ └── Info.plist
│ │ ├── Windows
│ │ │ ├── App.xaml
│ │ │ ├── app.manifest
│ │ │ ├── App.xaml.cs
│ │ │ └── Package.appxmanifest
│ │ └── Tizen
│ │ │ ├── Main.cs
│ │ │ └── tizen-manifest.xml
│ ├── MainPage.xaml.cs
│ ├── App.xaml.cs
│ ├── Popups
│ │ ├── ViewModels
│ │ │ ├── PopupViewModel.cs
│ │ │ └── ParamPopupViewModel.cs
│ │ └── Pages
│ │ │ ├── EasyPopup.xaml.cs
│ │ │ ├── ParamPopup.xaml.cs
│ │ │ ├── ParamPopup.xaml
│ │ │ └── EasyPopup.xaml
│ ├── Conversers
│ │ └── NullToVisibleConverter.cs
│ ├── App.xaml
│ ├── AppShell.xaml
│ ├── MauiProgram.cs
│ ├── MainPage.xaml
│ └── DemoProject.csproj
├── Maui.Plugins.PageResolver.Attributes
│ ├── IgnoreAttribute.cs
│ ├── SingletonAttribute.cs
│ ├── TransientAttribute.cs
│ ├── NoAutoDependenciesAttribute.cs
│ └── Maui.Plugins.PageResolver.Attributes.csproj
├── Maui.Plugins.PageResolver
│ ├── Initializer.cs
│ ├── MarkupExtensions.cs
│ ├── Maui.Plugins.PageResolver.csproj
│ ├── Resolver.cs
│ ├── StartupExtensions.cs
│ └── NavigationExtensions.cs
├── Maui.Plugins.PageResolver.SourceGenerators
│ ├── Log.cs
│ ├── Maui.Plugins.PageResolver.SourceGenerators.csproj
│ └── AutoDependencies.cs
├── Maui.Plugins.PageResolver.MopupsExtensions
│ ├── MopupExtensions.cs
│ └── Maui.Plugins.PageResolver.MopupsExtensions.csproj
└── Maui.Plugins.PageResolver.sln
├── .github
├── ISSUE_TEMPLATE
│ ├── feature_request.md
│ └── bug_report.md
└── workflows
│ └── ci.yml
├── README.md
├── LICENSE
└── .gitignore
/assets/gfg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matt-goldman/Maui.Plugins.PageResolver/HEAD/assets/gfg.png
--------------------------------------------------------------------------------
/src/DemoProject/GlobalUsings.cs:
--------------------------------------------------------------------------------
1 | global using DemoProject.Services;
2 | global using DemoProject.ViewModels;
3 | global using Maui.Plugins.PageResolver;
--------------------------------------------------------------------------------
/src/DemoProject/Services/INameService.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.Services;
2 |
3 | public interface INameService
4 | {
5 | string GetName();
6 | }
7 |
--------------------------------------------------------------------------------
/src/DemoProject/Resources/Images/dotnet_bot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matt-goldman/Maui.Plugins.PageResolver/HEAD/src/DemoProject/Resources/Images/dotnet_bot.png
--------------------------------------------------------------------------------
/src/DemoProject/Resources/Fonts/OpenSans-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matt-goldman/Maui.Plugins.PageResolver/HEAD/src/DemoProject/Resources/Fonts/OpenSans-Regular.ttf
--------------------------------------------------------------------------------
/src/DemoProject/Resources/Fonts/OpenSans-Semibold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matt-goldman/Maui.Plugins.PageResolver/HEAD/src/DemoProject/Resources/Fonts/OpenSans-Semibold.ttf
--------------------------------------------------------------------------------
/src/DemoProject/ViewModels/BaseViewModel.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.ViewModels;
2 |
3 | public class BaseViewModel
4 | {
5 | public INavigation? Navigation { get; set; }
6 | }
7 |
--------------------------------------------------------------------------------
/src/DemoProject/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "Windows Machine": {
4 | "commandName": "Project",
5 | "nativeDebugging": false
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/src/DemoProject/AppShell.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject;
2 |
3 | public partial class AppShell : Shell
4 | {
5 | public AppShell()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/DemoProject/Pages/MarkupPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.Pages;
2 |
3 | public partial class MarkupPage : ContentPage
4 | {
5 | public MarkupPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
--------------------------------------------------------------------------------
/src/DemoProject/ViewModels/PageParamViewModel.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.ViewModels;
2 |
3 | public class PageParamViewModel
4 | {
5 | public string NameParam { get; set; } = string.Empty;
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/DemoProject/Services/NameService.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.Services;
2 |
3 | public class NameService : INameService
4 | {
5 | public string GetName()
6 | {
7 | return "Maui";
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver.Attributes/IgnoreAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace Maui.Plugins.PageResolver.Attributes;
2 |
3 | [AttributeUsage(AttributeTargets.Class, Inherited = false)]
4 | public class IgnoreAttribute : Attribute { }
5 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver.Attributes/SingletonAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace Maui.Plugins.PageResolver.Attributes;
2 |
3 | [AttributeUsage(AttributeTargets.Class, Inherited = false)]
4 | public class SingletonAttribute : Attribute { }
5 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver.Attributes/TransientAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace Maui.Plugins.PageResolver.Attributes;
2 |
3 | [AttributeUsage(AttributeTargets.Class, Inherited = false)]
4 | public class TransientAttribute : Attribute { }
5 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver.Attributes/NoAutoDependenciesAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace Maui.Plugins.PageResolver.Attributes;
2 |
3 | [AttributeUsage(AttributeTargets.Class, Inherited = false)]
4 | public class NoAutoDependenciesAttribute : Attribute { }
--------------------------------------------------------------------------------
/src/DemoProject/Pages/VmParamPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.Pages;
2 |
3 | public partial class VmParamPage : ContentPage
4 | {
5 | public VmParamPage(VmParamViewModel viewModel)
6 | {
7 | InitializeComponent();
8 | BindingContext = viewModel;
9 | }
10 | }
--------------------------------------------------------------------------------
/src/DemoProject/Pages/ScopeCheckPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.Pages;
2 |
3 | public partial class ScopeCheckPage : ContentPage
4 | {
5 | public ScopeCheckPage(ScopeCheckViewModel viewModel)
6 | {
7 | InitializeComponent();
8 | BindingContext = viewModel;
9 | }
10 | }
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/Android/Resources/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #512BD4
4 | #2B0B98
5 | #2B0B98
6 |
--------------------------------------------------------------------------------
/src/DemoProject/Resources/AppIcon/appicon.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/iOS/AppDelegate.cs:
--------------------------------------------------------------------------------
1 | using Foundation;
2 |
3 | namespace DemoProject;
4 |
5 | [Register("AppDelegate")]
6 | public class AppDelegate : MauiUIApplicationDelegate
7 | {
8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
9 | }
10 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/MacCatalyst/AppDelegate.cs:
--------------------------------------------------------------------------------
1 | using Foundation;
2 |
3 | namespace DemoProject;
4 |
5 | [Register("AppDelegate")]
6 | public class AppDelegate : MauiUIApplicationDelegate
7 | {
8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
9 | }
10 |
--------------------------------------------------------------------------------
/src/DemoProject/MainPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject;
2 |
3 | public partial class MainPage : ContentPage
4 | {
5 | public MainPage(MainViewModel viewModel)
6 | {
7 | viewModel.Navigation = Navigation;
8 | BindingContext = viewModel;
9 | InitializeComponent();
10 | }
11 | }
--------------------------------------------------------------------------------
/src/DemoProject/App.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject;
2 |
3 | public partial class App : Application
4 | {
5 | public App()
6 | {
7 | InitializeComponent();
8 | }
9 |
10 | protected override Window CreateWindow(IActivationState? activationState)
11 | {
12 | return new Window(new AppShell());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver.Attributes/Maui.Plugins.PageResolver.Attributes.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DemoProject/Popups/ViewModels/PopupViewModel.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.Popups.ViewModels;
2 |
3 | public class PopupViewModel
4 | {
5 | public string Message { get; set; }
6 |
7 | public PopupViewModel(IPopupDependencyService dependency)
8 | {
9 | Message = dependency.GetMessage();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DemoProject/Services/IIgnoredService.cs:
--------------------------------------------------------------------------------
1 | using Maui.Plugins.PageResolver.Attributes;
2 |
3 | namespace DemoProject.Services;
4 |
5 | public interface IIgnoredService
6 | {
7 | string GetHello();
8 | }
9 |
10 | [Ignore]
11 | public class IgnoredService : IIgnoredService
12 | {
13 | public string GetHello() => "Hello";
14 | }
15 |
--------------------------------------------------------------------------------
/src/DemoProject/Pages/DesktopRootPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.Pages;
2 |
3 | [XamlCompilation(XamlCompilationOptions.Compile)]
4 | public partial class DesktopRootPage : ContentPage
5 | {
6 | public DesktopRootPage(DesktopPageViewModel viewModel)
7 | {
8 | InitializeComponent();
9 | BindingContext = viewModel;
10 | }
11 | }
--------------------------------------------------------------------------------
/src/DemoProject/Popups/Pages/EasyPopup.xaml.cs:
--------------------------------------------------------------------------------
1 | using DemoProject.Popups.ViewModels;
2 | using Mopups.Pages;
3 |
4 | namespace DemoProject.Popups.Pages;
5 |
6 | public partial class EasyPopup : PopupPage
7 | {
8 | public EasyPopup(PopupViewModel viewModel)
9 | {
10 | InitializeComponent();
11 |
12 | BindingContext = viewModel;
13 | }
14 | }
--------------------------------------------------------------------------------
/src/DemoProject/Pages/AggregateExceptionPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.Pages;
2 |
3 | public partial class AggregateExceptionPage : ContentPage
4 | {
5 | public AggregateExceptionPage(AggregateExceptionViewModel vm)
6 | {
7 | InitializeComponent();
8 |
9 | throw new MissingMemberException("This is a test exception");
10 | }
11 | }
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/Windows/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DemoProject/Popups/Pages/ParamPopup.xaml.cs:
--------------------------------------------------------------------------------
1 | using DemoProject.Popups.ViewModels;
2 | using Mopups.Pages;
3 |
4 | namespace DemoProject.Popups.Pages;
5 |
6 | public partial class ParamPopup : PopupPage
7 | {
8 | public ParamPopup(ParamPopupViewModel viewModel)
9 | {
10 | InitializeComponent();
11 |
12 | BindingContext = viewModel;
13 | }
14 | }
--------------------------------------------------------------------------------
/src/DemoProject/Popups/ViewModels/ParamPopupViewModel.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.Popups.ViewModels;
2 |
3 | public class ParamPopupViewModel
4 | {
5 | public string Message { get; set; }
6 |
7 | public ParamPopupViewModel(IPopupDependencyService dependency, string param)
8 | {
9 | Message = dependency.GetParamMessage(param);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DemoProject/Pages/PageParamPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject;
2 |
3 | [XamlCompilation(XamlCompilationOptions.Compile)]
4 | public partial class PageParamPage : ContentPage
5 | {
6 | public PageParamPage(PageParamViewModel viewModel, string name)
7 | {
8 | InitializeComponent();
9 | viewModel.NameParam = name;
10 | BindingContext = viewModel;
11 | }
12 | }
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/Tizen/Main.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Maui;
3 | using Microsoft.Maui.Hosting;
4 |
5 | namespace DemoProject;
6 |
7 | class Program : MauiApplication
8 | {
9 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
10 |
11 | static void Main(string[] args)
12 | {
13 | var app = new Program();
14 | app.Run(args);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/Android/MainApplication.cs:
--------------------------------------------------------------------------------
1 | using Android.App;
2 | using Android.Runtime;
3 |
4 | namespace DemoProject;
5 |
6 | [Application]
7 | public class MainApplication : MauiApplication
8 | {
9 | public MainApplication(IntPtr handle, JniHandleOwnership ownership)
10 | : base(handle, ownership)
11 | {
12 | }
13 |
14 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
15 | }
16 |
--------------------------------------------------------------------------------
/src/DemoProject/ViewModels/VmParamViewModel.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.ViewModels;
2 |
3 | public class VmParamViewModel
4 | {
5 | public string NameParam { get; set; }
6 |
7 | public string NameFromServiceParam { get; set; }
8 |
9 | public VmParamViewModel(INameService nameService, string name)
10 | {
11 | NameParam = name;
12 | NameFromServiceParam = nameService.GetName();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/iOS/Program.cs:
--------------------------------------------------------------------------------
1 | using ObjCRuntime;
2 | using UIKit;
3 |
4 | namespace DemoProject;
5 |
6 | public class Program
7 | {
8 | // This is the main entry point of the application.
9 | static void Main(string[] args)
10 | {
11 | // if you want to use a different Application Delegate class from "AppDelegate"
12 | // you can specify it here.
13 | UIApplication.Main(args, null, typeof(AppDelegate));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/MacCatalyst/Program.cs:
--------------------------------------------------------------------------------
1 | using ObjCRuntime;
2 | using UIKit;
3 |
4 | namespace DemoProject;
5 |
6 | public class Program
7 | {
8 | // This is the main entry point of the application.
9 | static void Main(string[] args)
10 | {
11 | // if you want to use a different Application Delegate class from "AppDelegate"
12 | // you can specify it here.
13 | UIApplication.Main(args, null, typeof(AppDelegate));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/DemoProject/ViewModels/AggregateExceptionViewModel.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.ViewModels;
2 |
3 | public class AggregateExceptionViewModel
4 | {
5 | public string NameParam { get; set; }
6 |
7 | public string NameFromServiceParam { get; set; }
8 |
9 | public AggregateExceptionViewModel(INameService nameService, string name)
10 | {
11 | NameParam = name;
12 | NameFromServiceParam = nameService.GetName();
13 | }
14 | }
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/Android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver/Initializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Maui.Hosting;
3 |
4 | namespace Maui.Plugins.PageResolver
5 | {
6 | internal class Initializer : IMauiInitializeService
7 | {
8 | #region Implementation of IMauiInitializeService
9 |
10 | ///
11 | public void Initialize( IServiceProvider services )
12 | {
13 | Resolver.RegisterServiceProvider( services );
14 | }
15 |
16 | #endregion
17 | }
18 | }
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/Android/MainActivity.cs:
--------------------------------------------------------------------------------
1 | using Android.App;
2 | using Android.Content.PM;
3 | using Android.OS;
4 |
5 | namespace DemoProject;
6 |
7 | [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
8 | public class MainActivity : MauiAppCompatActivity
9 | {
10 | }
11 |
--------------------------------------------------------------------------------
/src/DemoProject/Conversers/NullToVisibleConverter.cs:
--------------------------------------------------------------------------------
1 | using System.Globalization;
2 |
3 | namespace DemoProject.Conversers;
4 |
5 | internal class NullToVisibleConverter : IValueConverter
6 | {
7 | public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
8 | {
9 | return value != null;
10 | }
11 |
12 | public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
13 | {
14 | throw new NotImplementedException();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/DemoProject/Pages/AggregateExceptionPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
--------------------------------------------------------------------------------
/src/DemoProject/Services/IPopupDependencyService.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.Services;
2 |
3 | public interface IPopupDependencyService
4 | {
5 | string GetMessage();
6 | string GetParamMessage(string param);
7 | }
8 |
9 | public class PopupDependencyService : IPopupDependencyService
10 | {
11 | public string GetMessage()
12 | {
13 | return "Hello from PopupDependencyService!";
14 | }
15 |
16 | public string GetParamMessage(string param)
17 | {
18 | return $"Hello from PopupDependencyService with param: {param}";
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/DemoProject/Pages/BrokenPage.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.Pages;
2 |
3 | ///
4 | /// This page has a dependency on a service that should not be registered. Runtime exception expected when navigating to this page.
5 | ///
6 | public class BrokenPage : ContentPage
7 | {
8 | public BrokenPage(IIgnoredService ignoredService)
9 | {
10 | Content = new VerticalStackLayout
11 | {
12 | Children = {
13 | new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = ignoredService.GetHello()
14 | }
15 | }
16 | };
17 | }
18 | }
--------------------------------------------------------------------------------
/src/DemoProject/Services/IDefaultScopedService.cs:
--------------------------------------------------------------------------------
1 | namespace DemoProject.Services;
2 |
3 | public interface IDefaultScopedService
4 | {
5 | int GetCount();
6 | void IncreaseCount(int? count = null);
7 | }
8 |
9 | public class DefaultScopedService : IDefaultScopedService
10 | {
11 | private int _count = 0;
12 |
13 | public int GetCount()
14 | {
15 | return _count;
16 | }
17 |
18 | public void IncreaseCount(int? count = null)
19 | {
20 | if (count.HasValue)
21 | {
22 | _count += count.Value;
23 | }
24 | else
25 | {
26 | _count++;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/DemoProject/Services/ICustomScopedService.cs:
--------------------------------------------------------------------------------
1 | using Maui.Plugins.PageResolver.Attributes;
2 |
3 | namespace DemoProject.Services;
4 |
5 | public interface ICustomScopedService : IDefaultScopedService
6 | {
7 | }
8 |
9 | [Transient]
10 | public class CustomScopedService : ICustomScopedService
11 | {
12 | private int _count = 0;
13 |
14 | public int GetCount()
15 | {
16 | return _count;
17 | }
18 |
19 | public void IncreaseCount(int? count = null)
20 | {
21 | if (count.HasValue)
22 | {
23 | _count += count.Value;
24 | }
25 | else
26 | {
27 | _count++;
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/DemoProject/ViewModels/MarkupViewModel.cs:
--------------------------------------------------------------------------------
1 | using CommunityToolkit.Mvvm.ComponentModel;
2 | using System.Windows.Input;
3 |
4 | namespace DemoProject.ViewModels;
5 |
6 | [ObservableObject]
7 | public partial class MarkupViewModel : BaseViewModel
8 | {
9 | private readonly INameService _nameService;
10 |
11 | [ObservableProperty]
12 | private string _name = string.Empty;
13 |
14 | public ICommand GetNameCommand => new Command(() => GetName());
15 |
16 | public MarkupViewModel(INameService nameService)
17 | {
18 | _nameService = nameService;
19 | }
20 |
21 | void GetName()
22 | {
23 | Name = _nameService.GetName();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/src/DemoProject/App.xaml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/DemoProject/Resources/Raw/AboutAssets.txt:
--------------------------------------------------------------------------------
1 | Any raw assets you want to be deployed with your application can be placed in
2 | this directory (and child directories). Deployment of the asset to your application
3 | is automatically handled by the following `MauiAsset` Build Action within your `.csproj`.
4 |
5 |
6 |
7 | These files will be deployed with your package and will be accessible using Essentials:
8 |
9 | async Task LoadMauiAsset()
10 | {
11 | using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt");
12 | using var reader = new StreamReader(stream);
13 |
14 | var contents = reader.ReadToEnd();
15 | }
16 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/MacCatalyst/Entitlements.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | com.apple.security.app-sandbox
8 |
9 |
10 | com.apple.security.network.client
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/DemoProject/AppShell.xaml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
16 |
17 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/Windows/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 | true/PM
12 | PerMonitorV2, PerMonitor
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/Tizen/tizen-manifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | maui-appicon-placeholder
7 |
8 |
9 |
10 |
11 | http://tizen.org/privilege/internet
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/Windows/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.UI.Xaml;
2 |
3 | // To learn more about WinUI, the WinUI project structure,
4 | // and more about our project templates, see: http://aka.ms/winui-project-info.
5 |
6 | namespace DemoProject.WinUI;
7 |
8 | ///
9 | /// Provides application-specific behavior to supplement the default Application class.
10 | ///
11 | public partial class App : MauiWinUIApplication
12 | {
13 | ///
14 | /// Initializes the singleton application object. This is the first line of authored code
15 | /// executed, and as such is the logical equivalent of main() or WinMain().
16 | ///
17 | public App()
18 | {
19 | this.InitializeComponent();
20 | }
21 |
22 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver.SourceGenerators/Log.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 |
4 | namespace Maui.Plugins.PageResolver.SourceGenerators
5 | {
6 | public static class Log
7 | {
8 | private static StringBuilder _builder;
9 |
10 | public static void Init(StringBuilder builder)
11 | {
12 | _builder = builder;
13 | }
14 |
15 | public static void Write(string entry)
16 | {
17 | _builder.Append($"{DateTime.Now.ToString()} - INFO - {entry}");
18 | }
19 |
20 | public static void WriteLine(string entry)
21 | {
22 | _builder.AppendLine($"{DateTime.Now.ToString()} - INFO - {entry}");
23 | }
24 |
25 | public static void FlushLog()
26 | {
27 | System.Diagnostics.Debug.Write(_builder.ToString());
28 |
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver.MopupsExtensions/MopupExtensions.cs:
--------------------------------------------------------------------------------
1 | using Mopups.Interfaces;
2 | using Mopups.Pages;
3 |
4 | namespace Maui.Plugins.PageResolver;
5 |
6 | public static class MopupExtensions
7 | {
8 | public static async Task PushAsync(this IPopupNavigation navigation) where T: PopupPage
9 | {
10 | var popup = Resolver.Resolve() as PopupPage
11 | ?? throw new ArgumentException("Could not resolve popup page");
12 |
13 | await navigation.PushAsync(popup, true);
14 | }
15 |
16 | public static async Task PushAsync(this IPopupNavigation navigation, params object[] parameters) where T : PopupPage
17 | {
18 | var popup = NavigationExtensions.ResolvePage(parameters) as PopupPage
19 | ?? throw new ArgumentException("Could not resolve popup page");
20 |
21 | await navigation.PushAsync(popup, true);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/DemoProject/MauiProgram.cs:
--------------------------------------------------------------------------------
1 | using DemoProject.Popups.Pages;
2 | using DemoProject.Popups.ViewModels;
3 | using Microsoft.Extensions.Logging;
4 | using Mopups.Hosting;
5 |
6 | namespace DemoProject;
7 |
8 | public static class MauiProgram
9 | {
10 | public static MauiApp CreateMauiApp()
11 | {
12 | var builder = MauiApp.CreateBuilder();
13 | builder
14 | .UseMauiApp()
15 | .ConfigureFonts(fonts =>
16 | {
17 | fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
18 | fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
19 | })
20 | .ConfigureMopups()
21 | .UseAutodependencies();
22 |
23 | builder.Services.AddTransient();
24 | builder.Services.AddTransient();
25 |
26 | StartupExtensions.UpsertViewModelMapping();
27 |
28 | #if DEBUG
29 | builder.Logging.AddDebug();
30 | #endif
31 |
32 | return builder.Build();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/DemoProject/Pages/PageParamPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
11 |
14 |
17 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PageResolver (Deprecated)
2 |
3 | This repository is no longer maintained.
4 |
5 | The PageResolver library has been renamed, superseded, and fully replaced by:
6 |
7 | ## Plugin.Maui.SmartNavigation
8 |
9 | Migration/upgrade is simple, but there are a couple of breaking changes.
10 |
11 | See the migration guide: [New repository](ttps://github.com/matt-goldman/Plugin.Maui.SmartNavigation)
12 |
13 | New NuGet package: `Plugin.Maui.SmartNavigation`
14 |
15 | SmartNavigation is the direct continuation of this project.
16 |
17 | It includes:
18 |
19 | * A cleaner API surface
20 | * Stronger DI integration
21 | * Type-safe Shell routing
22 | * Improved lifecycle behaviour
23 | * A new source generator
24 | * Updated naming aligned with .NET conventions
25 | * Full support for .NET 10
26 |
27 | This repository is kept as a historical reference only and will not receive updates, fixes, or releases.
28 |
29 | All future development takes place in the SmartNavigation repository.
30 |
31 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/src/DemoProject/Pages/VmParamPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
13 |
16 |
17 |
20 |
23 |
24 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver/MarkupExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.DependencyInjection;
2 | using Microsoft.Maui.Controls;
3 | using Microsoft.Maui.Controls.Xaml;
4 | using System;
5 |
6 | namespace Maui.Plugins.PageResolver;
7 |
8 | public class ResolveViewModel : IMarkupExtension
9 | {
10 | public T ViewModel { get; set; }
11 |
12 | public T ProvideValue(IServiceProvider serviceProvider)
13 | {
14 | var sp = Resolver.GetServiceProvider();
15 | var result = sp.GetRequiredService();
16 |
17 | return result;
18 | }
19 |
20 | object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
21 | {
22 | return ProvideValue(serviceProvider);
23 | }
24 | }
25 |
26 | [ContentProperty(nameof(ViewModel))]
27 | public class ResolveViewModel : IMarkupExtension
28 | {
29 | public Type ViewModel { get; set; }
30 |
31 | public object ProvideValue(IServiceProvider serviceProvider)
32 | {
33 | var sp = Resolver.GetServiceProvider();
34 | var result = sp.GetRequiredService(ViewModel);
35 |
36 | return result;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Matt Goldman
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | LSRequiresIPhoneOS
6 |
7 | UIDeviceFamily
8 |
9 | 1
10 | 2
11 |
12 | UIRequiredDeviceCapabilities
13 |
14 | arm64
15 |
16 | UISupportedInterfaceOrientations
17 |
18 | UIInterfaceOrientationPortrait
19 | UIInterfaceOrientationLandscapeLeft
20 | UIInterfaceOrientationLandscapeRight
21 |
22 | UISupportedInterfaceOrientations~ipad
23 |
24 | UIInterfaceOrientationPortrait
25 | UIInterfaceOrientationPortraitUpsideDown
26 | UIInterfaceOrientationLandscapeLeft
27 | UIInterfaceOrientationLandscapeRight
28 |
29 | XSAppIconAssets
30 | Assets.xcassets/appicon.appiconset
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/DemoProject/Popups/Pages/ParamPopup.xaml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
20 |
21 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/DemoProject/Popups/Pages/EasyPopup.xaml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
20 |
21 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/DemoProject/ViewModels/ScopeCheckViewModel.cs:
--------------------------------------------------------------------------------
1 | using CommunityToolkit.Mvvm.ComponentModel;
2 | using System.Windows.Input;
3 |
4 | namespace DemoProject.ViewModels;
5 |
6 | [ObservableObject]
7 | public partial class ScopeCheckViewModel : BaseViewModel
8 | {
9 | private readonly IDefaultScopedService _defaultScopedService;
10 | private readonly ICustomScopedService _customScopedService;
11 |
12 | [ObservableProperty]
13 | private int _defaultCount;
14 |
15 | [ObservableProperty]
16 | private int _customCount;
17 |
18 | public ICommand IncreaseCountCommand => new Command(() => IncreaseCount());
19 |
20 | public ScopeCheckViewModel(IDefaultScopedService defaultScopedService, ICustomScopedService customScopedService)
21 | {
22 | _defaultScopedService = defaultScopedService;
23 | _customScopedService = customScopedService;
24 |
25 | DefaultCount = _defaultScopedService.GetCount();
26 | CustomCount = _customScopedService.GetCount();
27 | }
28 |
29 | public void IncreaseCount()
30 | {
31 | _defaultScopedService.IncreaseCount();
32 | _customScopedService.IncreaseCount();
33 |
34 | DefaultCount = _defaultScopedService.GetCount();
35 | CustomCount = _customScopedService.GetCount();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | version:
7 | description: 'Version to build'
8 | required: true
9 | default: '0.0.0'
10 |
11 |
12 | jobs:
13 | build:
14 |
15 | env:
16 | BUILD_CONFIG: 'Release'
17 | SOLUTION: '.\src\Maui.Plugins.PageResolver.sln'
18 |
19 | runs-on: windows-latest
20 |
21 | steps:
22 | - uses: actions/checkout@v2
23 |
24 |
25 | # - name: Install workloads
26 | # run: dotnet workload install maui maui-windows
27 |
28 | # - name: Restore dependencies
29 | # run: dotnet restore $env:SOLUTION
30 |
31 | - name: Setup .NET
32 | uses: actions/setup-dotnet@v1
33 | with:
34 | dotnet-version: 8.x.x
35 | include-prerelease: false
36 |
37 | - name: Install workloads
38 | run: dotnet workload install maui
39 |
40 | - name: Build
41 | run: dotnet build $env:SOLUTION --configuration $env:BUILD_CONFIG -p:Version=${{ github.event.inputs.version }}
42 |
43 | # - name: Run tests
44 | # run: dotnet test /p:Configuration=$env:BUILD_CONFIG --no-restore --no-build --verbosity normal
45 |
46 | - name: Setup NuGet
47 | uses: NuGet/setup-nuget@v1.0.5
48 |
49 | - name: Publish
50 | run: nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}}
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver.MopupsExtensions/Maui.Plugins.PageResolver.MopupsExtensions.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 8.0
5 | net$(NetCoreVersion)
6 | Enable
7 | true
8 | Matt Goldman
9 |
10 | https://github.com/matt-goldman/Maui.Plugins.PageResolver
11 | Matt Goldman 2024
12 | true
13 | Goldie.MauiPlugins.PageResolver.MopupsExtensions
14 |
15 | Mopups extensions for PageResolver - push popup pages with resolved dependencies
16 | gfg.png
17 |
18 | LICENSE
19 | 2.5.1
20 |
21 |
22 |
23 |
24 |
25 | True
26 |
27 |
28 |
29 |
30 | True
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/DemoProject/Pages/MarkupPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
12 |
13 |
17 |
18 |
25 |
26 |
33 |
34 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/MacCatalyst/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | UIDeviceFamily
15 |
16 | 2
17 |
18 | UIRequiredDeviceCapabilities
19 |
20 | arm64
21 |
22 | UISupportedInterfaceOrientations
23 |
24 | UIInterfaceOrientationPortrait
25 | UIInterfaceOrientationLandscapeLeft
26 | UIInterfaceOrientationLandscapeRight
27 |
28 | UISupportedInterfaceOrientations~ipad
29 |
30 | UIInterfaceOrientationPortrait
31 | UIInterfaceOrientationPortraitUpsideDown
32 | UIInterfaceOrientationLandscapeLeft
33 | UIInterfaceOrientationLandscapeRight
34 |
35 | XSAppIconAssets
36 | Assets.xcassets/appicon.appiconset
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/DemoProject/Resources/Splash/splash.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/DemoProject/Resources/AppIcon/appiconfg.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver.SourceGenerators/Maui.Plugins.PageResolver.SourceGenerators.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | Matt Goldman
6 |
7 | true
8 | Goldie.MauiPlugins.PageResolver.SourceGenerator
9 | Source generators used by PageResolver
10 | Matt Goldman 2023
11 | https://github.com/matt-goldman/Maui.Plugins.PageResolver
12 | gfg.png
13 | LICENSE
14 | 2.0.1
15 | false
16 |
17 |
18 |
19 |
20 |
21 | True
22 |
23 |
24 |
25 | True
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | all
40 | runtime; build; native; contentfiles; analyzers; buildtransitive
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver/Maui.Plugins.PageResolver.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 8.0
5 | net$(NetCoreVersion)
6 | true
7 | Matt Goldman
8 |
9 | https://github.com/matt-goldman/Maui.Plugins.PageResolver
10 | Matt Goldman 2024
11 | true
12 | Goldie.MauiPlugins.PageResolver
13 |
14 | A simple lightweight page resolver for dotnet MAUI projects. Uses the built in DI container to resolve dependencies and push a resolved page onto the navigation stack.
15 | gfg.png
16 |
17 | LICENSE
18 | 2.5.3
19 |
20 |
21 |
22 |
23 | True
24 |
25 |
26 |
27 | True
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/DemoProject/ViewModels/DesktopPageViewModel.cs:
--------------------------------------------------------------------------------
1 | using CommunityToolkit.Mvvm.ComponentModel;
2 | using CommunityToolkit.Mvvm.Input;
3 | using DemoProject.Pages;
4 |
5 | namespace DemoProject.ViewModels;
6 |
7 | public partial class DesktopPageViewModel
8 | : ObservableObject
9 | {
10 | Window? _vmWindow;
11 | Window? _winParamsWindow;
12 | Window? _vmParamsWindow;
13 |
14 | [ObservableProperty]
15 | bool _isMainWindowOpen;
16 |
17 | [ObservableProperty]
18 | bool _isWinParamsWindowOpen;
19 |
20 | [ObservableProperty]
21 | bool _isVmParamsWindowOpen;
22 |
23 | [RelayCommand]
24 | public void OpenWindowWithVm()
25 | {
26 | _vmWindow = App.Current?.OpenWindow();
27 | IsMainWindowOpen = true;
28 | }
29 |
30 | [RelayCommand]
31 | public void OpenWindowWithWinParams()
32 | {
33 | _winParamsWindow = App.Current?.OpenWindow("Name passed as page parameter");
34 | IsWinParamsWindowOpen = true;
35 | }
36 |
37 | [RelayCommand]
38 | public void OpenWindowWithVmParams()
39 | {
40 | _vmParamsWindow = App.Current?.OpenWindow("Name passed as vm parameter");
41 |
42 | _vmParamsWindow!.Width = 400;
43 | _vmParamsWindow.Height = 400;
44 | _vmParamsWindow.X = 100;
45 | _vmParamsWindow.Y = 100;
46 |
47 | IsVmParamsWindowOpen = true;
48 | }
49 |
50 | [RelayCommand]
51 | public void CloseWindowWithVm()
52 | {
53 | App.Current?.CloseWindow(_vmWindow!);
54 | IsMainWindowOpen = false;
55 | }
56 |
57 | [RelayCommand]
58 | public void CloseWindowWithWinParams()
59 | {
60 | App.Current?.CloseWindow(_winParamsWindow!);
61 | IsWinParamsWindowOpen = false;
62 | }
63 |
64 | [RelayCommand]
65 | public void CloseWindowWithVmParams()
66 | {
67 | App.Current?.CloseWindow(_vmParamsWindow!);
68 | IsVmParamsWindowOpen = false;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/DemoProject/Pages/ScopeCheckPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
19 |
20 |
27 |
28 |
34 |
40 |
41 |
48 |
49 |
51 |
52 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/Windows/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | $placeholder$
15 | User Name
16 | $placeholder$.png
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/DemoProject/Platforms/iOS/Resources/PrivacyInfo.xcprivacy:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 | NSPrivacyAccessedAPITypes
14 |
15 |
16 | NSPrivacyAccessedAPIType
17 | NSPrivacyAccessedAPICategoryFileTimestamp
18 | NSPrivacyAccessedAPITypeReasons
19 |
20 | C617.1
21 |
22 |
23 |
24 | NSPrivacyAccessedAPIType
25 | NSPrivacyAccessedAPICategorySystemBootTime
26 | NSPrivacyAccessedAPITypeReasons
27 |
28 | 35F9.1
29 |
30 |
31 |
32 | NSPrivacyAccessedAPIType
33 | NSPrivacyAccessedAPICategoryDiskSpace
34 | NSPrivacyAccessedAPITypeReasons
35 |
36 | E174.1
37 |
38 |
39 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/src/DemoProject/ViewModels/MainViewModel.cs:
--------------------------------------------------------------------------------
1 | using CommunityToolkit.Mvvm.ComponentModel;
2 | using CommunityToolkit.Mvvm.Input;
3 | using DemoProject.Pages;
4 | using DemoProject.Popups.Pages;
5 | using Mopups.Services;
6 | using System.Diagnostics;
7 |
8 | namespace DemoProject.ViewModels;
9 |
10 | [ObservableObject]
11 | public partial class MainViewModel(INameService nameService) : BaseViewModel
12 | {
13 | [ObservableProperty]
14 | private string _name = string.Empty;
15 |
16 | [RelayCommand]
17 | private void GetName()
18 | {
19 | Name = nameService.GetName();
20 | }
21 |
22 | [RelayCommand]
23 | private async Task GoToPageParamPage()
24 | {
25 | Name = nameService.GetName();
26 |
27 | await Navigation.PushAsync(Name);
28 | }
29 |
30 | [RelayCommand]
31 | private async Task GoToVmParamPage()
32 | {
33 | await Navigation.PushAsync("Name passed as parameter");
34 | }
35 |
36 | [RelayCommand]
37 | private async Task GoToMarkup()
38 | {
39 | await Navigation.PushAsync(new MarkupPage());
40 | }
41 |
42 | [RelayCommand]
43 | private async Task GoToScopeCheck()
44 | {
45 | await Navigation.PushAsync();
46 | }
47 |
48 | [RelayCommand]
49 | private async Task GoToBrokenPage()
50 | {
51 | await Navigation.PushAsync();
52 | }
53 |
54 | [RelayCommand]
55 | private Task ShowEasyPopup()
56 | {
57 | return MopupService.Instance.PushAsync();
58 | }
59 |
60 | [RelayCommand]
61 | private Task ShowParamPopup()
62 | {
63 | return MopupService.Instance.PushAsync("It's alive!");
64 | }
65 |
66 | [RelayCommand]
67 | private async Task TriggerAggregateException()
68 | {
69 | try
70 | {
71 | await Navigation.PushAsync("test");
72 | }
73 | catch(AggregateException ex)
74 | {
75 | Debug.WriteLine(ex);
76 | Debugger.Break();
77 | throw;
78 | }
79 | }
80 | }
--------------------------------------------------------------------------------
/src/DemoProject/Resources/Styles/Colors.xaml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 | #512BD4
10 | #ac99ea
11 | #242424
12 | #DFD8F7
13 | #9880e5
14 | #2B0B98
15 |
16 | White
17 | Black
18 | #D600AA
19 | #190649
20 | #1f1f1f
21 |
22 | #E1E1E1
23 | #C8C8C8
24 | #ACACAC
25 | #919191
26 | #6E6E6E
27 | #404040
28 | #212121
29 | #141414
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver/Resolver.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.DependencyInjection;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Reflection;
6 |
7 | namespace Maui.Plugins.PageResolver;
8 |
9 | internal static partial class Resolver
10 | {
11 | private static IServiceScope scope;
12 |
13 | internal static readonly Dictionary ViewModelLookup = new();
14 |
15 | internal static void InitialiseViewModelLookup(Assembly assembly)
16 | {
17 | var pages = assembly.DefinedTypes.Where(t => t.IsClass && t.Name.EndsWith("Page"));
18 |
19 | var viewModels = assembly.DefinedTypes.Where(t => t.IsClass && t.Name.EndsWith("ViewModel"));
20 |
21 | foreach (var page in pages)
22 | {
23 | var matches = viewModels.Where(vm =>
24 | vm.Name == $"{page.Name}ViewModel" || vm.Name == page.Name.Substring(0, page.Name.Length - 4) + "ViewModel").ToList();
25 |
26 | if (matches.Count == 1)
27 | ViewModelLookup.Add(page, matches[0]);
28 | }
29 | }
30 |
31 | internal static void InitialiseViewModelLookup(Dictionary ViewModelMappings)
32 | {
33 | ViewModelLookup.Clear();
34 |
35 | foreach (var mapping in ViewModelMappings)
36 | {
37 | ViewModelLookup.Add(mapping.Key, mapping.Value);
38 | }
39 | }
40 |
41 | internal static Type GetViewModelType(Type pageType)
42 | {
43 | if (ViewModelLookup.ContainsKey(pageType))
44 | return ViewModelLookup[pageType];
45 |
46 | return null;
47 | }
48 |
49 | ///
50 | /// Registers the service provider and creates a dependency scope
51 | ///
52 | ///
53 | internal static void RegisterServiceProvider(IServiceProvider sp)
54 | {
55 | scope ??= sp.CreateScope();
56 | }
57 |
58 | ///
59 | /// Returns a resolved instance of the requested type.
60 | ///
61 | ///
62 | ///
63 | internal static T Resolve() where T : class
64 | {
65 | var result = scope.ServiceProvider.GetRequiredService();
66 |
67 | return result;
68 | }
69 |
70 | internal static IServiceProvider GetServiceProvider()
71 | {
72 | return scope.ServiceProvider;
73 | }
74 |
75 | internal static void AddMappingRange(Dictionary mappings)
76 | {
77 | foreach (var mapping in mappings)
78 | {
79 | ViewModelLookup[mapping.Key] = mapping.Value;
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/DemoProject/Pages/DesktopRootPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
17 |
18 |
24 |
25 |
33 |
34 |
41 |
42 |
51 |
52 |
59 |
60 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.2.32210.308
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maui.Plugins.PageResolver", "Maui.Plugins.PageResolver\Maui.Plugins.PageResolver.csproj", "{34BC27F4-EAED-450D-956D-7943B8BD8148}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maui.Plugins.PageResolver.SourceGenerators", "Maui.Plugins.PageResolver.SourceGenerators\Maui.Plugins.PageResolver.SourceGenerators.csproj", "{22AFD22E-D7F4-4EB5-A6D4-09F0365D319E}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maui.Plugins.PageResolver.Attributes", "Maui.Plugins.PageResolver.Attributes\Maui.Plugins.PageResolver.Attributes.csproj", "{52D883B1-203F-429A-A117-344B4085FA14}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maui.Plugins.PageResolver.MopupsExtensions", "Maui.Plugins.PageResolver.MopupsExtensions\Maui.Plugins.PageResolver.MopupsExtensions.csproj", "{BFB3DF3F-C81E-4F52-8FEB-3FE529295F18}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoProject", "DemoProject\DemoProject.csproj", "{2ECC2822-727B-4B66-97E8-284D1B9D1DCB}"
15 | EndProject
16 | Global
17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
18 | Debug|Any CPU = Debug|Any CPU
19 | Release|Any CPU = Release|Any CPU
20 | EndGlobalSection
21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
22 | {34BC27F4-EAED-450D-956D-7943B8BD8148}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {34BC27F4-EAED-450D-956D-7943B8BD8148}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {34BC27F4-EAED-450D-956D-7943B8BD8148}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {34BC27F4-EAED-450D-956D-7943B8BD8148}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {79F5FD46-BB6F-4D66-B502-5E79B5CFB299}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {79F5FD46-BB6F-4D66-B502-5E79B5CFB299}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {79F5FD46-BB6F-4D66-B502-5E79B5CFB299}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
29 | {79F5FD46-BB6F-4D66-B502-5E79B5CFB299}.Release|Any CPU.ActiveCfg = Release|Any CPU
30 | {79F5FD46-BB6F-4D66-B502-5E79B5CFB299}.Release|Any CPU.Build.0 = Release|Any CPU
31 | {79F5FD46-BB6F-4D66-B502-5E79B5CFB299}.Release|Any CPU.Deploy.0 = Release|Any CPU
32 | {22AFD22E-D7F4-4EB5-A6D4-09F0365D319E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {22AFD22E-D7F4-4EB5-A6D4-09F0365D319E}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {22AFD22E-D7F4-4EB5-A6D4-09F0365D319E}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {22AFD22E-D7F4-4EB5-A6D4-09F0365D319E}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {52D883B1-203F-429A-A117-344B4085FA14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {52D883B1-203F-429A-A117-344B4085FA14}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {52D883B1-203F-429A-A117-344B4085FA14}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {52D883B1-203F-429A-A117-344B4085FA14}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {BFB3DF3F-C81E-4F52-8FEB-3FE529295F18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {BFB3DF3F-C81E-4F52-8FEB-3FE529295F18}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {BFB3DF3F-C81E-4F52-8FEB-3FE529295F18}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {BFB3DF3F-C81E-4F52-8FEB-3FE529295F18}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {2ECC2822-727B-4B66-97E8-284D1B9D1DCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {2ECC2822-727B-4B66-97E8-284D1B9D1DCB}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {2ECC2822-727B-4B66-97E8-284D1B9D1DCB}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {2ECC2822-727B-4B66-97E8-284D1B9D1DCB}.Release|Any CPU.Build.0 = Release|Any CPU
48 | EndGlobalSection
49 | GlobalSection(SolutionProperties) = preSolution
50 | HideSolutionNode = FALSE
51 | EndGlobalSection
52 | GlobalSection(ExtensibilityGlobals) = postSolution
53 | SolutionGuid = {F015D993-F9B0-4588-A027-3F2B0FB8B2D5}
54 | EndGlobalSection
55 | EndGlobal
56 |
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver/StartupExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.DependencyInjection;
2 | using Microsoft.Extensions.DependencyInjection.Extensions;
3 | using Microsoft.Maui.Hosting;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Reflection;
7 |
8 | namespace Maui.Plugins.PageResolver;
9 |
10 | public static class StartupExtensions
11 | {
12 | ///
13 | /// Registers the services in the service collection with the page resolver
14 | ///
15 | ///
16 | /// If true, the ViewModelResolver will be initialised with the calling assembly (required for passing ViewModel parameters in navigation). Disabled by default as it uses reflection and will have startup time impact.
17 | public static void UsePageResolver(this IServiceCollection services, bool? UseParamaterisedViewModels = false)
18 | {
19 | services.TryAddEnumerable( ServiceDescriptor.Transient() );
20 |
21 | if (UseParamaterisedViewModels ?? false)
22 | {
23 | Resolver.InitialiseViewModelLookup(Assembly.GetCallingAssembly());
24 | }
25 | }
26 |
27 | ///
28 | /// Registers the services in the service collection with the page resolver
29 | ///
30 | ///
31 | /// If true, the ViewModelResolver will be initialised with the calling assembly (required for passing ViewModel parameters in navigation). Disabled by default as it uses reflection and will have startup time impact.
32 | public static MauiAppBuilder UsePageResolver(this MauiAppBuilder builder, bool? UseParamaterisedViewModels = false)
33 | {
34 | builder.Services.TryAddEnumerable(
35 | ServiceDescriptor.Transient() );
36 |
37 | if (UseParamaterisedViewModels??false)
38 | {
39 | Resolver.InitialiseViewModelLookup(Assembly.GetCallingAssembly());
40 | }
41 |
42 | return builder;
43 | }
44 |
45 | ///
46 | /// Registers the services in the service collection and the page-to-ViewModel mappings with the page resolver. This overload is intended for use with the Source Generator.
47 | ///
48 | ///
49 | /// A dictionary that provides Page to ViewModel mappings..
50 | public static void UsePageResolver(this IServiceCollection services, Dictionary ViewModelMappings)
51 | {
52 | services.TryAddEnumerable(ServiceDescriptor.Transient());
53 |
54 | Resolver.InitialiseViewModelLookup(ViewModelMappings);
55 | }
56 |
57 | ///
58 | /// Clears the current page to ViewModel mappings and replaces with the specified mappings
59 | ///
60 | ///
61 | ///
62 | ///
63 | public static IServiceCollection AddViewModelMappings(this IServiceCollection services, Dictionary ViewModelMappings)
64 | {
65 | Resolver.InitialiseViewModelLookup(ViewModelMappings);
66 | return services;
67 | }
68 |
69 | ///
70 | /// Adds the specified page to ViewModel mappings to the existing mappings (replaces items with existing key)
71 | ///
72 | ///
73 | public static void AddViewModelMappings(Dictionary ViewModelMappings)
74 | {
75 | Resolver.AddMappingRange(ViewModelMappings);
76 | }
77 |
78 | ///
79 | /// Adds a single page to ViewModel mapping to the existing mappings (replaces item with existing key)
80 | ///
81 | ///
82 | ///
83 | public static void UpsertViewModelMapping()
84 | {
85 | Resolver.ViewModelLookup[typeof(T1)] = typeof(T2);
86 | }
87 |
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/DemoProject/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
12 |
13 |
17 |
18 |
23 |
24 |
29 |
30 |
35 |
36 |
41 |
42 |
47 |
48 |
53 |
54 |
59 |
60 |
65 |
66 |
71 |
72 |
78 |
79 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/src/DemoProject/DemoProject.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net9.0-android;net9.0-ios;net9.0-maccatalyst
5 | $(TargetFrameworks);net9.0-windows10.0.19041.0
6 |
7 |
8 |
9 |
14 |
15 |
16 | Exe
17 | DemoProject
18 | true
19 | true
20 | enable
21 | enable
22 |
23 |
24 | DemoProject
25 |
26 |
27 | com.companyname.demoproject
28 |
29 |
30 | 1.0
31 | 1
32 |
33 |
34 | None
35 |
36 | 15.0
37 | 15.0
38 | 21.0
39 | 10.0.17763.0
40 | 10.0.17763.0
41 | 6.5
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
79 |
80 |
81 |
82 | MSBuild:Compile
83 |
84 |
85 | MSBuild:Compile
86 |
87 |
88 | MSBuild:Compile
89 |
90 |
91 | MSBuild:Compile
92 |
93 |
94 | MSBuild:Compile
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Aa][Rr][Mm]/
27 | [Aa][Rr][Mm]64/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 | [Ll]ogs/
33 |
34 | # Visual Studio 2015/2017 cache/options directory
35 | .vs/
36 | # Uncomment if you have tasks that create the project's static files in wwwroot
37 | #wwwroot/
38 |
39 | # Visual Studio 2017 auto generated files
40 | Generated\ Files/
41 |
42 | # MSTest test Results
43 | [Tt]est[Rr]esult*/
44 | [Bb]uild[Ll]og.*
45 |
46 | # NUnit
47 | *.VisualState.xml
48 | TestResult.xml
49 | nunit-*.xml
50 |
51 | # Build Results of an ATL Project
52 | [Dd]ebugPS/
53 | [Rr]eleasePS/
54 | dlldata.c
55 |
56 | # Benchmark Results
57 | BenchmarkDotNet.Artifacts/
58 |
59 | # .NET Core
60 | project.lock.json
61 | project.fragment.lock.json
62 | artifacts/
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_h.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *_wpftmp.csproj
88 | *.log
89 | *.vspscc
90 | *.vssscc
91 | .builds
92 | *.pidb
93 | *.svclog
94 | *.scc
95 |
96 | # Chutzpah Test files
97 | _Chutzpah*
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opendb
104 | *.opensdf
105 | *.sdf
106 | *.cachefile
107 | *.VC.db
108 | *.VC.VC.opendb
109 |
110 | # Visual Studio profiler
111 | *.psess
112 | *.vsp
113 | *.vspx
114 | *.sap
115 |
116 | # Visual Studio Trace Files
117 | *.e2e
118 |
119 | # TFS 2012 Local Workspace
120 | $tf/
121 |
122 | # Guidance Automation Toolkit
123 | *.gpState
124 |
125 | # ReSharper is a .NET coding add-in
126 | _ReSharper*/
127 | *.[Rr]e[Ss]harper
128 | *.DotSettings.user
129 |
130 | # TeamCity is a build add-in
131 | _TeamCity*
132 |
133 | # DotCover is a Code Coverage Tool
134 | *.dotCover
135 |
136 | # AxoCover is a Code Coverage Tool
137 | .axoCover/*
138 | !.axoCover/settings.json
139 |
140 | # Visual Studio code coverage results
141 | *.coverage
142 | *.coveragexml
143 |
144 | # NCrunch
145 | _NCrunch_*
146 | .*crunch*.local.xml
147 | nCrunchTemp_*
148 |
149 | # MightyMoose
150 | *.mm.*
151 | AutoTest.Net/
152 |
153 | # Web workbench (sass)
154 | .sass-cache/
155 |
156 | # Installshield output folder
157 | [Ee]xpress/
158 |
159 | # DocProject is a documentation generator add-in
160 | DocProject/buildhelp/
161 | DocProject/Help/*.HxT
162 | DocProject/Help/*.HxC
163 | DocProject/Help/*.hhc
164 | DocProject/Help/*.hhk
165 | DocProject/Help/*.hhp
166 | DocProject/Help/Html2
167 | DocProject/Help/html
168 |
169 | # Click-Once directory
170 | publish/
171 |
172 | # Publish Web Output
173 | *.[Pp]ublish.xml
174 | *.azurePubxml
175 | # Note: Comment the next line if you want to checkin your web deploy settings,
176 | # but database connection strings (with potential passwords) will be unencrypted
177 | *.pubxml
178 | *.publishproj
179 |
180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
181 | # checkin your Azure Web App publish settings, but sensitive information contained
182 | # in these scripts will be unencrypted
183 | PublishScripts/
184 |
185 | # NuGet Packages
186 | *.nupkg
187 | # NuGet Symbol Packages
188 | *.snupkg
189 | # The packages folder can be ignored because of Package Restore
190 | **/[Pp]ackages/*
191 | # except build/, which is used as an MSBuild target.
192 | !**/[Pp]ackages/build/
193 | # Uncomment if necessary however generally it will be regenerated when needed
194 | #!**/[Pp]ackages/repositories.config
195 | # NuGet v3's project.json files produces more ignorable files
196 | *.nuget.props
197 | *.nuget.targets
198 |
199 | # Microsoft Azure Build Output
200 | csx/
201 | *.build.csdef
202 |
203 | # Microsoft Azure Emulator
204 | ecf/
205 | rcf/
206 |
207 | # Windows Store app package directories and files
208 | AppPackages/
209 | BundleArtifacts/
210 | Package.StoreAssociation.xml
211 | _pkginfo.txt
212 | *.appx
213 | *.appxbundle
214 | *.appxupload
215 |
216 | # Visual Studio cache files
217 | # files ending in .cache can be ignored
218 | *.[Cc]ache
219 | # but keep track of directories ending in .cache
220 | !?*.[Cc]ache/
221 |
222 | # Others
223 | ClientBin/
224 | ~$*
225 | *~
226 | *.dbmdl
227 | *.dbproj.schemaview
228 | *.jfm
229 | *.pfx
230 | *.publishsettings
231 | orleans.codegen.cs
232 |
233 | # Including strong name files can present a security risk
234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
235 | #*.snk
236 |
237 | # Since there are multiple workflows, uncomment next line to ignore bower_components
238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
239 | #bower_components/
240 |
241 | # RIA/Silverlight projects
242 | Generated_Code/
243 |
244 | # Backup & report files from converting an old project file
245 | # to a newer Visual Studio version. Backup files are not needed,
246 | # because we have git ;-)
247 | _UpgradeReport_Files/
248 | Backup*/
249 | UpgradeLog*.XML
250 | UpgradeLog*.htm
251 | ServiceFabricBackup/
252 | *.rptproj.bak
253 |
254 | # SQL Server files
255 | *.mdf
256 | *.ldf
257 | *.ndf
258 |
259 | # Business Intelligence projects
260 | *.rdl.data
261 | *.bim.layout
262 | *.bim_*.settings
263 | *.rptproj.rsuser
264 | *- [Bb]ackup.rdl
265 | *- [Bb]ackup ([0-9]).rdl
266 | *- [Bb]ackup ([0-9][0-9]).rdl
267 |
268 | # Microsoft Fakes
269 | FakesAssemblies/
270 |
271 | # GhostDoc plugin setting file
272 | *.GhostDoc.xml
273 |
274 | # Node.js Tools for Visual Studio
275 | .ntvs_analysis.dat
276 | node_modules/
277 |
278 | # Visual Studio 6 build log
279 | *.plg
280 |
281 | # Visual Studio 6 workspace options file
282 | *.opt
283 |
284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
285 | *.vbw
286 |
287 | # Visual Studio LightSwitch build output
288 | **/*.HTMLClient/GeneratedArtifacts
289 | **/*.DesktopClient/GeneratedArtifacts
290 | **/*.DesktopClient/ModelManifest.xml
291 | **/*.Server/GeneratedArtifacts
292 | **/*.Server/ModelManifest.xml
293 | _Pvt_Extensions
294 |
295 | # Paket dependency manager
296 | .paket/paket.exe
297 | paket-files/
298 |
299 | # FAKE - F# Make
300 | .fake/
301 |
302 | # CodeRush personal settings
303 | .cr/personal
304 |
305 | # Python Tools for Visual Studio (PTVS)
306 | __pycache__/
307 | *.pyc
308 |
309 | # Cake - Uncomment if you are using it
310 | # tools/**
311 | # !tools/packages.config
312 |
313 | # Tabs Studio
314 | *.tss
315 |
316 | # Telerik's JustMock configuration file
317 | *.jmconfig
318 |
319 | # BizTalk build output
320 | *.btp.cs
321 | *.btm.cs
322 | *.odx.cs
323 | *.xsd.cs
324 |
325 | # OpenCover UI analysis results
326 | OpenCover/
327 |
328 | # Azure Stream Analytics local run output
329 | ASALocalRun/
330 |
331 | # MSBuild Binary and Structured Log
332 | *.binlog
333 |
334 | # NVidia Nsight GPU debugger configuration file
335 | *.nvuser
336 |
337 | # MFractors (Xamarin productivity tool) working folder
338 | .mfractor/
339 |
340 | # Local History for Visual Studio
341 | .localhistory/
342 |
343 | # BeatPulse healthcheck temp database
344 | healthchecksdb
345 |
346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
347 | MigrationBackup/
348 |
349 | # Ionide (cross platform F# VS Code tools) working folder
350 | .ionide/
351 | .meteor/
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver/NavigationExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.DependencyInjection;
2 | using Microsoft.Maui.Controls;
3 | using System;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace Maui.Plugins.PageResolver;
8 |
9 | public static class NavigationExtensions
10 | {
11 | #region paramaterless navigation
12 |
13 | ///
14 | /// Resolves a page of type T (must inherit from Page) and pushes a new instance onto the navigation stack
15 | ///
16 | ///
17 | ///
18 | ///
19 | public static async Task PushAsync(this INavigation navigation) where T : Page
20 | {
21 | var resolvedPage = Resolver.Resolve();
22 |
23 | await navigation.PushAsync(resolvedPage);
24 | }
25 |
26 | ///
27 | /// Resolves a page of type T (must inherit from Page) and pushes a new modal instance onto the navigation stack
28 | ///
29 | ///
30 | ///
31 | ///
32 | public static async Task PushModalAsync(this INavigation navigation) where T : Page
33 | {
34 | var resolvedPage = Resolver.Resolve();
35 |
36 | await navigation.PushModalAsync(resolvedPage);
37 | }
38 |
39 | ///
40 | /// Resolves a page of type T (must inherit from Page) and inserts it onto the navigation stack before a specific page
41 | ///
42 | ///
43 | ///
44 | ///
45 | public static void InsertPageBefore(this INavigation navigation, Page before) where T : Page
46 | {
47 | var resolvedPage = Resolver.Resolve();
48 | navigation.InsertPageBefore(resolvedPage, before);
49 | }
50 |
51 | ///
52 | /// Creates a new window with a resolved page of type T (must inherit from Page)
53 | ///
54 | ///
55 | public static Window CreateWindow() where T : Page
56 | {
57 | var resolvedPage = Resolver.Resolve();
58 | return new Window(resolvedPage);
59 | }
60 |
61 | ///
62 | /// Creates a new window with a resolved page of type T (must inherit from Page) and opens it, and returns the window
63 | ///
64 | ///
65 | public static Window OpenWindow(this Application application) where T : Page
66 | {
67 | var window = CreateWindow();
68 | application.OpenWindow(window);
69 | return window;
70 | }
71 |
72 | #endregion paramaterless navigation
73 |
74 | #region parameterized navigation
75 |
76 | ///
77 | /// Resolves a page of type T (must inherit from Page) and pushes a new instance onto the navigation stack
78 | ///
79 | /// The type of the page to be resolved
80 | ///
81 | /// The constructor parameters expected by the page to be resolved
82 | ///
83 | public static async Task PushAsync(this INavigation navigation, params object[] parameters) where T : Page
84 | {
85 | var page = ResolvePage(parameters);
86 | await navigation.PushAsync(page);
87 | }
88 |
89 | ///
90 | /// Resolves a page of type T (must inherit from Page) and pushes a new modal instance onto the navigation stack
91 | ///
92 | /// The type of the page to be resolved
93 | ///
94 | /// The constructor parameters expected by the page to be resolved
95 | ///
96 | public static async Task PushModalAsync(this INavigation navigation, params object[] parameters) where T : Page
97 | {
98 | var page = ResolvePage(parameters);
99 | await navigation.PushModalAsync(page);
100 | }
101 |
102 | ///
103 | /// Resolves a page of type T (must inherit from Page) and inserts it onto the navigation stack before a specific page
104 | ///
105 | ///
106 | ///
107 | ///
108 | /// The constructor parameters expected by the page to be resolved
109 | public static void InsertPageBefore(this INavigation navigation, Page before, params object[] parameters) where T : Page
110 | {
111 | var page = ResolvePage(parameters);
112 | navigation.InsertPageBefore(page, before);
113 | }
114 |
115 | ///
116 | /// Creates a new window with a resolved page of type T (must inherit from Page)
117 | ///
118 | ///
119 | /// The constructor parameters expected by the page to be resolved
120 | public static Window CreateWindow(params object[] parameters) where T : Page
121 | {
122 | var page = ResolvePage(parameters);
123 | return new Window(page);
124 | }
125 |
126 | ///
127 | /// Creates a new window with a resolved page of type T (must inherit from Page) and opens it, and returns the window
128 | ///
129 | ///
130 | /// The constructor parameters expected by the page to be resolved
131 | public static Window OpenWindow(this Application application, params object[] parameters) where T : Page
132 | {
133 | var window = CreateWindow(parameters);
134 | application.OpenWindow(window);
135 | return window;
136 | }
137 |
138 | #endregion parameterized navigation
139 |
140 | internal static Page ResolvePage(params object[] parameters) where T : Page
141 | {
142 | var serviceProvider = Resolver.GetServiceProvider();
143 |
144 | var pageType = typeof(T);
145 | var viewModelType = Resolver.GetViewModelType(pageType);
146 |
147 | if (viewModelType is not null && parameters.Any(x => x.GetType().Equals(viewModelType)))
148 | {
149 | viewModelType = null;
150 | }
151 |
152 | if (viewModelType == null)
153 | {
154 | return CreatePageWithoutViewModel(serviceProvider, parameters);
155 | }
156 |
157 | return CreatePageWithViewModel(serviceProvider, viewModelType, parameters);
158 | }
159 |
160 | private static Page CreatePageWithoutViewModel(IServiceProvider serviceProvider, params object[] parameters) where T : Page
161 | {
162 | return ActivatorUtilities.CreateInstance(serviceProvider, parameters);
163 | }
164 |
165 | private static Page CreatePageWithViewModel(IServiceProvider serviceProvider, Type viewModelType, params object[] parameters) where T : Page
166 | {
167 | // Check if parameters fit the ViewModel's constructors
168 | if (ParametersMatchConstructors(viewModelType, parameters))
169 | {
170 | var viewModel = ActivatorUtilities.CreateInstance(serviceProvider, viewModelType, parameters);
171 | return CreatePageUsingViewModel(serviceProvider, viewModel);
172 | }
173 | // Check if parameters fit the Page's constructors, excluding the ViewModel type
174 | else if (ParametersMatchConstructorsExcludingType(typeof(T), viewModelType, parameters))
175 | {
176 | return ActivatorUtilities.CreateInstance(serviceProvider, parameters);
177 | }
178 | else
179 | {
180 | throw new ArgumentException("Provided parameters do not match the constructors of the Page or ViewModel.");
181 | }
182 | }
183 |
184 | private static bool ParametersMatchConstructors(Type type, params object[] parameters)
185 | {
186 | var sp = Resolver.GetServiceProvider();
187 |
188 | var constructors = type.GetConstructors();
189 | foreach (var constructor in constructors)
190 | {
191 | var ctorParams = constructor.GetParameters();
192 |
193 | var nonInjectableParams = ctorParams.Where(p => !IsRegisteredDependency(sp, p.ParameterType)).ToArray();
194 |
195 | if (nonInjectableParams.Length == parameters.Length)
196 | {
197 | for (int i = 0; i < nonInjectableParams.Length; i++)
198 | {
199 | if (!nonInjectableParams[i].ParameterType.IsAssignableFrom(parameters[i].GetType()))
200 | break;
201 | if (i == nonInjectableParams.Length - 1)
202 | return true; // all parameters match
203 | }
204 | }
205 | }
206 | return false;
207 | }
208 |
209 | private static bool ParametersMatchConstructorsExcludingType(Type type, Type excludeType, params object[] parameters)
210 | {
211 | var sp = Resolver.GetServiceProvider();
212 |
213 | var constructors = type.GetConstructors();
214 | foreach (var constructor in constructors)
215 | {
216 | var ctorParams = constructor.GetParameters().Where(p => p.ParameterType != excludeType).ToArray();
217 |
218 | var nonInjectableParams = ctorParams.Where(p => !IsRegisteredDependency(sp, p.ParameterType)).ToArray();
219 |
220 | if (nonInjectableParams.Length == parameters.Length)
221 | {
222 | for (int i = 0; i < nonInjectableParams.Length; i++)
223 | {
224 | if (!nonInjectableParams[i].ParameterType.IsAssignableFrom(parameters[i].GetType()))
225 | break;
226 | if (i == nonInjectableParams.Length - 1)
227 | return true; // all parameters match
228 | }
229 | }
230 | }
231 | return false;
232 | }
233 |
234 | private static Page CreatePageUsingViewModel(IServiceProvider serviceProvider, object viewModel) where T : Page
235 | {
236 | try
237 | {
238 | return ActivatorUtilities.CreateInstance(serviceProvider, viewModel);
239 | }
240 | catch (MissingMemberException ex)
241 | {
242 | try
243 | {
244 | return ActivatorUtilities.CreateInstance(Resolver.GetServiceProvider());
245 | }
246 | catch (Exception ex1)
247 | {
248 | throw new AggregateException("Failed to create page with ViewModel", ex, ex1);
249 | }
250 | }
251 | }
252 |
253 | private static bool IsRegisteredDependency(IServiceProvider serviceProvider, Type type)
254 | {
255 | if (type.IsPrimitive || type == typeof(string) || type.IsValueType)
256 | {
257 | return false;
258 | }
259 |
260 | try
261 | {
262 | var services = serviceProvider.GetServices(type);
263 | return services.Any();
264 | }
265 | catch (Exception)
266 | {
267 | return false;
268 | }
269 | }
270 | }
--------------------------------------------------------------------------------
/src/Maui.Plugins.PageResolver.SourceGenerators/AutoDependencies.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace Maui.Plugins.PageResolver.SourceGenerators
8 | {
9 | [Generator]
10 | public class AutoDependencies : ISourceGenerator
11 | {
12 | private Dictionary> _dependencies;
13 |
14 | public void Execute(GeneratorExecutionContext context)
15 | {
16 | StringBuilder lb = new StringBuilder();
17 |
18 | Log.Init(lb);
19 |
20 | try
21 | {
22 | // TODO: get all referenced assemblies
23 | var assembly = context.Compilation.Assembly;
24 |
25 | Log.WriteLine($"Scanning assembly: {assembly.Name}");
26 |
27 | var types = GetAllTypes(context.Compilation.SourceModule.ContainingAssembly.GlobalNamespace);
28 |
29 | InitialiseDependencies(types);
30 |
31 | Log.WriteLine("Getting MauiProgram...");
32 |
33 | var mauiProgramName = $"{assembly.Name}.MauiProgram";
34 |
35 | Log.WriteLine($"Global namespace: {context.Compilation.Assembly.GlobalNamespace.Name}");
36 |
37 | var mauiProgram = context.Compilation
38 | .GetTypeByMetadataName(mauiProgramName);
39 |
40 | if (mauiProgram is null)
41 | {
42 | Log.WriteLine("MauiProgram not found");
43 | throw new Exception("MauiProgram not found.");
44 | }
45 |
46 | bool hasNoAutoDependenciesAttribute = mauiProgram.GetAttributes()
47 | .Any(ad => ad.AttributeClass.ToDisplayString() == "Maui.Plugins.PageResolver.Attributes.NoAutoDependenciesAttribute");
48 |
49 | if (hasNoAutoDependenciesAttribute)
50 | {
51 | Log.WriteLine("NoAutoDependenciesAttribute found, skipping.");
52 | return;
53 | }
54 |
55 | Log.WriteLine($"Found main method: {mauiProgram.Name}");
56 |
57 | StringBuilder sourceBuilder = new StringBuilder();
58 |
59 | sourceBuilder.Append($@"using Maui.Plugins.PageResolver;
60 |
61 | // ---------------
62 | //
63 | // Generated by the MauiPageResolver Auto-registration module.
64 | // https://github.com/matt-goldman/Maui.Plugins.PageResolver
65 | //
66 | // ---------------
67 |
68 | namespace {mauiProgram.ContainingNamespace.ToDisplayString()};
69 |
70 | public static class PageResolverExtensions
71 | {{
72 |
73 | public static MauiAppBuilder UseAutodependencies(this MauiAppBuilder builder)
74 | {{
75 | var ViewModelMappings = new Dictionary();
76 |
77 | // pages
78 | ");
79 |
80 | // add page registrations
81 | foreach (var page in _dependencies["Pages"])
82 | {
83 | string lifetime = _dependencies["ExplicitSingletons"].Contains(page) ? "Singleton" : "Transient";
84 |
85 | sourceBuilder.AppendLine($" builder.Services.Add{lifetime}();");
86 | }
87 |
88 | sourceBuilder.Append(@"
89 |
90 | // ViewModels
91 | ");
92 |
93 | // add ViewModel registrations
94 | foreach (var vm in _dependencies["ViewModels"])
95 | {
96 | string lifetime = _dependencies["ExplicitSingletons"].Contains(vm) ? "Singleton" : "Transient";
97 |
98 | sourceBuilder.AppendLine($" builder.Services.Add{lifetime}();");
99 | }
100 |
101 | sourceBuilder.Append(@"
102 |
103 | // Services
104 | ");
105 |
106 | // add Service registrations
107 | foreach (var service in _dependencies["Services"])
108 | {
109 | string lifetime = _dependencies["ExplicitTransients"].Contains(service) ? "Transient" : "Singleton";
110 |
111 | var abstraction = _dependencies["Abstractions"].Where(a => a.Name == $"I{service.Name}").FirstOrDefault();
112 |
113 | if (abstraction is null)
114 | {
115 | sourceBuilder.AppendLine($" builder.Services.Add{lifetime}();");
116 | }
117 | else
118 | {
119 | string serviceInterface = service.ToDisplayString();
120 | serviceInterface = serviceInterface.Replace(service.Name, $"I{service.Name}");
121 |
122 | sourceBuilder.AppendLine($" builder.Services.Add{lifetime}();");
123 | }
124 | }
125 |
126 | sourceBuilder.Append(@"
127 |
128 | // ViewModel to Page mappings
129 | ");
130 |
131 | var mappings = GetPageToViewModelMappings();
132 |
133 | foreach (var mapping in mappings)
134 | {
135 | sourceBuilder.AppendLine($" ViewModelMappings.Add(typeof(global::{mapping.Key.ToDisplayString()}), typeof(global::{mapping.Value.ToDisplayString()}));");
136 | }
137 |
138 | sourceBuilder.Append(@"
139 |
140 | // Initialisation
141 | ");
142 |
143 | sourceBuilder.AppendLine($" builder.Services.UsePageResolver(ViewModelMappings);");
144 |
145 | sourceBuilder.AppendLine($" return builder;");
146 |
147 | // close the partial method and class
148 | sourceBuilder.Append(@" }
149 | }");
150 |
151 | // generate the source file
152 | var typeName = mauiProgram.Name;
153 |
154 | context.AddSource("PageResolverExtensions.g.cs", sourceBuilder.ToString());
155 | Log.WriteLine($"Generated: PageResolverExtensions.g.cs, {sourceBuilder}");
156 | }
157 | catch (Exception ex)
158 | {
159 | Log.WriteLine("[AutoDependencies Source Generator] Exception thrown: ");
160 | Log.WriteLine($"{ex}");
161 | Log.WriteLine($"{ex.StackTrace}");
162 | }
163 | finally
164 | {
165 | Log.WriteLine("[AutoDependencies Source Generator] Finished.]");
166 | Log.FlushLog();
167 | }
168 | }
169 |
170 | public void Initialize(GeneratorInitializationContext context)
171 | {
172 | // no initialisation
173 | }
174 |
175 | private void InitialiseDependencies(IEnumerable types)
176 | {
177 | var comparer = SymbolEqualityComparer.Default;
178 |
179 | _dependencies = new Dictionary>
180 | {
181 | { "Pages", new HashSet(comparer) },
182 | { "ViewModels", new HashSet (comparer) },
183 | { "Services", new HashSet(comparer) },
184 | { "Abstractions", new HashSet(comparer) },
185 | { "ExplicitSingletons", new HashSet(comparer) },
186 | { "ExplicitTransients", new HashSet(comparer) }
187 | };
188 |
189 | var ignoredTypes = new HashSet(types.Where(type =>
190 | type.GetAttributes().Any(ad =>
191 | ad.AttributeClass.ToDisplayString() == "Maui.Plugins.PageResolver.Attributes.IgnoreAttribute")
192 | || type.IsAbstract), comparer);
193 |
194 | var singletons = types.Where(type =>
195 | type.GetAttributes().Any(ad =>
196 | ad.AttributeClass.ToDisplayString() == "Maui.Plugins.PageResolver.Attributes.SingletonAttribute"));
197 | _dependencies["ExplicitSingletons"] = new HashSet(singletons, comparer);
198 |
199 | var transients = types.Where(type =>
200 | type.GetAttributes().Any(ad =>
201 | ad.AttributeClass.ToDisplayString() == "Maui.Plugins.PageResolver.Attributes.TransientAttribute"));
202 | _dependencies["ExplicitTransients"] = new HashSet(transients, comparer);
203 |
204 | var pages = types.Where(t => t.TypeKind == TypeKind.Class && t.Name.EndsWith("Page") && !ignoredTypes.Contains(t, comparer));
205 | _dependencies["Pages"] = new HashSet(pages, comparer);
206 |
207 | var viewModels = types.Where(t => t.TypeKind == TypeKind.Class && t.Name.EndsWith("ViewModel") && !ignoredTypes.Contains(t, comparer));
208 | _dependencies["ViewModels"] = new HashSet(viewModels, comparer);
209 |
210 | var services = types.Where(t => t.TypeKind == TypeKind.Class && t.Name.EndsWith("Service") && !ignoredTypes.Contains(t, comparer));
211 | _dependencies["Services"] = new HashSet(services, comparer);
212 |
213 | var abstractions = types.Where(t => t.TypeKind == TypeKind.Interface && t.Name.EndsWith("Service"));
214 | _dependencies["Abstractions"] = new HashSet(abstractions, comparer);
215 |
216 | Log.WriteLine($"Found {pages.Count()} pages.");
217 | Log.WriteLine($"Found {viewModels.Count()} ViewModels.");
218 | Log.WriteLine($"Found {services.Count()} Services.");
219 | Log.WriteLine($"Found {abstractions.Count()} interfaces.");
220 | }
221 |
222 | private Dictionary GetPageToViewModelMappings()
223 | {
224 | var VMLookup = new Dictionary(SymbolEqualityComparer.Default);
225 |
226 | foreach (var page in _dependencies["Pages"])
227 | {
228 | var matches = _dependencies["ViewModels"].Where(vm =>
229 | vm.Name == $"{page.Name}ViewModel" || vm.Name == page.Name.Substring(0, page.Name.Length - 4) + "ViewModel").ToList();
230 |
231 | if (matches.Count == 1)
232 | {
233 | var pageType = page.Name;
234 | var vmType = matches[0].Name;
235 |
236 | Log.WriteLine($"[AutoDependencies Source Generator] adding mapping for {pageType} to {vmType}");
237 |
238 | VMLookup.Add(page, matches[0]);
239 | }
240 | }
241 |
242 | return VMLookup;
243 | }
244 |
245 | private static IEnumerable GetAllTypes(INamespaceSymbol root)
246 | {
247 | foreach (var namespaceOrTypeSymbol in root.GetMembers())
248 | {
249 | if (namespaceOrTypeSymbol is INamespaceSymbol @namespace)
250 | foreach (var nested in GetAllTypes(@namespace))
251 | yield return nested;
252 |
253 | else if (namespaceOrTypeSymbol is ITypeSymbol type)
254 | yield return type;
255 | }
256 | }
257 | }
258 | }
259 |
--------------------------------------------------------------------------------
/src/DemoProject/Resources/Styles/Styles.xaml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
10 |
11 |
15 |
16 |
21 |
22 |
25 |
26 |
51 |
52 |
69 |
70 |
90 |
91 |
112 |
113 |
134 |
135 |
141 |
142 |
163 |
164 |
182 |
183 |
186 |
187 |
193 |
194 |
200 |
201 |
205 |
206 |
228 |
229 |
244 |
245 |
265 |
266 |
269 |
270 |
293 |
294 |
314 |
315 |
321 |
322 |
341 |
342 |
345 |
346 |
374 |
375 |
395 |
396 |
419 |
420 |
424 |
425 |
437 |
438 |
443 |
444 |
450 |
451 |
452 |
--------------------------------------------------------------------------------