99using System . Windows . Media ;
1010using System . Windows . Media . Imaging ;
1111using System . Windows . Shell ;
12- using BlazorDesktop . Extensions ;
1312using BlazorDesktop . Hosting ;
1413using Microsoft . AspNetCore . Components . WebView . Wpf ;
1514using 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