internal async Task <XF.Page> BuildPage(Type componentType) { var container = new RootContainerHandler(); var route = NavigationParameters[componentType]; #pragma warning disable CA2000 // Dispose objects before losing scope. Renderer is disposed when page is closed. var renderer = new MobileBlazorBindingsRenderer(_services, _services.GetRequiredService <ILoggerFactory>()); #pragma warning restore CA2000 // Dispose objects before losing scope var addComponentTask = renderer.AddComponent(componentType, container, route.Parameters); var elementAddedTask = container.WaitForElementAsync(); await Task.WhenAny(addComponentTask, elementAddedTask).ConfigureAwait(false); if (container.Elements.Count != 1) { throw new InvalidOperationException("The target component of a Shell navigation must have exactly one root element."); } var page = container.Elements.FirstOrDefault() as XF.Page ?? throw new InvalidOperationException("The target component of a Shell navigation must derive from the Page component."); DisposeRendererWhenPageIsClosed(renderer, page); return(page); }
internal async Task <MC.Page> BuildPage(Type componentType) { #pragma warning disable CA2000 // Dispose objects before losing scope. Scope is disposed when page is closed. var scope = _services.CreateScope(); #pragma warning restore CA2000 // Dispose objects before losing scope var serviceProvider = scope.ServiceProvider; var container = new RootContainerHandler(); var route = NavigationParameters[componentType]; var renderer = serviceProvider.GetRequiredService <MobileBlazorBindingsRenderer>(); var convertedParameters = ConvertParameters(componentType, route.Parameters); var addComponentTask = renderer.AddComponent(componentType, container, convertedParameters); var elementAddedTask = container.WaitForElementAsync(); await Task.WhenAny(addComponentTask, elementAddedTask).ConfigureAwait(false); if (container.Elements.Count != 1) { throw new InvalidOperationException("The target component of a Shell navigation must have exactly one root element."); } var page = container.Elements.FirstOrDefault() as MC.Page ?? throw new InvalidOperationException("The target component of a Shell navigation must derive from the Page component."); page.ParentChanged += DisposeScopeWhenParentRemoved; return(page); void DisposeScopeWhenParentRemoved(object _, EventArgs __) { if (page.Parent is null) { scope.Dispose(); page.ParentChanged -= DisposeScopeWhenParentRemoved; } } }