diff --git a/src/BlazorWebView/samples/BlazorWinFormsApp/Form1.cs b/src/BlazorWebView/samples/BlazorWinFormsApp/Form1.cs index c303d7ed92d2..5726481f7071 100644 --- a/src/BlazorWebView/samples/BlazorWinFormsApp/Form1.cs +++ b/src/BlazorWebView/samples/BlazorWinFormsApp/Form1.cs @@ -17,11 +17,18 @@ public partial class Form1 : Form public Form1() { var services1 = new ServiceCollection(); - services1.AddBlazorWebView(); + services1.AddWindowsFormsBlazorWebView(); +#if DEBUG + services1.AddBlazorWebViewDeveloperTools(); +#endif services1.AddSingleton(_appState); var services2 = new ServiceCollection(); - services2.AddBlazorWebView(); + services2.AddWindowsFormsBlazorWebView(); +#if DEBUG + services2.AddBlazorWebViewDeveloperTools(); +#endif + services2.AddSingleton(_appState); InitializeComponent(); diff --git a/src/BlazorWebView/samples/BlazorWpfApp/MainWindow.xaml.cs b/src/BlazorWebView/samples/BlazorWpfApp/MainWindow.xaml.cs index 564609d7cd84..c425792117cc 100644 --- a/src/BlazorWebView/samples/BlazorWpfApp/MainWindow.xaml.cs +++ b/src/BlazorWebView/samples/BlazorWpfApp/MainWindow.xaml.cs @@ -18,12 +18,20 @@ public partial class MainWindow : Window public MainWindow() { var services1 = new ServiceCollection(); - services1.AddBlazorWebView(); + services1.AddWpfBlazorWebView(); +#if DEBUG + services1.AddBlazorWebViewDeveloperTools(); +#endif + services1.AddSingleton(_appState); Resources.Add("services1", services1.BuildServiceProvider()); var services2 = new ServiceCollection(); - services2.AddBlazorWebView(); + services2.AddWpfBlazorWebView(); +#if DEBUG + services2.AddBlazorWebViewDeveloperTools(); +#endif + services2.AddSingleton(_appState); Resources.Add("services2", services2.BuildServiceProvider()); diff --git a/src/BlazorWebView/src/Maui/Android/AndroidWebKitWebViewManager.cs b/src/BlazorWebView/src/Maui/Android/AndroidWebKitWebViewManager.cs index d602ded634ec..82921feb3a96 100644 --- a/src/BlazorWebView/src/Maui/Android/AndroidWebKitWebViewManager.cs +++ b/src/BlazorWebView/src/Maui/Android/AndroidWebKitWebViewManager.cs @@ -3,6 +3,7 @@ using System.IO; using Android.Webkit; using Microsoft.AspNetCore.Components.Web; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using AWebView = Android.Webkit.WebView; using AUri = Android.Net.Uri; @@ -33,6 +34,14 @@ public class AndroidWebKitWebViewManager : WebViewManager public AndroidWebKitWebViewManager(AWebView webview!!, IServiceProvider services, Dispatcher dispatcher, IFileProvider fileProvider, JSComponentConfigurationStore jsComponents, string hostPageRelativePath) : base(services, dispatcher, new Uri(AppOrigin), fileProvider, jsComponents, hostPageRelativePath) { +#if WEBVIEW2_MAUI + if (services.GetService() is null) + { + throw new InvalidOperationException( + "Unable to find the required services. " + + $"Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(BlazorWebViewServiceCollectionExtensions.AddMauiBlazorWebView)}' in the application startup code."); + } +#endif _webview = webview; } diff --git a/src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs b/src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs index 8f256353cb1f..2f28827a8f56 100644 --- a/src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs +++ b/src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs @@ -29,7 +29,7 @@ protected override BlazorAndroidWebView CreatePlatformView() // To allow overriding ExternalLinkMode.InsecureOpenInWebView and open links in browser with a _blank target blazorAndroidWebView.Settings.SetSupportMultipleWindows(true); - BlazorAndroidWebView.SetWebContentsDebuggingEnabled(enabled: true); + BlazorAndroidWebView.SetWebContentsDebuggingEnabled(enabled: DeveloperTools.Enabled); if (blazorAndroidWebView.Settings != null) { diff --git a/src/BlazorWebView/src/Maui/BlazorWebViewHandler.cs b/src/BlazorWebView/src/Maui/BlazorWebViewHandler.cs index cffc6fa4997f..142e974d308e 100644 --- a/src/BlazorWebView/src/Maui/BlazorWebViewHandler.cs +++ b/src/BlazorWebView/src/Maui/BlazorWebViewHandler.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using Microsoft.AspNetCore.Components.WebView; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Maui; using Microsoft.Maui.Handlers; @@ -21,7 +22,7 @@ public partial class BlazorWebViewHandler /// /// Initializes a new instance of with default mappings. /// - public BlazorWebViewHandler() : base(BlazorWebViewMapper) + public BlazorWebViewHandler() : this(BlazorWebViewMapper) { } @@ -33,6 +34,8 @@ public BlazorWebViewHandler(PropertyMapper? mapper) : base(mapper ?? BlazorWebVi { } + internal BlazorWebViewDeveloperTools DeveloperTools => MauiContext!.Services.GetRequiredService(); + /// /// Maps the property to the specified handler. /// diff --git a/src/BlazorWebView/src/Maui/BlazorWebViewRegistrationExtensions.cs b/src/BlazorWebView/src/Maui/BlazorWebViewRegistrationExtensions.cs deleted file mode 100644 index a46fa273d09f..000000000000 --- a/src/BlazorWebView/src/Maui/BlazorWebViewRegistrationExtensions.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using Microsoft.Maui.Hosting; - -namespace Microsoft.AspNetCore.Components.WebView.Maui -{ - /// - /// Extension methods to . - /// - public static class BlazorWebViewRegistrationExtensions - { - /// - /// Configures to add support for . - /// - /// The . - /// The . - public static MauiAppBuilder RegisterBlazorMauiWebView(this MauiAppBuilder appHostBuilder) - { - if (appHostBuilder is null) - { - throw new ArgumentNullException(nameof(appHostBuilder)); - } - - appHostBuilder.ConfigureMauiHandlers(static handlers => handlers.AddHandler()); - - return appHostBuilder; - } - } -} diff --git a/src/BlazorWebView/src/Maui/MauiBlazorMarkerService.cs b/src/BlazorWebView/src/Maui/MauiBlazorMarkerService.cs new file mode 100644 index 000000000000..bcaca9fc3860 --- /dev/null +++ b/src/BlazorWebView/src/Maui/MauiBlazorMarkerService.cs @@ -0,0 +1,9 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Components.WebView.Maui +{ + internal class MauiBlazorMarkerService + { + } +} diff --git a/src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs b/src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs index b80673b39432..e04b5ad3ee01 100644 --- a/src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs +++ b/src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs @@ -50,7 +50,7 @@ protected override WKWebView CreatePlatformView() { var config = new WKWebViewConfiguration(); - config.Preferences.SetValueForKey(NSObject.FromObject(true), new NSString("developerExtrasEnabled")); + config.Preferences.SetValueForKey(NSObject.FromObject(DeveloperTools.Enabled), new NSString("developerExtrasEnabled")); config.UserContentController.AddScriptMessageHandler(new WebViewScriptMessageHandler(MessageReceived), "webwindowinterop"); config.UserContentController.AddUserScript(new WKUserScript( diff --git a/src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs b/src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs index 66e0cd3590fa..807fa0cb3cd0 100644 --- a/src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs +++ b/src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs @@ -5,6 +5,7 @@ using System.Text.Encodings.Web; using Foundation; using Microsoft.AspNetCore.Components.Web; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using UIKit; using WebKit; @@ -33,6 +34,13 @@ public class IOSWebViewManager : WebViewManager public IOSWebViewManager(BlazorWebViewHandler blazorMauiWebViewHandler!!, WKWebView webview!!, IServiceProvider provider, Dispatcher dispatcher, IFileProvider fileProvider, JSComponentConfigurationStore jsComponents, string hostPageRelativePath) : base(provider, dispatcher, new Uri(BlazorWebViewHandler.AppOrigin), fileProvider, jsComponents, hostPageRelativePath) { + if (provider.GetService() is null) + { + throw new InvalidOperationException( + "Unable to find the required services. " + + $"Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(BlazorWebViewServiceCollectionExtensions.AddMauiBlazorWebView)}' in the application startup code."); + } + _blazorMauiWebViewHandler = blazorMauiWebViewHandler; _webview = webview; diff --git a/src/BlazorWebView/src/SharedSource/BlazorWebViewDeveloperTools.cs b/src/BlazorWebView/src/SharedSource/BlazorWebViewDeveloperTools.cs new file mode 100644 index 000000000000..0f088fb3d261 --- /dev/null +++ b/src/BlazorWebView/src/SharedSource/BlazorWebViewDeveloperTools.cs @@ -0,0 +1,17 @@ +using System; + +#if WEBVIEW2_WINFORMS +namespace Microsoft.AspNetCore.Components.WebView.WindowsForms +#elif WEBVIEW2_WPF +namespace Microsoft.AspNetCore.Components.WebView.Wpf +#elif WEBVIEW2_MAUI +namespace Microsoft.AspNetCore.Components.WebView.Maui +#else +#error Must define WEBVIEW2_WINFORMS, WEBVIEW2_WPF, WEBVIEW2_MAUI +#endif +{ + internal class BlazorWebViewDeveloperTools + { + public bool Enabled { get; set; } = false; + } +} diff --git a/src/BlazorWebView/src/SharedSource/BlazorWebViewServiceCollectionExtensions.cs b/src/BlazorWebView/src/SharedSource/BlazorWebViewServiceCollectionExtensions.cs new file mode 100644 index 000000000000..353404b1e4fa --- /dev/null +++ b/src/BlazorWebView/src/SharedSource/BlazorWebViewServiceCollectionExtensions.cs @@ -0,0 +1,60 @@ +using System; +#if WEBVIEW2_WINFORMS +using Microsoft.AspNetCore.Components.WebView.WindowsForms; +#elif WEBVIEW2_WPF +using Microsoft.AspNetCore.Components.WebView.Wpf; +#elif WEBVIEW2_MAUI +using Microsoft.AspNetCore.Components.WebView.Maui; +using Microsoft.Maui.Hosting; +#else +#error Must define WEBVIEW2_WINFORMS, WEBVIEW2_WPF, WEBVIEW2_MAUI +#endif +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; + +namespace Microsoft.Extensions.DependencyInjection +{ + /// + /// Extension methods to . + /// + public static class BlazorWebViewServiceCollectionExtensions + { + /// + /// Configures to add support for . + /// + /// The . + /// The . +#if WEBVIEW2_WINFORMS + public static IServiceCollection AddWindowsFormsBlazorWebView(this IServiceCollection services) +#elif WEBVIEW2_WPF + public static IServiceCollection AddWpfBlazorWebView(this IServiceCollection services) +#elif WEBVIEW2_MAUI + public static IServiceCollection AddMauiBlazorWebView(this IServiceCollection services) +#else +#error Must define WEBVIEW2_WINFORMS, WEBVIEW2_WPF, WEBVIEW2_MAUI +#endif + { + services.AddBlazorWebView(); + services.TryAddSingleton(new BlazorWebViewDeveloperTools { Enabled = false }); +#if WEBVIEW2_MAUI + services.TryAddSingleton(); + services.ConfigureMauiHandlers(static handlers => handlers.AddHandler()); +#elif WEBVIEW2_WINFORMS + services.TryAddSingleton(); +#elif WEBVIEW2_WPF + services.TryAddSingleton(); +#endif + return services; + } + + /// + /// Enables Developer tools on the underlying WebView controls. + /// + /// The . + /// The . + public static IServiceCollection AddBlazorWebViewDeveloperTools(this IServiceCollection services) + { + return services.AddSingleton(new BlazorWebViewDeveloperTools { Enabled = true }); + } + } +} diff --git a/src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs b/src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs index 415259dcad7a..9130017a8d43 100644 --- a/src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs +++ b/src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs @@ -17,16 +17,21 @@ using Microsoft.Extensions.FileProviders; #if WEBVIEW2_WINFORMS using System.Diagnostics; +using Microsoft.AspNetCore.Components.WebView.WindowsForms; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Web.WebView2; using Microsoft.Web.WebView2.Core; using WebView2Control = Microsoft.Web.WebView2.WinForms.WebView2; #elif WEBVIEW2_WPF using System.Diagnostics; +using Microsoft.AspNetCore.Components.WebView.Wpf; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Web.WebView2; using Microsoft.Web.WebView2.Core; using WebView2Control = Microsoft.Web.WebView2.Wpf.WebView2; #elif WEBVIEW2_MAUI using Microsoft.AspNetCore.Components.WebView.Maui; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Web.WebView2.Core; using WebView2Control = Microsoft.UI.Xaml.Controls.WebView2; using System.Runtime.InteropServices.WindowsRuntime; @@ -58,6 +63,7 @@ public class WebView2WebViewManager : WebViewManager #if WEBVIEW2_WINFORMS || WEBVIEW2_WPF private protected CoreWebView2Environment _coreWebView2Environment; private readonly Action _externalNavigationStarting; + private readonly BlazorWebViewDeveloperTools _developerTools; /// /// Constructs an instance of . @@ -80,8 +86,25 @@ public WebView2WebViewManager( : base(services, dispatcher, new Uri(AppOrigin), fileProvider, jsComponents, hostPageRelativePath) { +#if WEBVIEW2_WINFORMS + if (services.GetService() is null) + { + throw new InvalidOperationException( + "Unable to find the required services. " + + $"Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(BlazorWebViewServiceCollectionExtensions.AddWindowsFormsBlazorWebView)}' in the application startup code."); + } +#elif WEBVIEW2_WPF + if (services.GetService() is null) + { + throw new InvalidOperationException( + "Unable to find the required services. " + + $"Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(BlazorWebViewServiceCollectionExtensions.AddWpfBlazorWebView)}' in the application startup code."); + } +#endif + _webview = webview; _externalNavigationStarting = externalNavigationStarting; + _developerTools = services.GetRequiredService(); // Unfortunately the CoreWebView2 can only be instantiated asynchronously. // We want the external API to behave as if initalization is synchronous, @@ -113,6 +136,13 @@ BlazorWebViewHandler blazorWebViewHandler ) : base(services, dispatcher, new Uri(AppOrigin), fileProvider, jsComponents, hostPageRelativePath) { + if (services.GetService() is null) + { + throw new InvalidOperationException( + "Unable to find the required services. " + + $"Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(BlazorWebViewServiceCollectionExtensions.AddMauiBlazorWebView)}' in the application startup code."); + } + _webview = webview; _blazorWebViewHandler = blazorWebViewHandler; @@ -145,7 +175,13 @@ private async Task InitializeWebView2() #endif .ConfigureAwait(true); await _webview.EnsureCoreWebView2Async(); - ApplyDefaultWebViewSettings(); + +#if WEBVIEW2_MAUI + var developerTools = _blazorWebViewHandler.DeveloperTools; +#elif WEBVIEW2_WINFORMS || WEBVIEW2_WPF + var developerTools = _developerTools; +#endif + ApplyDefaultWebViewSettings(developerTools); _webview.CoreWebView2.AddWebResourceRequestedFilter($"{AppOrigin}*", CoreWebView2WebResourceContext.All); @@ -263,8 +299,10 @@ private void LaunchUriInExternalBrowser(Uri uri) private protected static string GetHeaderString(IDictionary headers) => string.Join(Environment.NewLine, headers.Select(kvp => $"{kvp.Key}: {kvp.Value}")); - private void ApplyDefaultWebViewSettings() + private void ApplyDefaultWebViewSettings(BlazorWebViewDeveloperTools devTools) { + _webview.CoreWebView2.Settings.AreDevToolsEnabled = devTools.Enabled; + // Desktop applications typically don't want the default web browser context menu _webview.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false; diff --git a/src/BlazorWebView/src/WindowsForms/BlazorWebView.cs b/src/BlazorWebView/src/WindowsForms/BlazorWebView.cs index 3c4bfa496265..6ba6bf487c3b 100644 --- a/src/BlazorWebView/src/WindowsForms/BlazorWebView.cs +++ b/src/BlazorWebView/src/WindowsForms/BlazorWebView.cs @@ -9,6 +9,7 @@ using System.Reflection; using System.Windows.Forms; using Microsoft.AspNetCore.Components.WebView.WebView2; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using WebView2Control = Microsoft.Web.WebView2.WinForms.WebView2; diff --git a/src/BlazorWebView/src/WindowsForms/WindowsFormsBlazorMarkerService.cs b/src/BlazorWebView/src/WindowsForms/WindowsFormsBlazorMarkerService.cs new file mode 100644 index 000000000000..2ed95d01a103 --- /dev/null +++ b/src/BlazorWebView/src/WindowsForms/WindowsFormsBlazorMarkerService.cs @@ -0,0 +1,9 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Components.WebView.WindowsForms +{ + internal class WindowsFormsBlazorMarkerService + { + } +} diff --git a/src/BlazorWebView/src/Wpf/BlazorWebView.cs b/src/BlazorWebView/src/Wpf/BlazorWebView.cs index eef06962f9a5..b04de9b7df42 100644 --- a/src/BlazorWebView/src/Wpf/BlazorWebView.cs +++ b/src/BlazorWebView/src/Wpf/BlazorWebView.cs @@ -12,6 +12,7 @@ using System.Windows; using System.Windows.Controls; using Microsoft.AspNetCore.Components.WebView.WebView2; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using WebView2Control = Microsoft.Web.WebView2.Wpf.WebView2; diff --git a/src/BlazorWebView/src/Wpf/WpfBlazorMarkerService.cs b/src/BlazorWebView/src/Wpf/WpfBlazorMarkerService.cs new file mode 100644 index 000000000000..08801b5e1cde --- /dev/null +++ b/src/BlazorWebView/src/Wpf/WpfBlazorMarkerService.cs @@ -0,0 +1,9 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Components.WebView.Wpf +{ + internal class WpfBlazorMarkerService + { + } +} diff --git a/src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewTests.cs b/src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewTests.cs index f45ca690ad13..ebf5ee7e482f 100644 --- a/src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewTests.cs +++ b/src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewTests.cs @@ -16,7 +16,7 @@ public async Task BasicRazorComponentClick() { EnsureHandlerCreated(additionalCreationActions: appBuilder => { - appBuilder.Services.AddBlazorWebView(); + appBuilder.Services.AddMauiBlazorWebView(); }); var bwv = new BlazorWebViewWithCustomFiles diff --git a/src/Controls/samples/Controls.Sample/Pages/Blazor/BlazorPage.xaml.cs b/src/Controls/samples/Controls.Sample/Pages/Blazor/BlazorPage.xaml.cs index dba66b86fd70..c915ab29845c 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Blazor/BlazorPage.xaml.cs +++ b/src/Controls/samples/Controls.Sample/Pages/Blazor/BlazorPage.xaml.cs @@ -43,7 +43,6 @@ public BlazorPage() grid.Add(bwv); Grid.SetRow(bwv, 1); - var footerLabel = new Label { Text = "Thank you for using Blazor and .NET MAUI!", FontSize = 24, TextColor = Colors.BlanchedAlmond, HorizontalOptions = LayoutOptions.Center, }; grid.Add(footerLabel); Grid.SetRow(footerLabel, 2); diff --git a/src/Controls/samples/Controls.Sample/Startup.cs b/src/Controls/samples/Controls.Sample/Startup.cs index 247d4976fa95..17e626ac73b0 100644 --- a/src/Controls/samples/Controls.Sample/Startup.cs +++ b/src/Controls/samples/Controls.Sample/Startup.cs @@ -88,9 +88,10 @@ public static MauiApp CreateMauiApp() }); #if NET6_0_OR_GREATER - appBuilder - .RegisterBlazorMauiWebView(); - services.AddBlazorWebView(); + services.AddMauiBlazorWebView(); +#if DEBUG + services.AddBlazorWebViewDeveloperTools(); +#endif #endif services.AddLogging(logging => diff --git a/src/Core/src/Hosting/HandlerMauiAppBuilderExtensions.cs b/src/Core/src/Hosting/HandlerMauiAppBuilderExtensions.cs index df8f17f8f3c6..e456fbc1ea9d 100644 --- a/src/Core/src/Hosting/HandlerMauiAppBuilderExtensions.cs +++ b/src/Core/src/Hosting/HandlerMauiAppBuilderExtensions.cs @@ -10,12 +10,19 @@ public static class HandlerMauiAppBuilderExtensions { public static MauiAppBuilder ConfigureMauiHandlers(this MauiAppBuilder builder, Action? configureDelegate) { - builder.Services.TryAddSingleton(); + ConfigureMauiHandlers(builder.Services, configureDelegate); + return builder; + } + + public static IServiceCollection ConfigureMauiHandlers(this IServiceCollection services, Action? configureDelegate) + { + services.TryAddSingleton(); if (configureDelegate != null) { - builder.Services.AddSingleton(new HandlerRegistration(configureDelegate)); + services.AddSingleton(new HandlerRegistration(configureDelegate)); } - return builder; + + return services; } internal class HandlerRegistration diff --git a/src/Templates/src/templates/maui-blazor/MauiProgram.cs b/src/Templates/src/templates/maui-blazor/MauiProgram.cs index 6d5379b282e8..35396dacf091 100644 --- a/src/Templates/src/templates/maui-blazor/MauiProgram.cs +++ b/src/Templates/src/templates/maui-blazor/MauiProgram.cs @@ -9,14 +9,17 @@ public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder - .RegisterBlazorMauiWebView() .UseMauiApp() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); }); - builder.Services.AddBlazorWebView(); + builder.Services.AddMauiBlazorWebView(); +#if DEBUG + builder.Services.AddBlazorWebViewDeveloperTools(); +#endif + builder.Services.AddSingleton(); return builder.Build();