// TODO: This isn't the right way to trigger the init, because it wouldn't happen naturally if consuming // BlazorWebView directly from Xamarin Forms XAML. It only works from MBB. public async Task InitAsync() { _attachInteropTask ??= AttachInteropAsync(); var handshakeResult = await _attachInteropTask.ConfigureAwait(false); var services = Services ?? BlazorHybridDefaultServices.Instance ?? DefaultServices.Value; _serviceScope = services.CreateScope(); var scopeServiceProvider = _serviceScope.ServiceProvider; var loggerFactory = services.GetRequiredService<ILoggerFactory>(); _navigationManager = (BlazorHybridNavigationManager)scopeServiceProvider.GetRequiredService<NavigationManager>(); _navigationManager.Initialize(_jsRuntime, handshakeResult.BaseUri, handshakeResult.InitialUri); _blazorHybridRenderer = new BlazorHybridRenderer(_ipc, scopeServiceProvider, loggerFactory, _jsRuntime, _dispatcher); }
// TODO: This isn't the right way to trigger the init, because it wouldn't happen naturally if consuming // BlazorWebView directly from Xamarin Forms XAML. It only works from MBB. public async Task InitAsync() { var services = Host?.Services ?? DefaultServices.Value; _serviceScope = services.CreateScope(); var scopeServiceProvider = _serviceScope.ServiceProvider; var webViewJSRuntime = (BlazorHybridJSRuntime)scopeServiceProvider.GetRequiredService <IJSRuntime>(); webViewJSRuntime.AttachToIpcChannel(_ipc); _jsRuntime = webViewJSRuntime; _attachInteropTask ??= AttachInteropAsync(); var handshakeResult = await _attachInteropTask.ConfigureAwait(false); var loggerFactory = scopeServiceProvider.GetRequiredService <ILoggerFactory>(); _navigationManager = (BlazorHybridNavigationManager)scopeServiceProvider.GetRequiredService <NavigationManager>(); _navigationManager.Initialize(_jsRuntime, handshakeResult.BaseUri, handshakeResult.InitialUri); _blazorHybridRenderer = new BlazorHybridRenderer(_ipc, scopeServiceProvider, loggerFactory, _jsRuntime, _dispatcher, ErrorHandler); }