Skip to content

Commit 0c525a4

Browse files
chore: Cleanup root component initialization
1 parent f2ad63d commit 0c525a4

2 files changed

Lines changed: 12 additions & 41 deletions

File tree

src/BlazorDesktop/Extensions/RootComponentsCollectionExtensions.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/BlazorDesktop/Wpf/BlazorDesktopWindow.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using System.Windows.Media;
1010
using System.Windows.Media.Imaging;
1111
using System.Windows.Shell;
12-
using BlazorDesktop.Extensions;
1312
using BlazorDesktop.Hosting;
1413
using Microsoft.AspNetCore.Components.WebView.Wpf;
1514
using Microsoft.Web.WebView2.Core;
@@ -32,11 +31,6 @@ public class BlazorDesktopWindow : Window
3231
/// </summary>
3332
private readonly IServiceProvider _services;
3433

35-
/// <summary>
36-
/// The root components.
37-
/// </summary>
38-
private readonly IEnumerable<RootComponent> _rootComponents;
39-
4034
/// <summary>
4135
/// The configuration.
4236
/// </summary>
@@ -75,19 +69,12 @@ public class BlazorDesktopWindow : Window
7569
/// Creates a <see cref="BlazorDesktopWindow"/> instance.
7670
/// </summary>
7771
/// <param name="services">The services.</param>
78-
/// <param name="rootComponents">The root components.</param>
7972
/// <param name="config">The configuration.</param>
8073
/// <param name="environment">The hosting environment.</param>
81-
public BlazorDesktopWindow(IServiceProvider services, RootComponentMappingCollection rootComponents, IConfiguration config, IWebHostEnvironment environment)
74+
public BlazorDesktopWindow(IServiceProvider services, IConfiguration config, IWebHostEnvironment environment)
8275
{
8376
WebView = new BlazorWebView();
8477
_services = services;
85-
_rootComponents = rootComponents.Select(c => new RootComponent()
86-
{
87-
Selector = c.Selector,
88-
ComponentType = c.ComponentType,
89-
Parameters = (IDictionary<string, object?>)c.Parameters.ToDictionary()
90-
});
9178
_config = config;
9279
_environment = environment;
9380
_uiSettings = new UISettings();
@@ -120,7 +107,17 @@ private void InitializeBlazor()
120107
WebView.Name = "BlazorWebView";
121108
WebView.HostPage = Path.Combine(_environment.WebRootPath, "index.html");
122109
WebView.Services = _services;
123-
WebView.RootComponents.AddRange(_rootComponents);
110+
111+
foreach (var rootComponent in _services.GetRequiredService<RootComponentMappingCollection>())
112+
{
113+
WebView.RootComponents.Add(new()
114+
{
115+
Selector = rootComponent.Selector,
116+
ComponentType = rootComponent.ComponentType,
117+
Parameters = (IDictionary<string, object?>)rootComponent.Parameters.ToDictionary()
118+
});
119+
}
120+
124121
WebView.Loaded += WebViewLoaded;
125122
}
126123

0 commit comments

Comments
 (0)