From 9e5772d3b185de4e4270c65a1a9e6a200287c1f1 Mon Sep 17 00:00:00 2001 From: Oleksandr Liakhevych Date: Wed, 23 Nov 2022 23:45:54 +0200 Subject: [PATCH 1/2] Add BlazorBindingsApplication --- samples/BlazorBindingsToDo/App.cs | 15 --------------- samples/BlazorBindingsToDo/MauiProgram.cs | 2 +- samples/BlazorBindingsXaminals/App.cs | 15 --------------- samples/BlazorBindingsXaminals/MauiProgram.cs | 2 +- samples/ControlGallery/App.cs | 15 --------------- samples/ControlGallery/MauiProgram.cs | 2 +- samples/FluxorSample/App.cs | 12 ------------ samples/FluxorSample/MauiProgram.cs | 2 +- samples/FlyoutPageSample/App.cs | 13 ------------- samples/FlyoutPageSample/MauiProgram.cs | 3 ++- samples/ThirdPartyControlsSample/App.cs | 16 ---------------- samples/ThirdPartyControlsSample/MauiProgram.cs | 2 +- src/BlazorBindings.Maui/BlazorBindingsApp.cs | 16 ++++++++++++++++ .../Navigation/Navigation.Shell.cs | 6 +++++- 14 files changed, 28 insertions(+), 93 deletions(-) delete mode 100644 samples/BlazorBindingsToDo/App.cs delete mode 100644 samples/BlazorBindingsXaminals/App.cs delete mode 100644 samples/ControlGallery/App.cs delete mode 100644 samples/FluxorSample/App.cs delete mode 100644 samples/FlyoutPageSample/App.cs delete mode 100644 samples/ThirdPartyControlsSample/App.cs create mode 100644 src/BlazorBindings.Maui/BlazorBindingsApp.cs diff --git a/samples/BlazorBindingsToDo/App.cs b/samples/BlazorBindingsToDo/App.cs deleted file mode 100644 index c7c2494e..00000000 --- a/samples/BlazorBindingsToDo/App.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -using BlazorBindings.Maui; - -namespace BlazorBindingsToDo -{ - public partial class App : Application - { - public App(MauiBlazorBindingsRenderer renderer) - { - _ = renderer.AddComponent(this); - } - } -} \ No newline at end of file diff --git a/samples/BlazorBindingsToDo/MauiProgram.cs b/samples/BlazorBindingsToDo/MauiProgram.cs index e505a9fc..7f05ca46 100644 --- a/samples/BlazorBindingsToDo/MauiProgram.cs +++ b/samples/BlazorBindingsToDo/MauiProgram.cs @@ -11,7 +11,7 @@ public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder - .UseMauiApp() + .UseMauiApp>() .UseMauiBlazorBindings(); builder.Services.AddSingleton(); diff --git a/samples/BlazorBindingsXaminals/App.cs b/samples/BlazorBindingsXaminals/App.cs deleted file mode 100644 index 3e2d0ece..00000000 --- a/samples/BlazorBindingsXaminals/App.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -using BlazorBindings.Maui; - -namespace BlazorBindingsXaminals -{ - public class App : Application - { - public App(MauiBlazorBindingsRenderer renderer) - { - renderer.AddComponent(this); - } - } -} diff --git a/samples/BlazorBindingsXaminals/MauiProgram.cs b/samples/BlazorBindingsXaminals/MauiProgram.cs index cd48dc4f..28c2d8d2 100644 --- a/samples/BlazorBindingsXaminals/MauiProgram.cs +++ b/samples/BlazorBindingsXaminals/MauiProgram.cs @@ -11,7 +11,7 @@ public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder - .UseMauiApp() + .UseMauiApp>() .UseMauiBlazorBindings() .ConfigureFonts(fonts => { diff --git a/samples/ControlGallery/App.cs b/samples/ControlGallery/App.cs deleted file mode 100644 index 5b518558..00000000 --- a/samples/ControlGallery/App.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -using BlazorBindings.Maui; - -namespace ControlGallery -{ - public class App : Application - { - public App(MauiBlazorBindingsRenderer renderer) - { - renderer.AddComponent(this); - } - } -} diff --git a/samples/ControlGallery/MauiProgram.cs b/samples/ControlGallery/MauiProgram.cs index 5618172a..1fc8bc50 100644 --- a/samples/ControlGallery/MauiProgram.cs +++ b/samples/ControlGallery/MauiProgram.cs @@ -12,7 +12,7 @@ public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder - .UseMauiApp() + .UseMauiApp>() .UseSkiaSharp() .UseMauiBlazorBindings() .ConfigureFonts(fonts => diff --git a/samples/FluxorSample/App.cs b/samples/FluxorSample/App.cs deleted file mode 100644 index b36a0eea..00000000 --- a/samples/FluxorSample/App.cs +++ /dev/null @@ -1,12 +0,0 @@ -using BlazorBindings.Maui; - -namespace FluxorSample -{ - public partial class App : Application - { - public App(MauiBlazorBindingsRenderer renderer) - { - renderer.AddComponent(this); - } - } -} \ No newline at end of file diff --git a/samples/FluxorSample/MauiProgram.cs b/samples/FluxorSample/MauiProgram.cs index d3143237..eb660aeb 100644 --- a/samples/FluxorSample/MauiProgram.cs +++ b/samples/FluxorSample/MauiProgram.cs @@ -9,7 +9,7 @@ public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder - .UseMauiApp() + .UseMauiApp>() .UseMauiBlazorBindings() .ConfigureFonts(fonts => { diff --git a/samples/FlyoutPageSample/App.cs b/samples/FlyoutPageSample/App.cs deleted file mode 100644 index 406813ee..00000000 --- a/samples/FlyoutPageSample/App.cs +++ /dev/null @@ -1,13 +0,0 @@ -using BlazorBindings.Maui; -using FlyoutPageSample.Views; - -namespace FlyoutPageSample -{ - public partial class App : Application - { - public App(MauiBlazorBindingsRenderer renderer) - { - renderer.AddComponent(this); - } - } -} \ No newline at end of file diff --git a/samples/FlyoutPageSample/MauiProgram.cs b/samples/FlyoutPageSample/MauiProgram.cs index df6ed5d2..68c786ae 100644 --- a/samples/FlyoutPageSample/MauiProgram.cs +++ b/samples/FlyoutPageSample/MauiProgram.cs @@ -1,4 +1,5 @@ using BlazorBindings.Maui; +using FlyoutPageSample.Views; namespace FlyoutPageSample { @@ -7,7 +8,7 @@ public static class MauiProgram public static MauiApp CreateMauiApp() { return MauiApp.CreateBuilder() - .UseMauiApp() + .UseMauiApp>() .UseMauiBlazorBindings() .Build(); } diff --git a/samples/ThirdPartyControlsSample/App.cs b/samples/ThirdPartyControlsSample/App.cs deleted file mode 100644 index a19aadbd..00000000 --- a/samples/ThirdPartyControlsSample/App.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -using ThirdPartyControlsSample.Pages; -using BlazorBindings.Maui; - -namespace ThirdPartyControlsSample -{ - public class App : Application - { - public App(MauiBlazorBindingsRenderer renderer) - { - renderer.AddComponent(this); - } - } -} diff --git a/samples/ThirdPartyControlsSample/MauiProgram.cs b/samples/ThirdPartyControlsSample/MauiProgram.cs index 572b6d1c..4525e107 100644 --- a/samples/ThirdPartyControlsSample/MauiProgram.cs +++ b/samples/ThirdPartyControlsSample/MauiProgram.cs @@ -9,7 +9,7 @@ public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder - .UseMauiApp() + .UseMauiApp>() .UseMauiBlazorBindings() .UseMauiCommunityToolkit() .ConfigureFonts(fonts => diff --git a/src/BlazorBindings.Maui/BlazorBindingsApp.cs b/src/BlazorBindings.Maui/BlazorBindingsApp.cs new file mode 100644 index 00000000..d06f73be --- /dev/null +++ b/src/BlazorBindings.Maui/BlazorBindingsApp.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Maui.Controls; +using System; + +namespace BlazorBindings.Maui +{ + public class BlazorBindingsApplication : Application where T : IComponent + { + public BlazorBindingsApplication(IServiceProvider services) + { + var renderer = services.GetRequiredService(); + _ = renderer.AddComponent(this); + } + } +} diff --git a/src/BlazorBindings.Maui/Navigation/Navigation.Shell.cs b/src/BlazorBindings.Maui/Navigation/Navigation.Shell.cs index 2d2efa99..23778a59 100644 --- a/src/BlazorBindings.Maui/Navigation/Navigation.Shell.cs +++ b/src/BlazorBindings.Maui/Navigation/Navigation.Shell.cs @@ -51,8 +51,12 @@ public async Task NavigateToAsync(string uri, Dictionary paramet //TODO This route matching could be better. Can we use the ASPNEt version? private List FindRoutes() { + var appType = MC.Application.Current.GetType(); + var assembly = appType.IsGenericType && appType.GetGenericTypeDefinition() == typeof(BlazorBindingsApplication<>) + ? appType.GenericTypeArguments[0].Assembly + : appType.Assembly; + var result = new List(); - var assembly = MC.Application.Current.GetType().Assembly; var pages = assembly.GetTypes().Where(x => x.IsSubclassOf(typeof(ComponentBase))); foreach (var page in pages) { From 8c03c3190aa71846ba1c43e1a38617461a176bd0 Mon Sep 17 00:00:00 2001 From: Oleksandr Liakhevych Date: Wed, 23 Nov 2022 23:52:02 +0200 Subject: [PATCH 2/2] Update template --- ...zorBindingsApp.cs => BlazorBindingsApplication.cs} | 0 templates/BlazorBindingsMaui-app/NewApp/App.cs | 11 ----------- .../BlazorBindingsMaui-app/NewApp/MauiProgram.cs | 2 +- 3 files changed, 1 insertion(+), 12 deletions(-) rename src/BlazorBindings.Maui/{BlazorBindingsApp.cs => BlazorBindingsApplication.cs} (100%) delete mode 100644 templates/BlazorBindingsMaui-app/NewApp/App.cs diff --git a/src/BlazorBindings.Maui/BlazorBindingsApp.cs b/src/BlazorBindings.Maui/BlazorBindingsApplication.cs similarity index 100% rename from src/BlazorBindings.Maui/BlazorBindingsApp.cs rename to src/BlazorBindings.Maui/BlazorBindingsApplication.cs diff --git a/templates/BlazorBindingsMaui-app/NewApp/App.cs b/templates/BlazorBindingsMaui-app/NewApp/App.cs deleted file mode 100644 index 80dbcf6b..00000000 --- a/templates/BlazorBindingsMaui-app/NewApp/App.cs +++ /dev/null @@ -1,11 +0,0 @@ -using BlazorBindings.Maui; - -namespace NewApp; - -public partial class App : Application -{ - public App(MauiBlazorBindingsRenderer renderer) - { - renderer.AddComponent(this); - } -} diff --git a/templates/BlazorBindingsMaui-app/NewApp/MauiProgram.cs b/templates/BlazorBindingsMaui-app/NewApp/MauiProgram.cs index b8e76d9a..e167cf6a 100644 --- a/templates/BlazorBindingsMaui-app/NewApp/MauiProgram.cs +++ b/templates/BlazorBindingsMaui-app/NewApp/MauiProgram.cs @@ -8,7 +8,7 @@ public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder - .UseMauiApp() + .UseMauiApp>() .UseMauiBlazorBindings() .ConfigureFonts(fonts => {